def create_variants(): try: io = IconObjectDB() except ValueError as val_err: general.message_box_ok(str(val_err)) return None general.clear_selection() general.select_object("icon_object_shot") # get the other items name mtl and brush item_filepaths = get_file_path_list(".xml", get_items_dir()) # overwrite the name mtl and brush icon_object_variants = [ { "name": get_item_name_from_xml(filepath), "brush": get_item_geometry_from_xml(filepath), "mtl": get_item_material_from_xml(filepath), "scale": general.get_scale("icon_object_shot"), "pos": general.get_position("icon_object_shot"), "rot": general.get_rotation("icon_object_shot"), } for filepath in item_filepaths ] # save it for icon_obj in icon_object_variants: io.insert_object(icon_obj, override=True)
def test_something(self): io = IconObjectDB() x = io.get_all() objs = list() for obj in io.get_all(): if 'brush' in obj: objs.append(obj['brush']) print objs
def duplicate_change_model(): io = IconObjectDB() with open("D:\perforce\dev\EI\icons\icon_objects.json") as icon_object_json_file: json_db = json.loads("".join(icon_object_json_file.readlines()))["_default"] db_items = [json_db[key] for key in json_db.keys()] plated_items = filter( lambda x: x["brush"].startswith("objects/basebuilding/plated/"), db_items ) wooden_items = map(lambda x: replace_plated_with_wood(x), plated_items) inserted = [io.insert_object(obj) for obj in wooden_items] print(inserted)
def load(): try: io = IconObjectDB() except ValueError as val_err: general.message_box_ok(str(val_err)) return False brush = norm_path_for_ce(general.open_file_box(), maintain_casing=False) obj = io.get_obj_by_brush(brush) if obj is not None: add_to_scene(obj) else: add_to_scene(get_default_object(brush))
def duplicate_change_model(): io = IconObjectDB() with open("D:\perforce\dev\EI\icons\icon_objects.json" ) as icon_object_json_file: json_db = json.loads("".join( icon_object_json_file.readlines()))["_default"] db_items = [json_db[key] for key in json_db.keys()] plated_items = filter( lambda x: x["brush"].startswith("objects/basebuilding/plated/"), db_items) wooden_items = map(lambda x: replace_plated_with_wood(x), plated_items) inserted = [io.insert_object(obj) for obj in wooden_items] print(inserted)
def load_by_name(): try: io = IconObjectDB() except ValueError as val_err: general.message_box_ok(str(val_err)) return False name = general.edit_box("Entity Classname") if not name: return False obj = io.get_obj_by_name(name) print(obj) if obj is not None: add_to_scene(obj) if obj is None: if general.message_box_yes_no("Does not Exist! \n Load By Brush?"): # load it by brush load()
def add_embellishment(): io = IconObjectDB() store = UserValues() obj = get_icon_object_in_scene() obj['embellishment_48'] = '' obj['embellishment_200'] = '' obj['embellishment_2048'] = '' save()
def create_variants(): try: io = IconObjectDB() except ValueError as val_err: general.message_box_ok(str(val_err)) return None general.clear_selection() general.select_object("icon_object_shot") # get the other items name mtl and brush item_filepaths = get_file_path_list(".xml", get_items_dir()) # overwrite the name mtl and brush icon_object_variants = [{ "name": get_item_name_from_xml(filepath), "brush": get_item_geometry_from_xml(filepath), "mtl": get_item_material_from_xml(filepath), "scale": general.get_scale("icon_object_shot"), "pos": general.get_position("icon_object_shot"), "rot": general.get_rotation("icon_object_shot"), } for filepath in item_filepaths] # save it for icon_obj in icon_object_variants: io.insert_object(icon_obj, override=True)
def get_icon_object_in_scene(): try: store = UserValues() io = IconObjectDB() except ValueError as val_err: general.message_box_ok(str(val_err)) return None store_obj = store.get("current_icon_object") if store_obj: print('Returning Stored Object from User Values') print(store_obj) return store_obj # if we can't find a stored version try and find it if not store_obj: general.select_object("icon_object_shot") obj = io.get_obj_by_brush_and_mtl( lodtools.getselected().lower(), general.get_assigned_material("icon_object_shot"), ) if obj: return obj # object was not set in store and is not set in io_db return None
def load_batch(_store): try: io = IconObjectDB() except ValueError as val_err: general.message_box_ok(str(val_err)) return False xml_path = store.get("todo")[0] name = get_item_name_from_xml(xml_path) if xml_path is not None: icon_object = io.get_obj_by_name(name) if icon_object: add_to_scene(icon_object) else: print('Inserting ' + name + 'to icon database') add_to_scene( get_default_object( get_item_geometry_from_xml(xml_path), mtl=get_item_material_from_xml(xml_path), name=name ) ) save(name) add_item_to_processed_list(xml_path, store)
def save(name=False, overwrite=False, embellishment=None): """ Save an Icon Setup :return: string name of the entity class name """ # name of icon_object in icon_level.cry ico_obj = "icon_object_shot" store = UserValues() # the obj to insert obj = dict() # instantiate our iodb try: io = IconObjectDB() except ValueError as val_err: general.message_box_ok(str(val_err)) return None # clear the selection general.clear_selection() # get the info from the icon_object_shot obj["pos"] = general.get_position(ico_obj) obj["scale"] = general.get_scale(ico_obj) obj["rot"] = general.get_rotation(ico_obj) obj["mtl"] = general.get_assigned_material(ico_obj) obj["tod"] = general.get_cvar("e_timeOfDay") # get the brush by selecting the ico_obj general.select_object(ico_obj) obj["brush"] = lodtools.getselected().lower() general.clear_selection() stored = io.get_obj_by_brush_and_mtl(obj["brush"], obj["mtl"]) if embellishment: print("Saving Embellishments") obj["embellishment_48"] = embellishment["embellishment_48"] obj["embellishment_200"] = embellishment["embellishment_200"] obj["embellishment_2048"] = embellishment["embellishment_2048"] if "embellishment_under" in embellishment.keys(): obj["embellishment_under"] = True else: icon_obj = store.get("current_icon_object") if icon_obj: keys = icon_obj.keys() if "embellishment_under" in keys: obj["embellishment_under"] = True if "embellishment_48" in keys: obj["embellishment_48"] = icon_obj["embellishment_48"] if "embellishment_200" in keys: obj["embellishment_200"] = icon_obj["embellishment_200"] if "embellishment_2048" in keys: obj["embellishment_2048"] = icon_obj["embellishment_2048"] if name: obj["name"] = name elif stored: obj["name"] = stored["name"] if not general.message_box_yes_no(str("Save " + stored["name"] + "?")): obj["name"] = general.edit_box("Entity ClassName") else: overwrite = True else: obj["name"] = general.edit_box("Entity ClassName") if io.insert_object(obj) is False: if overwrite: io.insert_object(obj, override=True) else: if general.message_box_yes_no("Overwrite?"): io.insert_object(obj, override=True) print("Storing Item into UserValues") store.set("current_icon_object", obj) return obj["name"]
def load_by_xml(): try: io = IconObjectDB() except ValueError as val_err: general.message_box_ok(str(val_err)) return False xml_filepath = general.open_file_box() if not xml_filepath: return False entity_name = get_item_name_from_xml(xml_filepath) obj = io.get_obj_by_name(entity_name) if is_vehicle_skin(xml_filepath): vehicle_skin_name = get_skin_name(xml_filepath) base_item_name = get_vehicle_name_from_skin(xml_filepath) io_obj = ( io.get_obj_by_name(vehicle_skin_name) if io.get_obj_by_name(vehicle_skin_name) is not None else io.get_obj_by_name(base_item_name) ) tod = "12" if "tod" in io_obj: tod = io_obj["tod"] add_to_scene( get_default_object( io_obj["brush"], mtl=get_item_material_from_skin_xml(xml_filepath), name=vehicle_skin_name, pos=io_obj["pos"], rot=io_obj["rot"], scale=io_obj["scale"], tod=tod, ) ) return True # check if it's a skin file if it is grab the base item xml file and use that. if is_skin(xml_filepath): base_item_xml_path = get_base_item_xml_path(xml_filepath) base_item_name = get_item_name_from_xml(base_item_xml_path) io_obj = io.get_obj_by_name(base_item_name) tod = "12" if "tod" in io_obj: tod = io_obj["tod"] add_to_scene( get_default_object( io_obj["brush"], mtl=get_item_material_from_skin_xml(xml_filepath), name=entity_name, pos=io_obj["pos"], rot=io_obj["rot"], scale=io_obj["scale"], tod=tod, ) ) return True # if the object already exists grab it and add it to the scene if obj is not None: add_to_scene(obj) return True # add the object to the scene add_to_scene( get_default_object( get_item_geometry_from_xml(xml_filepath), mtl=get_item_material_from_xml(xml_filepath), name=entity_name, ) ) save(entity_name) return True