So since Three.js has deprecated its blender json exporter, I have begun playing with the GLTFLoader.
I only need to load the geometry of one mesh at a time.
Is there a standard way to do this or do I need to go through the scene.children and hand select what I need and clone geometry of autocreated skinnedmesh? Doing this I probably would have to be careful to dispose any auto created default materials and nullify the auto created mesh right?
My material system is database driven so I can easily control and reuse materials and geometries on several meshes.
Is there like a “SimpleGLTFloader” or something?
The object returned by GLTFLoader contains a parser reference, which you can make use of:
var loader = new THREE.GLTFLoader();
loader.load('foo.gltf', async (gltf) => {
var parser = gltf.parser;
var mesh = await parser.getDependency( 'mesh', 0 ); // Promise
var meshes = await parser.getDependencies( 'mesh' );
});
But in that case, it still instantiates everything the file contains anyway. Adding a mode where it does everything lazily could be a good change, along with access to the glTF JSON data so you can figure out the index of the mesh you want. Something like:
var loader = new THREE.GLTFLoader();
loader.setMode( THREE.GLTFLoader.LAZY );
loader.load('foo.gltf', async (gltf) => {
var json = gltf.json;
var parser = gltf.parser;
var myMeshIndex = json.meshes.findIndex((m) => m.name === 'my_mesh');
var mesh = await parser.getDependency( 'mesh', myMeshIndex );
} );
^That isn’t supported now — setMode
doesn’t exist, and gltf.json
isn’t exposed — but the code is structured to support that if you want to try a PR. I think it would be a fairly small change, and would avoid doing any extra loading until you request something that requires it.