三个JS圈删除

时间:2013-05-07 03:58:35

标签: javascript

Doob先生在他的论坛/网站上添加了这个圈子

var resolution = 100;
var amplitude = 100;
var size = 360 / resolution;

var geometry = new THREE.Geometry();
var material = new THREE.LineBasicMaterial( { color: 0xFFFFFF, opacity: 1.0} );
for(var i = 0; i <= resolution; i++) {
    var segment = ( i * size ) * Math.PI / 180;
    geometry.vertices.push( new THREE.Vertex( new THREE.Vector3( Math.cos( segment ) * amplitude, 0, Math.sin( segment ) * amplitude ) ) );         
}

var line = new THREE.Line( geometry, material );
scene.add(line);

我想删除我制作的一些圈子,但使用“scene.remove(line)”为我做的工作......

P.S。

这是我的代码的一部分,在制作一个圆圈之后,我想再次摆脱它。

 var feetcircle;
        var resolution = 100;
        var amplitude = 140;
        var size = 360 / resolution;

        var geometry = new THREE.Geometry();
        var material = new THREE.LineBasicMaterial({
            color: 0x00FF00,
            opacity: 1.0
        });




        for (var i = 0; i <= resolution; i++) {
            var segment = (i * size) * Math.PI / 180;
            geometry.vertices.push(new THREE.Vertex(new THREE.Vector3((Math.cos(segment) * amplitude) +  (moves[move][move + '_mrfoot0'][0][0] * scale)-30, 0, (Math.sin(segment) * amplitude) + 375)));
        }

        for (var i = 0; i <= resolution; i++) {
            var segment = (i * size) * Math.PI / 180;
            geometry.vertices.push(new THREE.Vertex(new THREE.Vector3((Math.cos(segment) * amplitude) +  (moves[move][move + '_mrfoot0'][0][0] * scale)-30, 410, (Math.sin(segment) * amplitude) + 375)));
        }

        for (var i = 0; i <= resolution; i++) {
            var segment = (i * size) * Math.PI / 180;
            geometry.vertices.push(new THREE.Vertex(new THREE.Vector3((Math.cos(segment) * amplitude) +  (moves[move][move + '_mrfoot0'][0][0] * scale)-30, 285, (Math.sin(segment) * amplitude) + 375)));
        }


        feetcircle = new THREE.Line(geometry, new THREE.LineBasicMaterial({
            color: 0x00ff00, opacity: 1.0
        }));
        feetcircle.geometry.dynamic = true;
        scene.add(feetcircle);

1 个答案:

答案 0 :(得分:0)

您不是要添加单个对象。所有这些顶点都属于同一个对象,因此您无法轻易删除它们。你需要做的是:

    for (var i = 0; i <= resolution; i++) {
        var segment = (i * size) * Math.PI / 180;
        geometry.vertices.push(new THREE.Vertex(new THREE.Vector3((Math.cos(segment) * amplitude) +  (moves[move][move + '_mrfoot0'][0][0] * scale)-30, 0, (Math.sin(segment) * amplitude) + 375)));
    }

    feetcircle = new THREE.Line(geometry, new THREE.LineBasicMaterial({
        color: 0x00ff00, opacity: 1.0
    }));
    feetcircle.geometry.dynamic = true;
    scene.add(feetcircle);

    geometry = new THREE.Geometry();
    for (var i = 0; i <= resolution; i++) {
        var segment = (i * size) * Math.PI / 180;
        geometry.vertices.push(new THREE.Vertex(new THREE.Vector3((Math.cos(segment) * amplitude) +  (moves[move][move + '_mrfoot0'][0][0] * scale)-30, 410, (Math.sin(segment) * amplitude) + 375)));
    }

    var feetcircle2 = new THREE.Line(geometry, new THREE.LineBasicMaterial({
        color: 0x00ff00, opacity: 1.0
    }));
    feetcircle2.geometry.dynamic = true;
    scene.add(feetcircle2);

    ...
    scene.remove(feetcircle);
    scene.remove(feetcircle2);

等...当然,如果你想要真正删除它们,你要么给它们各自的变量名,要么把它们放在一个数组中。

var circles = new Array();

for (int i = 0; i < 3; i++)
{
    geometry = new THREE.Geometry();
    for (var j = 0;j <= resolution; j++) {
            var segment = (j* size) * Math.PI / 180;
            geometry.vertices.push(new THREE.Vertex(new THREE.Vector3((Math.cos(segment) * amplitude) +  (moves[move][move + '_mrfoot0'][0][0] * scale)-30, 410, (Math.sin(segment) * amplitude) + 375)));
    }
    feetcircle = new THREE.Line(geometry, new THREE.LineBasicMaterial({
        color: 0x00ff00, opacity: 1.0
    }));
    feetcircle.geometry.dynamic = true;
    circles.push(feetcircle);
    scene.add(circles[i]);
}

for (int i = 0; i < circles.length; i++)
     scene.remove(circles[i]);