コード例 #1
0
ファイル: handlers.py プロジェクト: OpenWRLD/mixer
def update_object_state(old_objects: dict, new_objects: dict):
    stats_timer = share_data.current_stats_timer

    with stats_timer.child("checkobjects_addedAndRemoved"):
        objects = set(new_objects.keys())
        share_data.objects_added = objects - old_objects.keys()
        share_data.objects_removed = old_objects.keys() - objects

    share_data.old_objects = new_objects

    if len(share_data.objects_added) == 1 and len(
            share_data.objects_removed) == 1:
        share_data.objects_renamed[list(share_data.objects_removed)[0]] = list(
            share_data.objects_added)[0]
        share_data.objects_added.clear()
        share_data.objects_removed.clear()
        return

    if len(share_data.objects_added) > 1 and len(
            share_data.objects_removed) > 1:
        logger.error(
            f"more than one object renamed: unsupported{share_data.objects_added} {share_data.objects_removed}"
        )

    for obj_name in share_data.objects_removed:
        if obj_name in share_data.old_objects:
            del share_data.old_objects[obj_name]

    with stats_timer.child("updateObjectsParentingChanged"):
        for obj_name, parent in share_data.objects_parents.items():
            if obj_name not in share_data.old_objects:
                continue
            new_obj = share_data.old_objects[obj_name]
            new_obj_parent = "" if new_obj.parent is None else new_obj.parent.name_full
            if new_obj_parent != parent:
                share_data.objects_reparented.add(obj_name)

    with stats_timer.child("update_objects_visibilityChanged"):
        for obj_name, visibility in share_data.objects_visibility.items():
            new_obj = share_data.old_objects.get(obj_name)
            if not new_obj:
                continue
            if visibility != object_visibility(new_obj):
                share_data.objects_visibility_changed.add(obj_name)

    update_frame_changed_related_objects_state(old_objects, new_objects)
コード例 #2
0
ファイル: handlers.py プロジェクト: pypingyi/mixer
def update_object_state(old_objects: dict, new_objects: dict):

    objects = set(new_objects.keys())
    share_data.objects_added = objects - old_objects.keys()
    share_data.objects_removed = old_objects.keys() - objects

    share_data.old_objects = new_objects

    if len(share_data.objects_added) == 1 and len(
            share_data.objects_removed) == 1:
        share_data.objects_renamed[list(share_data.objects_removed)[0]] = list(
            share_data.objects_added)[0]
        share_data.objects_added.clear()
        share_data.objects_removed.clear()
        return

    if len(share_data.objects_added) > 1 and len(
            share_data.objects_removed) > 1:
        logger.error(
            f"more than one object renamed: unsupported{share_data.objects_added} {share_data.objects_removed}"
        )

    for obj_name in share_data.objects_removed:
        if obj_name in share_data.old_objects:
            del share_data.old_objects[obj_name]

    for obj_name, parent in share_data.objects_parents.items():
        if obj_name not in share_data.old_objects:
            continue
        new_obj = share_data.old_objects[obj_name]
        new_obj_parent = "" if new_obj.parent is None else new_obj.parent.name_full
        if new_obj_parent != parent:
            share_data.objects_reparented.add(obj_name)

    for obj_name, visibility in share_data.objects_visibility.items():
        new_obj = share_data.old_objects.get(obj_name)
        if not new_obj:
            continue
        if visibility != object_visibility(new_obj):
            share_data.objects_visibility_changed.add(obj_name)

    for obj_name, constraints in share_data.objects_constraints.items():
        new_obj = share_data.old_objects.get(obj_name)
        if not new_obj:
            continue
        new_constraints = get_object_constraints(new_obj)
        if new_constraints.has_parent_constraint and not constraints.has_parent_constraint:
            share_data.objects_constraints_added.add(
                (obj_name, constraint_api.ConstraintType.PARENT,
                 new_constraints.parent_target.name_full))
        elif (constraints.has_parent_constraint
              and new_constraints.has_parent_constraint
              and constraints.parent_target != new_constraints.parent_target):
            share_data.objects_constraints_added.add(
                (obj_name, constraint_api.ConstraintType.PARENT,
                 new_constraints.parent_target.name_full))
        elif not new_constraints.has_parent_constraint and constraints.has_parent_constraint:
            share_data.objects_constraints_removed.add(
                (obj_name, constraint_api.ConstraintType.PARENT))

        if new_constraints.has_look_at_constraint and not constraints.has_look_at_constraint:
            share_data.objects_constraints_added.add(
                (obj_name, constraint_api.ConstraintType.LOOK_AT,
                 new_constraints.look_at_target.name_full))
        elif (constraints.has_look_at_constraint
              and new_constraints.has_look_at_constraint and
              constraints.look_at_target != new_constraints.look_at_target):
            share_data.objects_constraints_added.add(
                (obj_name, constraint_api.ConstraintType.LOOK_AT,
                 new_constraints.look_at_target.name_full))
        elif not new_constraints.has_look_at_constraint and constraints.has_look_at_constraint:
            share_data.objects_constraints_removed.add(
                (obj_name, constraint_api.ConstraintType.LOOK_AT))

    update_frame_changed_related_objects_state(old_objects, new_objects)