def _fix_ex_parent(obj): """Fixes ex parent settings which were caused by re/unparenting. NOTE: ex parent is readed from parent identity property :param obj: SCS Blender object from which ex parent object should be taken :type obj: bpy.types.Object """ # fix children count for ex parent if obj.scs_props.parent_identity in bpy.data.objects: ex_parent_obj = bpy.data.objects[obj.scs_props.parent_identity] ex_parent_obj.scs_cached_num_children = len(ex_parent_obj.children) ex_parent_scs_root = _object_utils.get_scs_root(ex_parent_obj) if ex_parent_scs_root: _looks.clean_unused(ex_parent_scs_root)
def __material_assignement__(obj, new_mat_ids, removed_mat_ids): """Hookup function for material reassignement on object. :param obj: object on which material assignement happend :type obj: bpy.types.Object :param new_mat_ids: ID of newly added materials :type new_mat_ids: iter :param removed_mat_ids: ID of removed materials :type removed_mat_ids: iter """ # create actual new materials list new_mats = [] for mat in bpy.data.materials: curr_mat_id = str(mat.scs_props.id) if curr_mat_id in new_mat_ids: new_mats.append(mat) scs_root = _object_utils.get_scs_root(obj) if scs_root: _looks.add_materials(scs_root, new_mats) if len(removed_mat_ids) > 0: _looks.clean_unused(scs_root)
def make_scs_root_object(context, dialog=False): # FAIRLY SMART SELECTION OF SCS GAME OBJECT CONTENT scs_game_object_content = [] for obj in context.selected_objects: if not obj.parent: scs_game_object_content.append(obj) else: if not obj.parent.select: scs_game_object_content.append(obj) # ADD SCS ROOT OBJECT (EMPTY OBJECT) bpy.ops.object.empty_add( view_align=False, location=context.scene.cursor_location, ) # SET PROPERTIES name = _name.get_unique("game_object", bpy.data.objects) bpy.context.active_object.name = name new_scs_root = bpy.data.objects.get(name) new_scs_root.scs_props.scs_root_object_export_enabled = True new_scs_root.scs_props.empty_object_type = 'SCS_Root' # SET A NEW NAME DIALOG if dialog: bpy.ops.object.add_scs_root_object_dialog_operator('INVOKE_DEFAULT') # PARENT OBJECTS TO SCS ROOT OBJECT part_inventory = new_scs_root.scs_object_part_inventory if len(scs_game_object_content) > 0: bpy.ops.object.select_all(action='DESELECT') new_scs_root_mats = [] # select content object for parenting later for obj in scs_game_object_content: obj.select = True # fix old parent with new children number and cleaned looks if obj.parent: ex_parent_obj = obj.parent obj.parent = None ex_parent_obj.scs_cached_num_children = len( ex_parent_obj.children) ex_parent_scs_root = get_scs_root(ex_parent_obj) if ex_parent_scs_root: _looks.clean_unused(ex_parent_scs_root) obj.scs_props.parent_identity = new_scs_root.name obj.scs_cached_num_children = len(obj.children) for slot in obj.material_slots: if slot.material and slot.material not in new_scs_root_mats: new_scs_root_mats.append(slot.material) _looks.add_materials(new_scs_root, new_scs_root_mats) bpy.ops.object.parent_set(type='OBJECT', keep_transform=False) bpy.ops.object.select_all(action='DESELECT') new_scs_root.select = True # fix children count to prevent persistent to hook up new_scs_root.scs_cached_num_children = len(new_scs_root.children) for part_name in collect_parts_on_root(new_scs_root): _inventory.add_item(part_inventory, part_name) # MAKE DEFAULT PART IF THERE IS NO PARTS if len(part_inventory) == 0: _inventory.add_item(part_inventory, _PART_consts.default_name) return new_scs_root
def make_scs_root_object(context, dialog=False): # FAIRLY SMART SELECTION OF SCS GAME OBJECT CONTENT scs_game_object_content = [] for obj in context.selected_objects: if not obj.parent: scs_game_object_content.append(obj) else: if not obj.parent.select: scs_game_object_content.append(obj) # ADD SCS ROOT OBJECT (EMPTY OBJECT) bpy.ops.object.empty_add(view_align=False, location=context.scene.cursor_location) # SET PROPERTIES name = _name.get_unique("game_object", bpy.data.objects) bpy.context.active_object.name = name new_scs_root = bpy.data.objects.get(name) new_scs_root.scs_props.scs_root_object_export_enabled = True new_scs_root.scs_props.empty_object_type = "SCS_Root" # SET A NEW NAME DIALOG if dialog: bpy.ops.object.add_scs_root_object_dialog_operator("INVOKE_DEFAULT") # PARENT OBJECTS TO SCS ROOT OBJECT part_inventory = new_scs_root.scs_object_part_inventory if len(scs_game_object_content) > 0: bpy.ops.object.select_all(action="DESELECT") new_scs_root_mats = [] # select content object for parenting later for obj in scs_game_object_content: obj.select = True # fix old parent with new children number and cleaned looks if obj.parent: ex_parent_obj = obj.parent obj.parent = None ex_parent_obj.scs_cached_num_children = len(ex_parent_obj.children) ex_parent_scs_root = get_scs_root(ex_parent_obj) if ex_parent_scs_root: _looks.clean_unused(ex_parent_scs_root) obj.scs_props.parent_identity = new_scs_root.name obj.scs_cached_num_children = len(obj.children) for slot in obj.material_slots: if slot.material and slot.material not in new_scs_root_mats: new_scs_root_mats.append(slot.material) _looks.add_materials(new_scs_root, new_scs_root_mats) bpy.ops.object.parent_set(type="OBJECT", keep_transform=False) bpy.ops.object.select_all(action="DESELECT") new_scs_root.select = True # fix children count to prevent persistent to hook up new_scs_root.scs_cached_num_children = len(new_scs_root.children) for part_name in collect_parts_on_root(new_scs_root): _inventory.add_item(part_inventory, part_name) # MAKE DEFAULT PART IF THERE IS NO PARTS if len(part_inventory) == 0: _inventory.add_item(part_inventory, _PART_consts.default_name) return new_scs_root