Three.js - object.visible = true,没有立即显示 [英] Three.js - object.visible = true, not showing up right away
问题描述
我正在使用对象上的 .visible
属性隐藏和取消隐藏 Three.js 场景的部分内容.
I'm hiding and unhiding parts of my Three.js scene using the .visible
property on my objects.
默认情况下,某些对象(房间)的 .visible
属性为 false
.当相机位于某个网格(房间边界框)内时,.visible
属性设置为 true
并且房间显示出来.
By default certain objects (rooms) have the .visible
property to false
. When the camera is within a certain mesh (the room bounding box) the .visible
property is set to true
and the room shows up.
但是在将 .visible
属性设置为 true
并且房间实际被渲染后似乎有延迟(几秒或更短).多次进入房间后,延迟时间缩短.
But there seems to be a delay (seconds or less) after setting the .visible
property to true
and the room actually being rendered. This delay is shortened after entering the rooms more than once.
这个延迟的原因是什么?有没有办法知道房间何时或是否准备好进行渲染?将 .visible
属性设置为 true
后似乎不会触发更新事件,因此监听这些事件无济于事.
What is the cause of this delay? Is there a way to know when or if the room is ready for rendering? It doesn't seem like update events are being fired after setting the .visible
property to true
, so listening for those won't help.
感谢您的帮助,
您好!
编辑
因为我不能使用 ColladaLoader2.js
我决定简单地遍历加载了 ColladaLoader.js
的模型并用 BufferGeometry 替换所有几何属性
从现有的 Geometry
对象复制.之后我发现将现有 Geometry
对象的 .dynamic
属性设置为 false 似乎具有相同的效果.
Because I couldn't use ColladaLoader2.js
I decided to simply traverse the models loaded with the ColladaLoader.js
and replace all geometry properties with a BufferGeometry
copy made from the existing Geometry
object. After that I found out that setting the .dynamic
property of an existing Geometry
object to false seems to have the same effect.
dae.traverse(function (obj) {如果(obj.hasOwnProperty('几何')){obj.dynamic = 假;//obj.geometry = new THREE.BufferGeometry().fromGeometry(obj.geometry);}});
现在,当我将对象的 .visible
属性设置为 true
时,引擎会冻结一段时间,而不是前面提到的对象变为可见之前的延迟.现在我必须决定我希望在何处发生少量冻结,因为出于性能原因,我不认为所有对象都可以同时可见.
Now when I set the object's .visible
property to true
the engine freezes for a little while, instead of the earlier mentioned delay before the object becomes visible. For now I'll have to decide where I want to little freeze to occur, because I don't think all objects can be visible at the same time for performance reasons.
如果有更多关于对象及其几何体是否已加载并准备好查看,或者是否需要重新加载到内存中的控制和信息,那就太好了.现在还不清楚当 .visible
设置为 true
时 BufferGeometry
是否会立即显示,否则会发生短暂的冻结.
It would be nice to have more control and information about if an object and it's geometry is loaded and ready to be viewed, or if it needs to be reloaded into memory. Now it's unclear if a BufferGeometry
will show up immediately when .visible
is set to true
or a short freeze will occur.
推荐答案
Geometry
需要在渲染前转换为 BufferGeometry
.如果 mesh.visible
为 false
,则不会发生此转换.如果您的几何图形很复杂,或者要转换的几何图形很多,则转换可能需要一些时间.
Geometry
needs to be converted to BufferGeometry
prior to rendering. This conversion will not occur if mesh.visible
is false
. The conversion can take some time if your geometries are complex, or if there are a lot of geometries to convert.
解决方法是使用 BufferGeometry
创建网格.
A work-around is to create your meshes using BufferGeometry
.
var bufferGeometry = new THREE.BufferGeometry().fromGeometry( geometry );
var mesh = new THREE.Mesh( bufferGeometry, material );
three.js r.73
three.js r.73
这篇关于Three.js - object.visible = true,没有立即显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!