如何在Three.js中分隔网格的顶点?

时间:2014-10-02 05:55:20

标签: javascript html5 three.js

有没有办法分离Three.js网格的顶点?基本上,我想用鼠标输入撕开和撕开3D对象。最近,我为this web app编写了一个GLSL顶点着色器,它根据视频的亮度来移动网格的顶点。

然而,我不知道如何选择网格的顶点并基本上将它的边缘与它的最近邻居分开,而顶点着色器也在移动对象。

1 个答案:

答案 0 :(得分:0)

使用简单列表选择所有顶点:

var geometry = new THREE.CubeGeometry( 30, 30, 30 ,1,1,1);
for ( var i = 0; i < geometry.vertices.length; i ++ ) {
            var vertices = [];
            for ( var v = 0; v < geometry.vertices.length; v ++ ) {
            vertices.push( geometry.vertices[ v ].clone() );
            if ( v === i ) {
                //getting only Z axis:
                //vertices[ vertices.length - 1 ].x *= 2;
                //vertices[ vertices.length - 1 ].y *= 2;
                vertices[ vertices.length - 1 ].z *= 2;
            }
            }
            geometry.morphTargets.push( { name: "target" + i, vertices: vertices } );
        }
    console.log(geometry.vertices);


//Updating the morphs with new values. We only want to influence one side of the cube
        mesh.morphTargetInfluences[0] = 1
        mesh.morphTargetInfluences[2] = 1
        mesh.morphTargetInfluences[5] = 1
        mesh.morphTargetInfluences[7] = 1