def paste_xforms(): store = UserValues() selected = general.get_names_of_selected_objects()[0] if selected is None: general.message_box_ok("Please Select an object") xforms = store.get("xforms") general.set_position(selected, xforms['pos'][0], xforms['pos'][1], xforms['pos'][2]) general.set_rotation(selected, xforms['rot'][0], xforms['rot'][1], xforms['rot'][2]) general.set_scale(selected, xforms['scale'][0], xforms['scale'][1], xforms['scale'][2])
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
# 2. Create rigid body ex and copy model to rigidbodyex # 3. snap rigid body ex to xform of selected object # 4. and prompt user for weight # 5. hide selected object # 6. simulate rigidbody ex # 7. after simulation is done copy original object to new xform of simulated rigid body # 8. delete rigid body. import better_cry from user_values import UserValues if __name__ == "__main__": PHY_OBJ_NAME = "brush_sim_temp" level = better_cry.Level() store = UserValues() # check if we have a stored brush stored_brush = store.get("simmed_brush") if stored_brush is None: # 1. Get selected object. brush = level.selected[0] # store the users selection for setting the physics state later on store.set("simmed_brush", brush.name) # 2. Create rigid body ex and copy model to rigidbodyex phys_obj = level.new_object("Entity", r"RigidBodyEx", PHY_OBJ_NAME, 0, 0, 0) # mark it with a special material so you know it's being simulated phys_obj.material = "Materials/Special/green_screen.mtl" # set the physobj to be the selected brush object phys_obj.geometry_file = brush.geometry_file # 3. snap physobj to xform of selected object phys_obj.position = (brush.position[0], brush.position[1], brush.position[2]) phys_obj.rotation = (brush.rotation[0], brush.rotation[1], brush.rotation[2])
# 4. and prompt user for weight # 5. hide selected object # 6. simulate rigidbody ex # 7. after simulation is done copy original object to new xform of simulated rigid body # 8. delete rigid body. import general import lodtools import physics from user_values import UserValues PHYS_OBJECT_NAME = "brush_sim_temp" if __name__ == "__main__": store = UserValues() stored_brush = store.get("simmed_brush") # 1. Get selected object. # grab some properties for our selected object user_selection = general.get_names_of_selected_objects()[0] if stored_brush is None: print('Simulating Brush') # store the users selection for setting the physics state later on store.set("simmed_brush", user_selection) # grab the transforms of the object obj_pos = general.get_position(user_selection) obj_rot = general.get_rotation(user_selection) obj_scale = general.get_scale(user_selection) # 2. Create rigid body ex and copy model to rigidbodyex # create the object at 0,0,0
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"]
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) if __name__ == "__main__": store = UserValues() if store.get("todo") is None: store.set("todo", items) store.set("done", []) load_batch(store)