Javascript 如何解决这个循环并按顺序呈现圆锥体?

Javascript 如何解决这个循环并按顺序呈现圆锥体?,javascript,3d,three.js,Javascript,3d,Three.js,你能帮我解决这个问题吗。这项任务真的一直都很难完成:(你可以通过一个循环来完成,通过从j计算j和k,而不是再添加两个循环: var light = new THREE.DirectionalLight(0xffffff, 0.6); light.position.y = 1; light.position.x = 1; light.position.z = 1; scene.add(light); light = new THREE.DirectionalLight(0xffffff, 0.6)

你能帮我解决这个问题吗。这项任务真的一直都很难完成:(

你可以通过一个循环来完成,通过从
j
计算
j
k
,而不是再添加两个循环:

var light = new THREE.DirectionalLight(0xffffff, 0.6);
light.position.y = 1;
light.position.x = 1;
light.position.z = 1;
scene.add(light);
light = new THREE.DirectionalLight(0xffffff, 0.6);
light.position.y = -1;
light.position.x = -1;
light.position.z = -1;
scene.add(light);
light = new THREE.DirectionalLight(0xffffff, 0.6);
light.position.y = 1;
light.position.x = 0;
light.position.z = 0;
scene.add(light);
container.appendChild( renderer.domElement );
}
 function animate() 
{   
requestAnimationFrame( animate );
render();   
}
  function render() 
{                           
renderer.render(scene, camera);
}

for(var i=0;i)我们无法解决问题,但我们可能会帮助您解决您面临的问题。您能准备好吗,我们可以玩一下吗?@Engineer,我当然能想到JSfiddle@Engineer,这里是JSFIDLE链接:我希望我的问题得到解决:)@Romier,谢谢你的回复,伙计。我可以像你在上一个问题中帮助的那样使用JSFIDLE链接吗?提前谢谢。我刚刚检查了JSFIDLE的第8个版本,看起来不错。提示:你应该更改
geo.vertices.push(新三点顶点(新三点矢量3(0,0,0));
by
geo.vertices.push(新三点矢量3(0,0));
因为
THREE.Vertex
已被弃用(已被
THREE.Vector3
取代)它抛出了一个控制台警报,这会减慢初始加载速度。我已经更新了上面的JSFIDLE:但是现在我想选择单个圆锥体,它后面的子体作为单个选择。例如:如果我在第1层选择圆锥体1并旋转,它在第2层的子体和它在第3层的大子体应该被选择并以ti的速度旋转me。如果我在第2层选择了圆锥体,如果它在第1层上有父对象,它也会被选择,并且它在第3层上的子对象也会被选择旋转。像wise一样,第3层上的圆锥体必须在之前的层上找到它的父对象进行旋转。这些选择取决于JSON。
for ( var i = 0; i <nSize; i++)
     for ( var j = -5; j < 5; j++)
         for ( var k = -5; k < 5; k++) 
          {
            var cone1 = new THREE.MESH(lc_relationship.sensor1[i].Geometry,meshMaterial);
            cone1.doubleSided = true;
            cone1.overdraw = true;
            scene.add(cone1);
            var cone2 = new THREE.MESH(lc_relationship.sensor2[i].Geometry,meshMaterial);
            cone2.doubleSided = true;
            cone2.overdraw = true;
            scene.add(cone2);
            var cone3 = new THREE.MESH(lc_relationship.sensor3[i].Geometry,meshMaterial);
            cone3.doubleSided = true;
            cone3.overdraw = true;
            scene.add(cone3);
            cone1.position.set(2*k, 2*j,lc_relationship.sensor1[i].z_cordinate);
            cone2.position.set(2*k, 2*j,lc_relationship.sensor2[i].z_cordinate);
            cone3.position.set(2*k, 2*j,lc_relationship.sensor3[i].z_cordinate);
           }
var light = new THREE.DirectionalLight(0xffffff, 0.6);
light.position.y = 1;
light.position.x = 1;
light.position.z = 1;
scene.add(light);
light = new THREE.DirectionalLight(0xffffff, 0.6);
light.position.y = -1;
light.position.x = -1;
light.position.z = -1;
scene.add(light);
light = new THREE.DirectionalLight(0xffffff, 0.6);
light.position.y = 1;
light.position.x = 0;
light.position.z = 0;
scene.add(light);
container.appendChild( renderer.domElement );
}
 function animate() 
{   
requestAnimationFrame( animate );
render();   
}
  function render() 
{                           
renderer.render(scene, camera);
}
for ( var i = 0; i <nSize; i++)
{
    var k = i%10,
        j = (i-k)/10;

    j = j*2 - 10; // You may need to adjust this "10",
    k = k*2 - 10; // may be "9", so the layers get centered.

    //console.log(j,k)
    var cone1 = new THREE.MESH(lc_relationship.sensor1[i].Geometry,meshMaterial);
    cone1.doubleSided = true;
    cone1.overdraw = true;
    scene.add(cone1);
    var cone2 = new THREE.MESH(lc_relationship.sensor2[i].Geometry,meshMaterial);
    cone2.doubleSided = true;
    cone2.overdraw = true;
    scene.add(cone2);
    var cone3 = new THREE.MESH(lc_relationship.sensor3[i].Geometry,meshMaterial);
    cone3.doubleSided = true;
    cone3.overdraw = true;
    scene.add(cone3);
    cone1.position.set(j, k, lc_relationship.sensor1[i].z_cordinate);
    cone2.position.set(j, k, lc_relationship.sensor2[i].z_cordinate);
    cone3.position.set(j, k, lc_relationship.sensor3[i].z_cordinate);
}