Open zhuqingchao opened 6 years ago
I think as long as you pass in the materials array from loadObj
to each call to createGltf
it should be able to match up each primitive with each material.
However I haven't used obj2gltf
in this way before so if you are able to send more sample code that would help.
Just as an FYI, I was also trying to split OBJs in separate files based on the groups, and I succeeded using this approach after a bit of trial-and-error. See sample code below (this disregards any .mtl material that might be referenced in the .obj):
var objData;
loadObj('/path/to/multi-group/asset.obj', options).then(function(data){
objData = data;
});
var gltf = createGltf({ // creates the gltf for the first group in the .obj
nodes: [ objData.nodes[0] ],
materials:[],
name:objData.nodes[0].name
}, options);
writeGltf(gltf, options); // writes the .bin file and cleans up the gltf (removes empty nodes, ...)
var fileData = Buffer.from(JSON.stringify(gltf));
fs.writeFileSync(objData.nodes[0].name + '.gltf', fileData); // writes the .gtlf file
It's important to know how to convert gltf to b3dm, which I think should be provided.
here is my steps, help me 1、objdatas = loadObj(obj) // try to assemble a set of objs whit the objdatas // objs =[] objs = splitObjdatas( objdatas ) // try to transform obj to gltf one by one for obj in objs createGltf ( obj, options) writeGltf ... 2、i get the right set of models/gltfs/glbs, but i found the gltfs'textures have wrong performance except the first one. 3、i guess the textures properties made with the index of node, but i can't find how it work, please give me some suggestions 4、the final goal is to transform one combined obj to 3dtiles with a set of .b3dm.