2016-04-10 6 views
0

シーンに追加されたメッシュにジオメトリがマージされています。私は、メッシュ内のマージドジオメトリを更新し、シーンに追加します。これはある間隔です。three.js - マージジオメトリは更新をレンダリングしません

scene.remove(that.graph[i]); 
that.graph[i].geometry.dispose(); 

     var planeMaterial = new THREE.MeshLambertMaterial({ 
      color: 0xffffff, 
      vertexColors: THREE.VertexColors 
     }); 
     var boxGeometry = new THREE.BoxGeometry(50, 50, Math.random() * 10000, 1, 1); 
     var cube = new THREE.Mesh(boxGeometry, planeMaterial); 

     cube.material.color = new THREE.Color(1,0,0); 

     cube.updateMatrix(); 
     that.graph[i].geometry.dynamic = true; 
     that.graph[i].geometry.merge(cube.geometry, cube.matrix); 
     that.graph[i].geometry.mergeVertices(); 
     that.graph[i].geometry.verticesNeedUpdate = true; 
     that.graph[i].geometry.elementsNeedUpdate = true; 
     that.graph[i].geometry.morphTargetsNeedUpdate = true; 
     that.graph[i].geometry.uvsNeedUpdate = true; 
     that.graph[i].geometry.normalsNeedUpdate = true; 
     that.graph[i].geometry.colorsNeedUpdate = true; 
     that.graph[i].geometry.tangentsNeedUpdate = true; 
     that.graph[i].geometry.groupsNeedUpdate = true; 

     scene.add(that.graph[i]); 

私は更新フラグのほとんどを必要としないことを知っているが、私はすべてを追加したことを示したかったです。

ジオメトリは更新されていますが、最初のレンダリング後はレンダリングされません。

これまでレンダリングできる唯一の方法は、メッシュがシーンに追加される前に以下を追加することです。

that.graph[i].geometry = that.graph[i].geometry.clone(); 

しかし、これにより、約5回の反復後にタブがクラッシュします。

メッシュが新しいジオメトリで更新されないのはなぜですか?

答えて

0

私がgeometry.dispose()を理解している限り、ジオメトリオブジェクトをメモリから削除するので、merge()のようなメソッドはもう動作しません。新しいジオメトリをマージしないようにしよう、しかしthat.graph[i].geometryに割り当てる:

ところで
that.graph[i].geometry.dispose(); 

that.graph[i].geometry = new THREE.BoxGeometry(50, 50, Math.random() * 10000, 1, 1); 

// I don't see, where you are setting up a matrix, and there is no need to create a mesh anymore 
// but if you still need to apply a matrix do 
that.graph[i].geometry.applyMatrix(matrix); 

// if you want to change the material, e.g. you could do 
that.graph[i].material.color.setRGB(1,0,0); 

:私が思うに、scene.remove()scene.add()は不要です。

私はそれがうまくいきます:)

関連する問題