May pycollada be used to merge multiple collada files?

516 views
Skip to first unread message

Kang Zhao

unread,
Mar 10, 2013, 8:42:05 AM3/10/13
to pyco...@googlegroups.com
I have multiple parts modeled independently in collada format.  I am curious if pycollada can be used to assemble them and export as a single collada file. Any input is appreciated.

Kang

Jeff Terrace

unread,
Mar 10, 2013, 3:53:46 PM3/10/13
to zhaok...@gmail.com, pyco...@googlegroups.com
Yes, you could definitely use it for that. I'm not aware of any code out there for already doing this. However, there's code in meshtool for combining multiple geometries within a single collada file. You could do something similar but across files:
https://github.com/pycollada/meshtool/blob/master/meshtool/filters/optimize_filters/combine_primitives.py

Jeff


On Sun, Mar 10, 2013 at 5:42 AM, Kang Zhao <zhaok...@gmail.com> wrote:
I have multiple parts modeled independently in collada format.  I am curious if pycollada can be used to assemble them and export as a single collada file. Any input is appreciated.


Kang

--
You received this message because you are subscribed to the Google Groups "pycollada" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pycollada+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Kang Zhao

unread,
Mar 14, 2013, 8:13:49 AM3/14/13
to pyco...@googlegroups.com, zhaok...@gmail.com
Hi Jeff,

Thanks a lot for your reply. I will give a try.

Kang

Kang Zhao

unread,
Apr 1, 2013, 6:05:41 PM4/1/13
to Jeff Terrace, pyco...@googlegroups.com
Hi Jeff,

I guess I should share a feedback.

After some experiments, I managed to merge multiple Collada files into a single one with following simple code (with pycollada, not meshtool). With limited knowledge about Collada format and pycollada code, I am not sure if my implementation makes sense at all, but I do get the expected results in my particular application.  Any comment or suggestion is appreciated.

> cat merge_colladas.py

import collada

def merge_collada_files(list_fpath_inputs, fpath_output):
    list_collada_objects = []
    for fpath_input in list_fpath_inputs:
        list_collada_objects.append(collada.Collada(fpath_input))
    merged_collada_object = merge_collada_objects(list_collada_objects)
    merged_collada_object.write(fpath_output)

def merge_collada_objects(list_collada_objects):
   
    merged_collada_object = collada.Collada()  
    
    if len(list_collada_objects) == 0:
        return merged_collada_object
   
    merged_collada_object.assetInfo = list_collada_objects[0].assetInfo

    list_nodes_of_scene = []
    for mesh in list_collada_objects:
        merged_collada_object.effects.extend(mesh.effects)
        merged_collada_object.materials.extend(mesh.materials)
        merged_collada_object.geometries.extend(mesh.geometries)
       
        for scene in mesh.scenes:
            list_nodes_of_scene.extend(scene.nodes)         
       
    myscene = collada.scene.Scene("myscene", list_nodes_of_scene)
    merged_collada_object.scenes.append(myscene)
    merged_collada_object.scene = myscene       
           
    return merged_collada_object


# here is one example to use the above code

fpath_output = "D:\\download\\dae_examples\\merged.dae"
list_fpath_inputs = []
list_fpath_inputs.append("D:\\download\\dae_examples\\1.dae")
list_fpath_inputs.append("D:\\download\\dae_examples\\2.dae")
merge_collada_files(list_fpath_inputs, fpath_output)

Thanks,
Kang

Jeff Terrace

unread,
Apr 1, 2013, 6:23:11 PM4/1/13
to Kang Zhao, pyco...@googlegroups.com
Looks pretty good to me. Glad it worked out for you,

Jeff
Reply all
Reply to author
Forward
0 new messages