管几何不使用顶点数组[THREE.js]

时间:2017-10-28 04:15:34

标签: javascript arrays three.js geometry vertices

我在从数组随机点创建管样条时遇到一些问题。我不知道为什么这不起作用。

我收到此错误:

未捕获的TypeError:无法读取未定义的属性“x”

    for (var i = 0; i < 5; i++) {

                    //particle = new THREE.Sprite( material );
                    particle.position.x = (Math.random() - 0.5)* 20;
                    particle.position.y = (Math.random() - 0.5)* 20;
                    particle.position.z = (Math.random() - 0.5)* 20;

                    particle.scale.x = particle.scale.y = 1;
                    scene.add( particle );

                    geometry.vertices.push( particle.position );

                    //var line = new THREE.Line( geometry, new THREE.LineBasicMaterial( { color: 0xffffff, opacity: 0.5 } ) );

                    //scene.add( line );

//HERE IS WHERE THE PROBLEM START

        var tubeVertices = new THREE.Vector3(geometry.vertices);
        var Spline = new THREE.CatmullRomCurve3( 
                  tubeVertices
                 );

        var material = new THREE.MeshLambertMaterial( { color: 0xff00ff } );
        var tubeGeometry = new THREE.TubeGeometry( Spline, 5, 1, 5);
        var tube = new THREE.Mesh(tubeGeometry,material);
        scene.add( tube );   

       }

我曾尝试过这种方式,但它也不起作用。我添加了错误的图片。

    ....
    var tubeVertices = new THREE.Vector3(geometry.vertices[1]);
    console.log(tubeVertices);

     var sampleClosedSpline = new THREE.CatmullRomCurve3( 
                new THREE.Vector3(geometry.vertices[0]),
                new THREE.Vector3(geometry.vertices[1]),
                new THREE.Vector3(geometry.vertices[2]),
                new THREE.Vector3(geometry.vertices[3]),
                new THREE.Vector3(geometry.vertices[4])
             );
   ...

here is what i am trying to make ERROR_IMG

提前谢谢

0 个答案:

没有答案