コード例 #1
0
def __gather_animations(blender_scene, export_settings):
    animations = []
    for blender_object in blender_scene.objects:
        # First check if this object is exported or not. Do not export animation of not exported object
        obj_node = gltf2_blender_gather_nodes.gather_node(blender_object, blender_scene, export_settings)
        if obj_node is not None:
            animations += gltf2_blender_gather_animations.gather_animations(blender_object, export_settings)
    return animations
コード例 #2
0
def __gather_animations(blender_scene, anim_scene, export_settings):
    for _blender_object in blender_scene.objects:

        blender_object = _blender_object.proxy if _blender_object.proxy else _blender_object

        # First check if this object is exported or not. Do not export animation of not exported object
        obj_node = gltf2_blender_gather_nodes.gather_node(blender_object,
            blender_object.library.name if blender_object.library else None,
            blender_scene, None, export_settings)

    animations = gltf2_blender_gather_animations.gather_animations(anim_scene, export_settings)
    return animations
コード例 #3
0
def __gather_animations(blender_scene, export_settings):
    animations = []
    for blender_object in blender_scene.objects:
        # First check if this object is exported or not. Do not export animation of not exported object
        obj_node = gltf2_blender_gather_nodes.gather_node(
            blender_object, blender_scene, export_settings)
        if obj_node is not None:
            animations += gltf2_blender_gather_animations.gather_animations(
                blender_object, export_settings)

    # if none of those two actions have been selected,
    # let's merge indivudual animations into one single with multiple channels
    all_actions = export_settings['gltf_all_actions']
    nla_strips = export_settings['gltf_nla_strips']
    if not all_actions and not nla_strips:
        scene_animation = __merge_animations(blender_scene, animations,
                                             export_settings)
        animations = []
        animations.append(scene_animation)

    return animations
コード例 #4
0
def __gather_animations(blender_scene, export_settings):
    animations = []
    for blender_object in blender_scene.objects:
        animations += gltf2_blender_gather_animations.gather_animations(
            blender_object, export_settings)
    return animations
コード例 #5
0
def __gather_animations(blender_scene, export_settings):
    animations = []
    merged_tracks = {}

    for _blender_object in blender_scene.objects:

        blender_object = _blender_object.proxy if _blender_object.proxy else _blender_object

        # First check if this object is exported or not. Do not export animation of not exported object
        obj_node = gltf2_blender_gather_nodes.gather_node(
            blender_object,
            blender_object.library.name if blender_object.library else None,
            blender_scene, None, export_settings)
        if obj_node is not None:
            # Check was done on armature, but use here the _proxy object, because this is where the animation is
            animations_, merged_tracks = gltf2_blender_gather_animations.gather_animations(
                _blender_object, merged_tracks, len(animations),
                export_settings)
            animations += animations_

    if export_settings['gltf_nla_strips'] is False:
        # Fake an animation with all animations of the scene
        merged_tracks = {}
        merged_tracks['Animation'] = []
        for idx, animation in enumerate(animations):
            merged_tracks['Animation'].append(idx)

    to_delete_idx = []
    for merged_anim_track in merged_tracks.keys():
        if len(merged_tracks[merged_anim_track]) < 2:

            # There is only 1 animation in the track
            # If name of the track is not a default name, use this name for action
            if len(merged_tracks[merged_anim_track]) != 0:
                animations[merged_tracks[merged_anim_track]
                           [0]].name = merged_anim_track

            continue

        base_animation_idx = None
        offset_sampler = 0

        for idx, anim_idx in enumerate(merged_tracks[merged_anim_track]):
            if idx == 0:
                base_animation_idx = anim_idx
                animations[anim_idx].name = merged_anim_track
                already_animated = []
                for channel in animations[anim_idx].channels:
                    already_animated.append(
                        (channel.target.node, channel.target.path))
                continue

            to_delete_idx.append(anim_idx)

            # Merging extras
            # Warning, some values can be overwritten if present in multiple merged animations
            if animations[anim_idx].extras is not None:
                for k in animations[anim_idx].extras.keys():
                    if animations[base_animation_idx].extras is None:
                        animations[base_animation_idx].extras = {}
                    animations[base_animation_idx].extras[k] = animations[
                        anim_idx].extras[k]

            offset_sampler = len(animations[base_animation_idx].samplers)
            for sampler in animations[anim_idx].samplers:
                animations[base_animation_idx].samplers.append(sampler)

            for channel in animations[anim_idx].channels:
                if (channel.target.node,
                        channel.target.path) in already_animated:
                    print_console(
                        "WARNING",
                        "Some strips have same channel animation ({}), on node {} !"
                        .format(channel.target.path, channel.target.node.name))
                    continue
                animations[base_animation_idx].channels.append(channel)
                animations[base_animation_idx].channels[
                    -1].sampler = animations[base_animation_idx].channels[
                        -1].sampler + offset_sampler
                already_animated.append(
                    (channel.target.node, channel.target.path))

    new_animations = []
    if len(to_delete_idx) != 0:
        for idx, animation in enumerate(animations):
            if idx in to_delete_idx:
                continue
            new_animations.append(animation)
    else:
        new_animations = animations

    return new_animations
