【问题标题】:three.js - merged geometry doesn't render updatethree.js - 合并几何不呈现更新
【发布时间】:2016-07-31 07:08:51
【问题描述】:

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

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

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

【问题讨论】:

    标签: javascript three.js


    【解决方案1】:

    据我了解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() 是不必要的。

    我希望,它有效:)

    【讨论】:

      猜你喜欢
      • 2012-10-27
      • 2023-03-03
      • 1970-01-01
      • 2022-10-07
      • 2018-08-19
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多