Closed kfarr closed 1 year ago
Hi Kieran, I took a look at the glitch and I'm not sure I understand what the problem is?
The multiple instances of the car seem to be rendering OK to me. Can you explain what the issue is?
I'll post some updates on #28 with latest status there.
Hey @diarmidmackenzie sorry for the utterly confusing glitch. I've updated it to (a) remove the confusing street scene and (b) to show 4 examples clearly commented:
<!-- normal gltf loader using asset loader -->
<a-entity position="1 0 -5" gltf-model="#car-model"></a-entity>
<!-- instanced mesh using asset loader -->
<a-entity id="car-instanced" gltf-model="#car-model" instanced-mesh="capacity: 1000; positioning: world; updateMode: auto"></a-entity>
<a-entity position="-1 0 -10" instanced-mesh-member="mesh:#car-instanced"></a-entity>
<!-- using 3dstreet mixin (which uses gltf-model="url(path)" scheme) -->
<a-entity position="-1 0 -5" mixin="sedan-rig"></a-entity>
<!-- instanced mesh using 3dstreet mixin -->
<a-entity id="car-instanced-mixin" mixin="sedan-rig" instanced-mesh="capacity: 1000; positioning: world; updateMode: auto"></a-entity>
<a-entity position="1 0 -10" instanced-mesh-member="mesh:#car-instanced-mixin"></a-entity>
The "normal" loading ones are closest to the camera at -5 z and the instanced ones are at -10 z but neither appears to load.
Why am I bothering you about this? We are finally getting close to creating scenes to "show off" 3dstreet like this one: https://little-slow-november.glitch.me/ and we plan to have many vehicles and buildings that would definitely benefit from this component. That said there are a lot of irons in the fire right now so this is not urgent and I don't want to distract from higher priority things you might be working on.
OK - this issue is that the model uses a SkinnedMesh, which isn't working.
The issue is with the code that traverses the GLTF model searching for the Meshes that make up the model. https://github.com/diarmidmackenzie/instanced-mesh/blob/3c1ce5f06898fefde7232db2f518f5748fe22dda/src/instanced-mesh.js#L352
It identifies object3Ds of type 'Mesh', but not of type 'SkinnedMesh'.
There's no support in Three.js for instancing of skinned meshes....
....so I'm not sure this can be accommodated very easily. Edit: here's the latest on Instanced Skinned Meshes in THREE.js. Maybe not a million miles away from happening...
However I can definitely do a better job of error handling in this case. For now, I'll do a quick PR to document the restricton & provide a helpful error message when using Skinned Meshes.
Do you have the option of moving your model away from a Skinned Mesh?
One approach that may be useful in some cases would be to bake the default skeleton position into a standard Mesh. This would lose the animation capabilities of the Skinned Mesh, but would at least render a static version of the Skinned Mesh correctly.
Not sure I want to encourage this, though - in most cases, it's going to be preferable to pre-bake the bone positions into the model, and create a new GLTF that contains a Mesh rather than a Skinned Mesh.
It would be nice to be able to recommend a tool that can do this, but I don't know of one.
It's possible this baking can be done in Blender using something like this: https://blender.stackexchange.com/questions/22882/how-do-i-delete-an-armature-but-keep-the-baked-pose
Thanks @diarmidmackenzie you're totally right and sorry for not thinking of this earlier. We will do this again with simplified models.
closing for now since this is out of scope for this component
Hi Diarmid, not urgent but I was trying to get a basic example working but was not successful. Here is the sample project, all it is doing is loading a street and then trying to load 1 instance of an instanced mesh. Is there anything obviously wrong with my setup here or is this a bigger issue related to #28 ?
https://glitch.com/edit/#!/3dstreet-simple-instanced-mesh