コード例 #6
0
def __gather_animations(blender_scene, export_settings):
    animations = []
    merged_tracks = {}

    vtree = export_settings['vtree']
    for obj_uuid in vtree.get_all_objects():
        blender_object = vtree.nodes[obj_uuid].blender_object

        # Do not manage not exported objects
        if vtree.nodes[obj_uuid].node is None:
            continue

        animations_, merged_tracks = gltf2_blender_gather_animations.gather_animations(obj_uuid, merged_tracks, len(animations), export_settings)
        animations += animations_

    if export_settings['gltf_nla_strips'] is False:
        # Fake an animation with all animations of the scene
        merged_tracks = {}
        merged_tracks['Animation'] = []
        for idx, animation in enumerate(animations):
            merged_tracks['Animation'].append(idx)


    to_delete_idx = []
    for merged_anim_track in merged_tracks.keys():
        if len(merged_tracks[merged_anim_track]) < 2:

            # There is only 1 animation in the track
            # If name of the track is not a default name, use this name for action
            if len(merged_tracks[merged_anim_track]) != 0:
                animations[merged_tracks[merged_anim_track][0]].name = merged_anim_track

            continue

        base_animation_idx = None
        offset_sampler = 0

        for idx, anim_idx in enumerate(merged_tracks[merged_anim_track]):
            if idx == 0:
                base_animation_idx = anim_idx
                animations[anim_idx].name = merged_anim_track
                already_animated = []
                for channel in animations[anim_idx].channels:
                    already_animated.append((channel.target.node, channel.target.path))
                continue

            to_delete_idx.append(anim_idx)

            # Merging extensions
            # Provide a hook to handle extension merging since there is no way to know author intent
            export_user_extensions('merge_animation_extensions_hook', export_settings, animations[anim_idx], animations[base_animation_idx])

            # Merging extras
            # Warning, some values can be overwritten if present in multiple merged animations
            if animations[anim_idx].extras is not None:
                for k in animations[anim_idx].extras.keys():
                    if animations[base_animation_idx].extras is None:
                        animations[base_animation_idx].extras = {}
                    animations[base_animation_idx].extras[k] = animations[anim_idx].extras[k]

            offset_sampler = len(animations[base_animation_idx].samplers)
            for sampler in animations[anim_idx].samplers:
                animations[base_animation_idx].samplers.append(sampler)

            for channel in animations[anim_idx].channels:
                if (channel.target.node, channel.target.path) in already_animated:
                    print_console("WARNING", "Some strips have same channel animation ({}), on node {} !".format(channel.target.path, channel.target.node.name))
                    continue
                animations[base_animation_idx].channels.append(channel)
                animations[base_animation_idx].channels[-1].sampler = animations[base_animation_idx].channels[-1].sampler + offset_sampler
                already_animated.append((channel.target.node, channel.target.path))

    new_animations = []
    if len(to_delete_idx) != 0:
        for idx, animation in enumerate(animations):
            if idx in to_delete_idx:
                continue
            new_animations.append(animation)
    else:
        new_animations = animations


    return new_animations
コード例 #7
0
def __gather_animations(blender_scene, export_settings):
    animations = []
    for blender_object in blender_scene.objects:
        animations += gltf2_blender_gather_animations.gather_animations(blender_object, export_settings)
    return animations
コード例 #8
0
def __gather_animations(blender_scene, export_settings):
    animations = []
    merged_tracks = {}

    for blender_object in blender_scene.objects:
        # First check if this object is exported or not. Do not export animation of not exported object
        obj_node = gltf2_blender_gather_nodes.gather_node(
            blender_object, blender_scene, export_settings)
        if obj_node is not None:
            animations_, merged_tracks = gltf2_blender_gather_animations.gather_animations(
                blender_object, merged_tracks, len(animations),
                export_settings)
            animations += animations_

    if export_settings['gltf_nla_strips'] is False:
        # Fake an animation witha all animations of the scene
        merged_tracks = {}
        merged_tracks['Animation'] = []
        for idx, animation in enumerate(animations):
            merged_tracks['Animation'].append(idx)

    to_delete_idx = []
    for merged_anim_track in merged_tracks.keys():
        if len(merged_tracks[merged_anim_track]) < 2:
            continue

        base_animation_idx = None
        offset_sampler = 0

        for idx, anim_idx in enumerate(merged_tracks[merged_anim_track]):
            if idx == 0:
                base_animation_idx = anim_idx
                animations[anim_idx].name = merged_anim_track
                already_animated = []
                for channel in animations[anim_idx].channels:
                    already_animated.append(
                        (channel.target.node, channel.target.path))
                continue

            to_delete_idx.append(anim_idx)

            offset_sampler = len(animations[base_animation_idx].samplers)
            for sampler in animations[anim_idx].samplers:
                animations[base_animation_idx].samplers.append(sampler)

            for channel in animations[anim_idx].channels:
                if (channel.target.node,
                        channel.target.path) in already_animated:
                    print_console(
                        "WARNING",
                        "Some strips have same channel animation ({}), on node {} !"
                        .format(channel.target.path, channel.target.node.name))
                    continue
                animations[base_animation_idx].channels.append(channel)
                animations[base_animation_idx].channels[
                    -1].sampler = animations[base_animation_idx].channels[
                        -1].sampler + offset_sampler
                already_animated.append(
                    (channel.target.node, channel.target.path))

    new_animations = []
    if len(to_delete_idx) != 0:
        for idx, animation in enumerate(animations):
            if idx in to_delete_idx:
                continue
            new_animations.append(animation)
    else:
        new_animations = animations

    return new_animations
コード例 #9
0
def __gather_animations(blender_scene, export_settings):
    for blender_object in blender_scene.objects:
        return gltf2_blender_gather_animations.gather_animations(
            blender_object, export_settings)