0

My object separated into 9 files, so I need to load all 9 files: file_1.obj, ..., file_9.obj, merge them all and after that somehow use file.mtl with the result "big" object. How am I suppose to do it?

I thought about this solution:

mainObjGeometry = new THREE.Geometry();
loader.load( 'file_1.obj', function ( object ) {
    object.updateMatrix();
    mainObjGeometry.merge(object.geometry, object.matrix);
});
...
loader.load( 'file_9.obj', function ( object ) {
    object.updateMatrix();
    mainObjGeometry.merge(object.geometry, object.matrix);
});

And after that load .mtl file and connect them (even though I don't know how to do it).

But I think that using this technique I can not know the time when all objects are loaded.

How can I solve this problem? And can I connect "mainObjGeometry" and loaded from .mtl "mainObjMaterial"?

Eugene Kolesnikov
  • 643
  • 2
  • 6
  • 15

1 Answers1

0

You can know the time when all the files load. For example, you have:

loader.load( 'file_9.obj', function ( object ) {
    object.updateMatrix();
    mainObjGeometry.merge(object.geometry, object.matrix);
});

do this:

var totalModels = 0, loadedModels = 0;

function allLoadedCallback(){...}

loader.load( 'file_9.obj', function ( object ) {
    object.updateMatrix();
    mainObjGeometry.merge(object.geometry, object.matrix);
    loadedModels++
    if(loadedModel == totalModels) allLoadedCallback();

});
totalModels++;

The other part of the question i'm not so sure about. Why can't you merge the model before even exporting it. That way at least the exported material would make sense. I'm not too familiar with the merge utility, but I can see you having problems if you are trying to merge the materials without properly loading them first.

pailhead
  • 5,162
  • 2
  • 25
  • 46
  • Thank you for your reply, you helped me a lot. I've solved the second question without merging all 9 objects, I've just loaded each object with .mtl file using OBJMTLLoader and added this object to scene, so I have not 1 object but an array of 9 objects. – Eugene Kolesnikov Aug 07 '14 at 08:55