Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/startup/bl_operators/object_quick_effects.py
| Show First 20 Lines • Show All 186 Lines • ▼ Show 20 Lines | def execute(self, context): | ||||
| for obj in mesh_objects: | for obj in mesh_objects: | ||||
| if obj.particle_systems: | if obj.particle_systems: | ||||
| self.report({'ERROR'}, | self.report({'ERROR'}, | ||||
| "Object %r already has a " | "Object %r already has a " | ||||
| "particle system" % obj.name) | "particle system" % obj.name) | ||||
| return {'CANCELLED'} | return {'CANCELLED'} | ||||
| if self.fade: | |||||
| tex = bpy.data.textures.new("Explode fade", 'BLEND') | |||||
| tex.use_color_ramp = True | |||||
| if self.style == 'BLEND': | |||||
| tex.color_ramp.elements[0].position = 0.333 | |||||
| tex.color_ramp.elements[1].position = 0.666 | |||||
| tex.color_ramp.elements[0].color[3] = 1.0 | |||||
| tex.color_ramp.elements[1].color[3] = 0.0 | |||||
| if self.style == 'BLEND': | if self.style == 'BLEND': | ||||
| from_obj = mesh_objects[1] | from_obj = mesh_objects[1] | ||||
| to_obj = mesh_objects[0] | to_obj = mesh_objects[0] | ||||
| for obj in mesh_objects: | for obj in mesh_objects: | ||||
| fake_context["object"] = obj | fake_context["object"] = obj | ||||
| bpy.ops.object.particle_system_add(fake_context) | bpy.ops.object.particle_system_add(fake_context) | ||||
| settings = obj.particle_systems[-1].settings | settings = obj.particle_systems[-1].settings | ||||
| settings.count = self.amount | settings.count = self.amount | ||||
| # first set frame end, to prevent frame start clamping | # first set frame end, to prevent frame start clamping | ||||
| settings.frame_end = self.frame_end - self.frame_duration | settings.frame_end = self.frame_end - self.frame_duration | ||||
| settings.frame_start = self.frame_start | settings.frame_start = self.frame_start | ||||
| settings.lifetime = self.frame_duration | settings.lifetime = self.frame_duration | ||||
| settings.normal_factor = self.velocity | settings.normal_factor = self.velocity | ||||
| settings.render_type = 'NONE' | settings.render_type = 'NONE' | ||||
| explode = obj.modifiers.new(name='Explode', type='EXPLODE') | explode = obj.modifiers.new(name='Explode', type='EXPLODE') | ||||
| explode.use_edge_cut = True | explode.use_edge_cut = True | ||||
| if self.fade: | if self.fade: | ||||
| explode.show_dead = False | explode.show_dead = False | ||||
| uv = obj.data.uv_layers.new("Explode fade") | uv = obj.data.uv_layers.new(name="Explode fade") | ||||
| explode.particle_uv = uv.name | explode.particle_uv = uv.name | ||||
| mat = object_ensure_material(obj, "Explode Fade") | mat = object_ensure_material(obj, "Explode Fade") | ||||
| mat.blend_method = 'BLEND' | |||||
| mat.transparent_shadow_method = 'HASHED' | |||||
| if not mat.use_nodes: | |||||
| mat.use_nodes = True | |||||
| mat.use_transparency = True | nodes = mat.node_tree.nodes | ||||
| mat.use_transparent_shadows = True | for node in nodes: | ||||
| mat.alpha = 0.0 | if (node.type == 'OUTPUT_MATERIAL'): | ||||
| mat.specular_alpha = 0.0 | node_out_mat = node | ||||
| break | |||||
| tex_slot = mat.texture_slots.add() | |||||
| node_surface = node_out_mat.inputs['Surface'].links[0].from_node | |||||
| tex_slot.texture = tex | |||||
| tex_slot.texture_coords = 'UV' | |||||
| tex_slot.uv_layer = uv.name | |||||
| tex_slot.use_map_alpha = True | if node_surface.bl_idname == 'ShaderNodeBsdfPrincipled': | ||||
| node_x = node_surface.location[0] | |||||
| node_y = node_surface.location[1] - 200 | |||||
| offset_x = 400 | |||||
| if node_surface.inputs["Transmission"].is_linked: | |||||
| node_mul = nodes.new('ShaderNodeMath') | |||||
| node_mul.operation = 'MULTIPLY' | |||||
| node_mul.location = (node_x - offset_x, node_y) | |||||
| mat.node_tree.links.new(node_surface.inputs["Transmission"].links[0].from_socket, node_mul.inputs[0]) | |||||
| mat.node_tree.links.new(node_mul.outputs["Value"], node_surface.inputs["Transmission"]) | |||||
| offset_x += 200 | |||||
| node_ramp = nodes.new('ShaderNodeValToRGB') | |||||
| node_ramp.location = (node_x - offset_x, node_y) | |||||
| offset_x += 200 | |||||
| if node_surface.inputs["Transmission"].is_linked: | |||||
| mat.node_tree.links.new(node_ramp.outputs["Alpha"], node_mul.inputs[1]) | |||||
| else: | |||||
| mat.node_tree.links.new(node_ramp.outputs["Alpha"], node_surface.inputs["Transmission"]) | |||||
| color_ramp = node_ramp.color_ramp | |||||
| color_ramp.elements[0].color[3] = 0.0 | |||||
| color_ramp.elements[1].color[3] = 1.0 | |||||
| if self.style == 'BLEND': | if self.style == 'BLEND': | ||||
| color_ramp.elements[0].position = 0.333 | |||||
| color_ramp.elements[1].position = 0.666 | |||||
| if obj == to_obj: | if obj == to_obj: | ||||
| tex_slot.alpha_factor = -1.0 | # reverse ramp alpha | ||||
| elem = tex.color_ramp.elements[1] | color_ramp.elements[0].color[3] = 1.0 | ||||
| else: | color_ramp.elements[1].color[3] = 0.0 | ||||
| elem = tex.color_ramp.elements[0] | |||||
| # Keep already defined alpha! | node_sep = nodes.new('ShaderNodeSeparateXYZ') | ||||
| elem.color[:3] = mat.diffuse_color | node_sep.location = (node_x - offset_x, node_y) | ||||
| else: | offset_x += 200 | ||||
| tex_slot.use_map_color_diffuse = False | mat.node_tree.links.new(node_sep.outputs["X"], node_ramp.inputs["Fac"]) | ||||
| node_uv = nodes.new('ShaderNodeUVMap') | |||||
| node_uv.location = (node_x - offset_x, node_y) | |||||
| node_uv.uv_map = uv.name | |||||
| mat.node_tree.links.new(node_uv.outputs["UV"], node_sep.inputs["Vector"]) | |||||
| if self.style == 'BLEND': | if self.style == 'BLEND': | ||||
| settings.physics_type = 'KEYED' | settings.physics_type = 'KEYED' | ||||
| settings.use_emit_random = False | settings.use_emit_random = False | ||||
| settings.rotation_mode = 'NOR' | settings.rotation_mode = 'NOR' | ||||
| psys = obj.particle_systems[-1] | psys = obj.particle_systems[-1] | ||||
| ▲ Show 20 Lines • Show All 282 Lines • Show Last 20 Lines | |||||