合并后的几何体;t渲染更新

merged geometry doesn't render update

本文关键字:更新 几何体 合并      更新时间:2024-04-14

我在添加到场景的网格中有一个合并的几何体。我更新网格中的合并几何体,并将其添加到场景中。这是一个间歇期。

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次迭代后崩溃。

为什么我的网格没有使用新几何体更新?

就我对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);

BTW:我认为scene.remove()scene.add()是不必要的。

我希望它能起作用:)