Exemplo n.º 1
0
def load_meshes(
    progress: ProgressReport, manager: ImportManager
) -> List[Tuple[bpy.types.Mesh, gltf_buffer.VertexBuffer]]:

    progress.enter_substeps(len(manager.gltf.meshes), "Loading meshes...")
    meshes = [
        _create_mesh(progress, manager, mesh) for mesh in manager.gltf.meshes
    ]
    progress.leave_substeps()
    return meshes
Exemplo n.º 2
0
def load_materials(progress: ProgressReport,
                   manager: ImportManager) -> List[bpy.types.Material]:

    progress.enter_substeps(len(manager.gltf.textures), "Loading materials...")
    materials = [
        _create_material(progress, manager, material)
        for material in manager.gltf.materials
    ]
    progress.leave_substeps()
    return materials
Exemplo n.º 3
0
def load_objects(context, progress: ProgressReport,
                 manager: ImportManager) -> Tuple[List[Node], Node]:
    progress.enter_substeps(len(manager.gltf.nodes) + 1, "Loading objects...")

    # collection
    view_layer = context.view_layer
    if view_layer.collections.active:
        collection = view_layer.collections.active.collection
    else:
        collection = context.scene.master_collection.new()
        view_layer.collections.link(collection)

    # setup
    nodes = [
        Node(i, gltf_node) for i, gltf_node in enumerate(manager.gltf.nodes)
    ]

    # set parents
    for gltf_node, node in zip(manager.gltf.nodes, nodes):
        for child_index in gltf_node.children:
            child = nodes[child_index]
            node.children.append(child)
            child.parent = node

    progress.step()

    # check root
    roots = [node for node in enumerate(nodes) if not node[1].parent]
    if len(roots) != 1:
        root = Node(len(nodes), gltftypes.Node({'name': '__root__'}))
        for _, node in roots:
            root.children.append(node)
            node.parent = root
    else:
        root = nodes[0]
    root.create_object(progress, collection, manager)

    def get_root(skin: gltftypes.Skin) -> Optional[Node]:

        root = None

        for joint in skin.joints:
            node = nodes[joint]
            if not root:
                root = node
            else:
                if node in root.get_ancestors():
                    root = node

        return root

    # create armatures
    root_skin = gltftypes.Skin({'name': 'skin'})

    for skin in manager.gltf.skins:
        for joint in skin.joints:
            if joint not in root_skin.joints:
                root_skin.joints.append(joint)
    skeleton = get_root(root_skin)

    if skeleton:
        skeleton.create_armature(context, collection, view_layer, root_skin)

    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

    progress.leave_substeps()
    return (nodes, root)