Fix T41419: Quick Smoke doesn´t work with Cycles

Now the Quick Smoke operator creates a basic node setup for smoke and fire. This could be made more fancy still, but that's for later. :)
This commit is contained in:
Thomas Dinges
2014-09-07 05:15:26 +02:00
parent 2e560ebb95
commit 9460fe3fa0

View File

@@ -291,6 +291,10 @@ def obj_bb_minmax(obj, min_co, max_co):
max_co[2] = max(bb_vec[2], max_co[2]) max_co[2] = max(bb_vec[2], max_co[2])
def grid_location(x, y):
return (x * 200, y * 150)
class QuickSmoke(Operator): class QuickSmoke(Operator):
bl_idname = "object.quick_smoke" bl_idname = "object.quick_smoke"
bl_label = "Quick Smoke" bl_label = "Quick Smoke"
@@ -351,6 +355,84 @@ class QuickSmoke(Operator):
if self.style == 'FIRE': if self.style == 'FIRE':
obj.modifiers[-1].domain_settings.use_high_resolution = True obj.modifiers[-1].domain_settings.use_high_resolution = True
# Setup material
# Cycles
if context.scene.render.use_shading_nodes:
bpy.ops.object.material_slot_add()
mat = bpy.data.materials.new("Smoke Domain Material")
obj.material_slots[0].material = mat
# Make sure we use nodes
mat.use_nodes = True
# Set node variables and clear the default nodes
tree = mat.node_tree
nodes = tree.nodes
links = tree.links
nodes.clear()
# Create shader nodes
# Material output
node_out = nodes.new(type='ShaderNodeOutputMaterial')
node_out.location = grid_location(6, 1)
# Add shader 1
node_add_shader_1 = nodes.new(type='ShaderNodeAddShader')
node_add_shader_1.location = grid_location(5, 1)
links.new(node_add_shader_1.outputs["Shader"],
node_out.inputs["Volume"])
# Smoke
# Add shader 2
node_add_shader_2 = nodes.new(type='ShaderNodeAddShader')
node_add_shader_2.location = grid_location(4, 2)
links.new(node_add_shader_2.outputs["Shader"],
node_add_shader_1.inputs[0])
# Volume scatter
node_scatter = nodes.new(type='ShaderNodeVolumeScatter')
node_scatter.location = grid_location(3, 3)
links.new(node_scatter.outputs["Volume"],
node_add_shader_2.inputs[0])
# Volume absorption
node_absorption = nodes.new(type='ShaderNodeVolumeAbsorption')
node_absorption.location = grid_location(3, 2)
links.new(node_absorption.outputs["Volume"],
node_add_shader_2.inputs[1])
# Attribute "density"
node_attrib_density = nodes.new(type='ShaderNodeAttribute')
node_attrib_density.attribute_name = "density"
node_attrib_density.location = grid_location(2, 2)
links.new(node_attrib_density.outputs["Fac"],
node_scatter.inputs["Density"])
links.new(node_attrib_density.outputs["Fac"],
node_absorption.inputs["Density"])
# Fire
# Emission
node_emission = nodes.new(type='ShaderNodeEmission')
node_emission.inputs["Color"].default_value = (0.8, 0.1, 0.01, 1.0)
node_emission.location = grid_location(4, 1)
links.new(node_emission.outputs["Emission"],
node_add_shader_1.inputs[1])
# Attribute "flame"
node_attrib_flame = nodes.new(type='ShaderNodeAttribute')
node_attrib_flame.attribute_name = "flame"
node_attrib_flame.location = grid_location(3, 1)
links.new(node_attrib_flame.outputs["Fac"],
node_emission.inputs["Strength"])
# Blender Internal
else:
# create a volume material with a voxel data texture for the domain # create a volume material with a voxel data texture for the domain
bpy.ops.object.material_slot_add() bpy.ops.object.material_slot_add()