CesiumGS / obj2gltf

Convert OBJ assets to glTF
Apache License 2.0
1.7k stars 307 forks source link

trouble to separate one combined obj to a set of individual objs then to gltfs #135

Open zhuqingchao opened 6 years ago

zhuqingchao commented 6 years ago

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.

lilleyse commented 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.

silvainSayduck commented 6 years ago

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
simonasdmd commented 4 years ago

It's important to know how to convert gltf to b3dm, which I think should be provided.