12

我正在使用 THREE.JS rev 49。

我的程序需要通过更改其几何形状来更新网格。不幸的是,显示似乎没有更新。

这是我的代码:

// theObject is an array of associatives :

// {
//     object1: {mesh: undefined/THREE.mesh, mat: THREE.Material, geo: THREE.Geometry}
//     object2: {mesh: undefined/THREE.mesh, mat: THREE.Material, geo: THREE.Geometry}
//     ...
// }

// In my function, theObject[i].mesh geometry must change to be theObject[i].geo.


for(i in theObjects) {

    //*
    if ( theObjects[i].mesh == undefined) {
        theObjects[i].mesh = new THREE.Mesh(theObjects[i].geo, theObjects[i].mat);

        theObjects[i].mesh.geometry.dynamic = true;
        theObjects[i].geo.verticesNeedUpdate = true;

        scenePostsurgery.add(theObjects[i].mesh);
    }  else
        theObjects[i].mesh.geometry.vertices = theObjects[i].geo.vertices;

}

我必须添加其他东西吗?

/奥拉贡

4

2 回答 2

17

如果我理解正确,您将在此处更新顶点:

else{
        theObjects[i].mesh.geometry.vertices = theObjects[i].geo.vertices;  
}

尝试将此代码更改为:

else{
         theObjects[i].mesh.geometry.dynamic = true;
         theObjects[i].mesh.geometry.vertices = theObjects[i].geo.vertices;  
         theObjects[i].mesh.geometry.verticesNeedUpdate = true;
    }

if(){}您创建一个网格并进行else{}更新时dynamic = trueverticesNeedUpdate = true您需要设置为else{}.

于 2013-03-13T12:27:56.920 回答
3

更改整个几何图形时,我认为最简单的方法是删除旧的(scene.remove(geometry),然后添加新的(scene.add(geometry))。我认为修改网格和几何参数的成本和属性和添加一个新的一样,虽然添加要容易得多,而且省去了很多麻烦!

于 2013-06-11T15:24:30.360 回答