admin管理员组文章数量:1327277
I have a JSON model being loaded successfully based on AlteredQualia's skinning example. However, I would like to not reveal the model until it is finished loading. As you can see in this example, the models appear first and then their texture resources load afterwards: .html
I added an opaque div to my webpage and then using the callback of the JSONloader.load() function I move that div out of the way. Unfortunately this callback is triggered when the mesh is added to the scene, which does not seem to be blocked by the skinning images still being loaded, so I end up "revealing" an inplete scene.
How should I go about fixing this? I have seen that there is a function THREE.ImageUtils.loadTexture() which has a callback function but it does not seem to be involved in this use case where the mesh is declared and defined like so:
var mesh = new THREE.SkinnedMesh(geometry,new THREE.MeshFaceMaterial(materials));
//geometry and materials are both parameters of jsonloader.load callback
I had a look at the source code of MeshFaceMaterial and SkinnedMesh but could not see a solution there.
Thanks for any assistance offered.
I have a JSON model being loaded successfully based on AlteredQualia's skinning example. However, I would like to not reveal the model until it is finished loading. As you can see in this example, the models appear first and then their texture resources load afterwards: http://alteredqualia./three/examples/webgl_animation_skinning_tf2.html
I added an opaque div to my webpage and then using the callback of the JSONloader.load() function I move that div out of the way. Unfortunately this callback is triggered when the mesh is added to the scene, which does not seem to be blocked by the skinning images still being loaded, so I end up "revealing" an inplete scene.
How should I go about fixing this? I have seen that there is a function THREE.ImageUtils.loadTexture() which has a callback function but it does not seem to be involved in this use case where the mesh is declared and defined like so:
var mesh = new THREE.SkinnedMesh(geometry,new THREE.MeshFaceMaterial(materials));
//geometry and materials are both parameters of jsonloader.load callback
I had a look at the source code of MeshFaceMaterial and SkinnedMesh but could not see a solution there.
Thanks for any assistance offered.
Share Improve this question edited Dec 22, 2013 at 5:00 user128511 asked Dec 20, 2013 at 21:15 BrianBrian 1161 silver badge5 bronze badges3 Answers
Reset to default 3This is currently not properly sorted out. At the moment there is no callback or event dispatched when everything is loaded :/
This is a bit of a hack, but at line 10362 (revision 61) of three.js you will see image.onload = function()
(it's in the main THREE.Loader prototype). I managed to track that down to be the callback function for loaded textures from JSON models.
If you add your own callback inside that function you can track when textures are loaded.
As I said before though, this is a hack (which helped me out a lot for a particular application) and not a solution, be very careful modifying the library code. You might break stuff you don't know you're breaking.
This is a ridiculously stupid cheat, but it will work as a hack. I agree one needs to realize image loading and everything else at least separately, so things that don't need images aren't twiddling their little electronic thumbs. That said, if optimization ain't your problem......
var texture = THREE.ImageUtils.loadTexture(url);
while (texture.image.width == 0);
本文标签: javascriptHow to wait for textures to finish loading from JSON model in ThreejsStack Overflow
版权声明:本文标题:javascript - How to wait for textures to finish loading from JSON model in Three.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742209349a2433417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论