合并后的几何体;t渲染更新
merged geometry doesn't render update
我在添加到场景的网格中有一个合并的几何体。我更新网格中的合并几何体,并将其添加到场景中。这是一个间歇期。
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()
是不必要的。
我希望它能起作用:)
相关文章:
- Javascript循环不会自我更新
- 添加文字和评论功能更新Div
- AngularJS:ng之后,重复$scope值未按预期更新
- 如何通过数组更新角度子范围
- Ajax聊天消息重复而不仅仅是更新
- 通过CSV文件上载更新数据库表
- 平均值:无法将数据更新到数据库
- $rootScope未使用forEach进行更新
- d3基于用户选择动态更新节点
- 有条件更新d3.js力图中节点的最佳方法
- Angular:更新一次性绑定的数据
- Javascript更新孙窗口中的表单元素
- 使用AngularJS中的筛选器更新给定的表
- 从选项页面更新chrome扩展清单权限
- 如何在不刷新页面的情况下更新显示框
- 延期承诺值未更新/解析/延期
- 标记的实时更新,无需加载页面谷歌地图API V3
- 使用mongodb更新中的一个变量
- 合并后的几何体;t渲染更新
- 更新顶点几何体Threejs