aframevr / aframe

:a: Web framework for building virtual reality experiences.
https://aframe.io/
MIT License
16.61k stars 3.94k forks source link

gtlf-model component reparses same model and creates new texture instances #3975

Open tlaukkan opened 5 years ago

tlaukkan commented 5 years ago

gtlf model component reparses same model for each entity using it even it is referenced via a-assets. It also creates new instances of textures. Having 100 identical entities with gltf-mode="#mymodel" causes slow load time. The entities appear visibly one by one and stats component reports 100 textures if my model has single texture.

tlaukkan commented 5 years ago

@donmccurdy, @dmarcos here is the bug report about gltf-model reparsing the same model as discussed in slack some days ago.

tlaukkan commented 5 years ago

In general it would be nice if textures with exactly same content would be reused even across different models. Something like texture map with content hash as key?

donmccurdy commented 5 years ago

I don't think we can efficiently hash textures, but it should at least be possible to make sure the same texture URL isn't downloaded twice. That probably already is the case.

Ideally, a model could be parsed by the asset system, before being provided to things that depend on it:

<a-assets>
  <a-asset-item id="model" src="model.glb" preprocess="gltf"></a-asset-item>
</a-assets>

I'm not sure how much work that would be to create within core. It seems difficult to do as a third-party component.

ngokevin commented 5 years ago

You can create an invisible "template" gltf model: https://github.com/supermedium/beatsaver-viewer/blob/master/src/index.html#L59

And clone the mesh...something like https://github.com/supermedium/beatsaver-viewer/blob/master/src/components/beat.js#L340 but maybe better to do a full clone. This one just shares the geometry.