Search code examples
pythonnumpyblenderbpy

How to attach multiple mesh nodes to one object in blender?


I try to import 3d objects from one game (IGI 2: Covert Strike) into blender. Ingame format have a one common vertex buffer, where are stored all vertices from multiple meshes. Also have list of structs used to declare meshes, range of used vertices (from common buffer) and position of this mesh relatively to main object.

If I import full vertex boofer into one mesh i see that:

http://prntscr.com/n32e0v

This is a human model. Head are here indide :)

http://prntscr.com/n32fcw

Well I want to separate meshes and attach those to one object. But function

bpy.data.objects.new(name, mesh) #create object

accepts only one mesh.

Is there other way to add multiple mesh nodes to one object?

May be is posible to create one object per mesh and attach those to one main object?

But how later add a common skeleton to all this objects?


Solution

  • First off, you may consider asking this question in Blender SE too, as there is a lot of expertise about Blender in there, so they may be able to give more possible solutions to your problem.

    In any case, I don't think there is any way to have one Blender object hold more than one mesh. You can however group multiple objects under one parent object, something like this (Blender 2.79b):

    import bpy
    
    # Make parent (empty object)
    parent_object = bpy.data.objects.new('parent_object', None)
    bpy.context.scene.objects.link(parent_object)
    # Make multiple children
    for i in range(4):
        # Make child object (mesh object)
        mesh_data = bpy.data.meshes.new('mesh_data_' + str(i + 1))
        mesh_object = bpy.data.objects.new('mesh_object_' + str(i + 1), mesh_data)
        # Set the parent
        mesh_object.parent = parent_object
        bpy.context.scene.objects.link(mesh_object)
    bpy.context.scene.update()
    

    And you will get a hierarchy like this:

    Object hierarchy

    Note: There are some upcoming changes to the API in 2.8, see How do I create a new object using Python in Blender 2.80?.