12

私はTHREE.JSrev49を使用しています。

私のプログラムは、ジオメトリを変更してメッシュを更新する必要があります。残念ながら、表示は更新されていないようです。

これが私のコードです:

// 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;

}

他に何か追加する必要がありますか?

/ Oragon

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 = trueます。verticesNeedUpdate = trueelse{}

于 2013-03-13T12:27:56.920 に答える
3

ジオメトリ全体を変更する場合、最も簡単な方法は、古いものを削除して(scene.remove(geometry))、新しいものを追加する(scene.add(geometry))ことだと思います。メッシュとジオメトリのパラメータを変更するコストだと思います。プロパティは新しいものを追加するのと同じですが、追加する方がはるかに簡単で、多くの頭痛の種を節約できます。

于 2013-06-11T15:24:30.360 に答える