0
scene.remove(xaxis);
scene.remove(yaxis);
scene.remove(zaxis);

有没有办法将这些组合成一行(也许使用正则表达式?)。这是three.js 库的一部分。

4

2 回答 2

2

抱歉,如果这不是您想要的答案,但是将它们包装成一个函数呢?

function removeAxes(){
    scene.remove(xaxis);
    scene.remove(yaxis);
    scene.remove(zaxis);
}
于 2013-07-15T20:32:25.260 回答
1

Write this anywhere in your code.

THREE.Scene.prototype.removeItems = function(){

for (var i = 0; i < arguments.length; i++)
this.remove(arguments[i])

}

Now the Scene object accepts all the arguments you want. You can condensate the 3 lines anywhere in your code...

scene.removeItems(xaxis, yaxis, zaxis);

... call it with any number of arguments...

scene.removeItems(someStuff, someOtherStuff);

... be it 1 or 100

scene.removeItems(1, 2, 3, 4, 5);
于 2013-07-15T20:51:02.800 回答