def execute(self, context): props = context.scene.physfxtoolspro_props active_objects = context.selected_objects if len(active_objects) > 0: main_obj = active_objects[0] context.view_layer.objects.active = main_obj if main_obj.type == 'MESH': if main_obj.rigid_body is None: bpy.ops.rigidbody.object_add() if props.rigidbody_is_active: main_obj.rigid_body.mass = props.rigidbody_mass main_obj.rigid_body.collision_shape = props.rigidbody_shape main_obj.rigid_body.mesh_source = props.rigidbody_source main_obj.rigid_body.friction = props.rigidbody_friction main_obj.rigid_body.restitution = props.rigidbody_bounce main_obj.rigid_body.use_margin = True main_obj.rigid_body.collision_margin = props.rigidbody_margin bpy.ops.rigidbody.object_settings_copy() return {'FINISHED'} else: show_message_box("Uh oh!", "Please select a mesh!", "ERROR") return {'CANCELLED'} else: show_message_box("Uh oh!", "No objects selected!", "ERROR") return {'CANCELLED'}
def execute(self, context): active_objects = context.selected_objects if len(active_objects) > 0: bpy.ops.rigidbody.objects_remove() return {'FINISHED'} else: show_message_box("Uh oh!", "No objects selected!", "ERROR") return {'CANCELLED'}
def execute(self, context): active_object = context.active_object if (active_object is not None): bpy.ops.object.modifier_remove(modifier="Softbody") return {'FINISHED'} else: show_message_box("Uh oh!", "No active object selected!", icon="ERROR") return {'CANCELLED'}
def execute(self, context): active_objects = context.selected_objects if len(active_objects) > 0: for obj in active_objects: if obj.type == "MESH": for mod in obj.modifiers: if mod.type == "COLLISION": obj.modifiers.remove(mod) return {'FINISHED'} else: show_message_box("Uh oh!", "No objects selected!", "ERROR") return {'CANCELLED'}
def execute(self, context): home_path = os.path.join(parent_path, 'presets', 'cellfracture') target_path = os.path.join(bpy.utils.user_resource('SCRIPTS'), 'presets', 'operator', 'object.add_fracture_cell_objects') if not os.path.isdir(target_path): show_message_box("Uh oh!", "Couldn't find the cell fracture preset folder.", icon="ERROR") return {'CANCELLED'} else: for file in os.listdir(home_path): shutil.copy2(os.path.join(home_path, file), target_path) return {'FINISHED'}
def execute(self, context): props = context.scene.physfxtoolspro_props active_objects = context.selected_objects if len(active_objects) > 0: for obj in active_objects: if (obj.type == 'MESH'): obj.modifiers.new("Group Collision", 'COLLISION') mod = obj.collision mod.use_particle_kill = props.kill_particles mod.damping_factor = props.particle_damping mod.friction_factor = props.particle_friction mod.damping_random = props.particle_random mod.friction_random = props.particle_random mod.damping = props.cloth_damping mod.thickness_outer = props.cloth_thickness mod.cloth_friction = props.cloth_friction return {'FINISHED'} else: show_message_box("Uh oh!", "No objects selected!", "ERROR") return {'CANCELLED'}
def execute(self, context): active_objects = [] if len(context.selected_objects) > 0: for obj in context.selected_objects: active_objects.append(obj) for obj in active_objects: if (obj.type == "MESH"): resize_scale = obj.dimensions / 2.0 bpy.ops.mesh.primitive_cube_add() proxy_mesh = context.object proxy_mesh.name = obj.name + "_proxy" proxy_mesh.scale = resize_scale proxy_mesh.location = obj.location proxy_mesh.rotation_euler = obj.rotation_euler tmp_mod = proxy_mesh.modifiers.new("Subdivide_tmp", "SUBSURF") tmp_mod.subdivision_type = 'SIMPLE' tmp_mod.levels = 6 tmp_mod = proxy_mesh.modifiers.new('Shrinkwrap_tmp', "SHRINKWRAP") tmp_mod.offset = context.scene.physfxtoolspro_props.proxy_offset tmp_mod.wrap_mode = "ABOVE_SURFACE" tmp_mod.target = obj tmp_mod = proxy_mesh.modifiers.new('Remesh_tmp', "REMESH") tmp_mod.mode = 'SMOOTH' tmp_mod.octree_depth = bpy.context.scene.physfxtoolspro_props.proxy_resolution tmp_mod.use_smooth_shade = True proxy_mesh.parent = obj proxy_mesh.matrix_parent_inverse = obj.matrix_world.inverted() bpy.ops.object.convert(target='MESH', keep_original=False) return {'FINISHED'} else: show_message_box("Uh oh!", "No objects selected!", "ERROR") return {'CANCELLED'}
def execute(self, context): _collection = bpy.context.collection _objects = bpy.context.selected_objects depsgraph = context.evaluated_depsgraph_get() props = context.scene.physfxtoolspro_props try: bpy.ops.rigidbody.world_add() except: pass if (props.glue_collection): if _collection.name == "Scene Collection": show_message_box("Uh oh!", "Cannot glue 'Scene Collection'!", "ERROR") return {'CANCELLED'} else: _objects = _collection.objects gluecollectionname = _collection.name + "_glue" else: gluecollectionname = "_glue" gluecollection = bpy.data.collections.get(gluecollectionname) if gluecollection is None: gluecollection = bpy.data.collections.new(gluecollectionname) if gluecollectionname not in _collection: _collection.children.link(gluecollection) for idx, obj_a in enumerate(_objects): if obj_a.type == "MESH": mesh_a = depsgraph.objects.get(obj_a.name, None) if mesh_a is not None: for __, obj_b in enumerate(_objects[idx + 1:]): if obj_b.type == "MESH": mesh_b = depsgraph.objects.get(obj_b.name, None) if mesh_b is not None: try: is_obj_a_intersection, obj_a_intersection_point = obj_a.ray_cast( obj_a.location - obj_a.location, arrdiff(obj_a.location, obj_b.location))[:2] is_obj_b_intersection, obj_b_intersection_point = obj_b.ray_cast( obj_b.location - obj_b.location, arrdiff(obj_b.location, obj_a.location))[:2] except RuntimeError: show_message_box( 'Uh oh!', 'A Runtime Error occured.', "ERROR") return {'CANCELLED'} obj_a_intersection_point += obj_b.location obj_b_intersection_point += obj_a.location if (is_obj_a_intersection and is_obj_b_intersection): print(obj_a.name, obj_b.name) if ( obj_a_intersection_point - obj_b_intersection_point ).length_squared <= props.glue_distance: name = f"Glue-[{obj_a.name}, {obj_b.name}]" mesh = bpy.data.meshes.new(name) constraint_obj = bpy.data.objects.new( name, mesh) constraint_obj.name = name constraint_obj.color = (1, 1, 1, 1) constraint_obj.display_type = 'WIRE' constraint_obj.show_in_front = True gluecollection.objects.link( constraint_obj) context.view_layer.objects.active = constraint_obj if not constraint_obj.data.is_editmode: bpy.ops.object.mode_set( mode='EDIT') constraint_mesh = bmesh.from_edit_mesh( constraint_obj.data) v1 = constraint_mesh.verts.new( obj_a.location) v2 = constraint_mesh.verts.new( obj_b.location) constraint_mesh.edges.new([v1, v2]) bmesh.update_edit_mesh( constraint_obj.data) constraint_mesh.free() bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.rigidbody.constraint_add() constraint = constraint_obj.rigid_body_constraint constraint.type = 'FIXED' constraint.object1 = obj_a constraint.object2 = obj_b if (props.breaking_threshold == -1): constraint.use_breaking = False else: constraint.use_breaking = True constraint.breaking_threshold = props.breaking_threshold return {'FINISHED'}