def get_lightobj_by_name(name_key: str): """ Given the name_key returned by add_light, find the object for the light """ import blender_scripts.object_manip as object_manip return object_manip.get_bpyobj_by_name(name_key)
def set_as_active(name_key: str): """ Remove all other object and set the given one as the active object :param name_key: The key of the object :return: """ obj = object_manip.get_bpyobj_by_name(name_key) if utils.is_new_api(): bpy.context.view_layer.objects.active = obj else: bpy.context.scene.objects.active = obj
def get_shader_nodetree(name_key: str): """ Given the object name key, return the node tree of the object. The nodetree must be enabled :param name_key: :return: The node tree of this object material """ object = object_manip.get_bpyobj_by_name(name_key) material = object.active_material assert material is not None assert material.use_nodes # Ok return material.node_tree
def enable_shader_nodetree(name_key: str): """ By default the node tree is not enabled, this method enable it and clear all the nodes :param name_key: The key for the object :return: no return """ object = object_manip.get_bpyobj_by_name(name_key) material = object.active_material assert material is not None material.use_nodes = True # Remove current node nodes = get_shader_nodes(name_key) for node in nodes: nodes.remove(node)
def enable_physics_rigidbody(name_key: str, type='ACTIVE', properties=RigidBodyProperties()): """ Given the object, enable physical simulation for that object for either active or passive :param name_key: :param type: 'ACTIVE', 'PASSIVE' :param properties: control the virtual boundary for collision detection :return: """ set_as_active(name_key) bpy.ops.rigidbody.object_add(type=type) # Get the rigid body and setup properties obj = object_manip.get_bpyobj_by_name(name_key) obj.rigid_body.collision_margin = properties.collision_margin obj.rigid_body.linear_damping = properties.linear_damping obj.rigid_body.angular_damping = properties.angular_damping
def remove_from_renderer(obj_name_key: str): obj = get_bpyobj_by_name(obj_name_key) obj.hide_render = True
def add_to_renderer(obj_name_key: str): obj = get_bpyobj_by_name(obj_name_key) obj.hide_render = False