2022-02-11 09:07:11 +11:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2011-03-30 10:29:32 +00:00
|
|
|
|
|
|
|
from mathutils import Vector
|
|
|
|
import bpy
|
2011-08-12 06:57:00 +00:00
|
|
|
from bpy.types import Operator
|
2015-01-27 17:46:07 +11:00
|
|
|
from bpy.props import (
|
2017-03-25 11:07:05 +11:00
|
|
|
BoolProperty,
|
|
|
|
EnumProperty,
|
|
|
|
FloatProperty,
|
2017-11-29 18:00:41 +11:00
|
|
|
IntProperty,
|
2017-03-25 11:07:05 +11:00
|
|
|
)
|
2022-11-16 12:06:14 +01:00
|
|
|
from bpy.app.translations import pgettext_tip as tip_
|
2011-03-30 10:29:32 +00:00
|
|
|
|
2011-06-15 00:16:30 +00:00
|
|
|
|
|
|
|
def object_ensure_material(obj, mat_name):
|
|
|
|
""" Use an existing material or add a new one.
|
|
|
|
"""
|
|
|
|
mat = mat_slot = None
|
|
|
|
for mat_slot in obj.material_slots:
|
|
|
|
mat = mat_slot.material
|
|
|
|
if mat:
|
|
|
|
break
|
|
|
|
if mat is None:
|
|
|
|
mat = bpy.data.materials.new(mat_name)
|
|
|
|
if mat_slot:
|
|
|
|
mat_slot.material = mat
|
|
|
|
else:
|
|
|
|
obj.data.materials.append(mat)
|
|
|
|
return mat
|
|
|
|
|
2019-04-09 23:16:11 +10:00
|
|
|
|
2019-03-19 17:16:49 +01:00
|
|
|
class ObjectModeOperator:
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
return context.mode == 'OBJECT'
|
2011-06-15 00:16:30 +00:00
|
|
|
|
2019-04-09 23:16:11 +10:00
|
|
|
|
2019-03-19 17:16:49 +01:00
|
|
|
class QuickFur(ObjectModeOperator, Operator):
|
2023-02-15 12:13:34 +01:00
|
|
|
"""Add a fur setup to the selected objects"""
|
2011-06-12 11:14:28 +00:00
|
|
|
bl_idname = "object.quick_fur"
|
|
|
|
bl_label = "Quick Fur"
|
2011-03-30 10:29:32 +00:00
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
density: EnumProperty(
|
2023-02-15 12:13:34 +01:00
|
|
|
name="Density",
|
2018-06-26 19:41:37 +02:00
|
|
|
items=(
|
2023-02-15 12:13:34 +01:00
|
|
|
('LOW', "Low", ""),
|
2018-06-26 19:41:37 +02:00
|
|
|
('MEDIUM', "Medium", ""),
|
2023-02-15 12:13:34 +01:00
|
|
|
('HIGH', "High", ""),
|
2018-06-26 19:41:37 +02:00
|
|
|
),
|
|
|
|
default='MEDIUM',
|
|
|
|
)
|
2018-07-11 22:18:09 +02:00
|
|
|
length: FloatProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Length",
|
|
|
|
min=0.001, max=100,
|
|
|
|
soft_min=0.01, soft_max=10,
|
|
|
|
default=0.1,
|
2023-02-15 12:13:34 +01:00
|
|
|
subtype='DISTANCE'
|
|
|
|
)
|
|
|
|
radius: FloatProperty(
|
|
|
|
name="Hair Radius",
|
|
|
|
min=0.0, max=10,
|
|
|
|
soft_min=0.0001, soft_max=0.1,
|
|
|
|
default=0.001,
|
|
|
|
subtype='DISTANCE'
|
|
|
|
)
|
|
|
|
view_percentage: FloatProperty(
|
|
|
|
name="View Percentage",
|
|
|
|
min=0.0, max=1.0,
|
|
|
|
default=1.0,
|
|
|
|
subtype='FACTOR'
|
|
|
|
)
|
|
|
|
apply_hair_guides: BoolProperty(
|
|
|
|
name="Apply Hair Guides",
|
|
|
|
default=True,
|
|
|
|
)
|
|
|
|
use_noise: BoolProperty(
|
|
|
|
name="Noise",
|
|
|
|
default=True,
|
|
|
|
)
|
|
|
|
use_frizz: BoolProperty(
|
|
|
|
name="Frizz",
|
|
|
|
default=True,
|
2018-06-26 19:41:37 +02:00
|
|
|
)
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
def execute(self, context):
|
2023-02-15 12:13:34 +01:00
|
|
|
import os
|
|
|
|
mesh_objects = [obj for obj in context.selected_objects if obj.type == 'MESH']
|
2011-03-31 11:49:01 +00:00
|
|
|
if not mesh_objects:
|
2011-09-19 14:00:42 +00:00
|
|
|
self.report({'ERROR'}, "Select at least one mesh object")
|
2011-03-31 11:49:01 +00:00
|
|
|
return {'CANCELLED'}
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2023-02-15 12:13:34 +01:00
|
|
|
if self.density == 'LOW':
|
|
|
|
count = 1000
|
|
|
|
elif self.density == 'MEDIUM':
|
|
|
|
count = 10000
|
|
|
|
elif self.density == 'HIGH':
|
|
|
|
count = 100000
|
|
|
|
|
|
|
|
node_groups_to_append = {"Generate Hair Curves", "Set Hair Curve Profile", "Interpolate Hair Curves"}
|
|
|
|
if self.use_noise:
|
|
|
|
node_groups_to_append.add("Hair Curves Noise")
|
|
|
|
if self.use_frizz:
|
|
|
|
node_groups_to_append.add("Frizz Hair Curves")
|
|
|
|
assets_directory = os.path.join(bpy.utils.system_resource('DATAFILES'),
|
|
|
|
"assets",
|
|
|
|
"geometry_nodes",
|
|
|
|
"procedural_hair_node_assets.blend",
|
|
|
|
"NodeTree")
|
|
|
|
for name in node_groups_to_append:
|
|
|
|
bpy.ops.wm.append(directory=assets_directory,
|
|
|
|
filename=name,
|
|
|
|
use_recursive=True,
|
2023-02-16 11:17:21 -05:00
|
|
|
clear_asset_data=True,
|
2023-02-15 12:13:34 +01:00
|
|
|
do_reuse_local_id=True)
|
|
|
|
generate_group = bpy.data.node_groups["Generate Hair Curves"]
|
|
|
|
interpolate_group = bpy.data.node_groups["Interpolate Hair Curves"]
|
|
|
|
radius_group = bpy.data.node_groups["Set Hair Curve Profile"]
|
|
|
|
noise_group = bpy.data.node_groups["Hair Curves Noise"] if self.use_noise else None
|
|
|
|
frizz_group = bpy.data.node_groups["Frizz Hair Curves"] if self.use_frizz else None
|
|
|
|
|
|
|
|
material = bpy.data.materials.new("Fur Material")
|
|
|
|
|
|
|
|
for mesh_object in mesh_objects:
|
|
|
|
mesh = mesh_object.data
|
|
|
|
with context.temp_override(active_object=mesh_object):
|
|
|
|
bpy.ops.object.curves_empty_hair_add()
|
|
|
|
curves_object = context.active_object
|
|
|
|
curves = curves_object.data
|
|
|
|
curves.materials.append(material)
|
|
|
|
|
|
|
|
area = 0.0
|
|
|
|
for poly in mesh.polygons:
|
|
|
|
area += poly.area
|
|
|
|
density = count / area
|
|
|
|
|
|
|
|
generate_modifier = curves_object.modifiers.new(name="Generate", type='NODES')
|
|
|
|
generate_modifier.node_group = generate_group
|
|
|
|
generate_modifier["Input_2"] = mesh_object
|
|
|
|
generate_modifier["Input_18_attribute_name"] = curves.surface_uv_map
|
2023-03-15 12:07:53 -04:00
|
|
|
generate_modifier["Input_12"] = True
|
2023-02-15 12:13:34 +01:00
|
|
|
generate_modifier["Input_20"] = self.length
|
|
|
|
generate_modifier["Input_22"] = material
|
|
|
|
generate_modifier["Input_15"] = density * 0.01
|
|
|
|
|
|
|
|
radius_modifier = curves_object.modifiers.new(name="Set Hair Curve Profile", type='NODES')
|
|
|
|
radius_modifier.node_group = radius_group
|
|
|
|
radius_modifier["Input_3"] = self.radius
|
|
|
|
|
|
|
|
interpolate_modifier = curves_object.modifiers.new(name="Interpolate Hair Curves", type='NODES')
|
|
|
|
interpolate_modifier.node_group = interpolate_group
|
|
|
|
interpolate_modifier["Input_2"] = mesh_object
|
|
|
|
interpolate_modifier["Input_18_attribute_name"] = curves.surface_uv_map
|
2023-03-15 12:07:53 -04:00
|
|
|
interpolate_modifier["Input_12"] = True
|
2023-02-15 12:13:34 +01:00
|
|
|
interpolate_modifier["Input_15"] = density
|
|
|
|
interpolate_modifier["Input_17"] = self.view_percentage
|
|
|
|
interpolate_modifier["Input_24"] = True
|
|
|
|
|
|
|
|
if noise_group:
|
|
|
|
noise_modifier = curves_object.modifiers.new(name="Hair Curves Noise", type='NODES')
|
|
|
|
noise_modifier.node_group = noise_group
|
|
|
|
|
|
|
|
if frizz_group:
|
|
|
|
frizz_modifier = curves_object.modifiers.new(name="Frizz Hair Curves", type='NODES')
|
|
|
|
frizz_modifier.node_group = frizz_group
|
|
|
|
|
|
|
|
if self.apply_hair_guides:
|
|
|
|
with context.temp_override(object=curves_object):
|
|
|
|
bpy.ops.object.modifier_apply(modifier=generate_modifier.name)
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2023-03-15 12:07:53 -04:00
|
|
|
curves_object.modifiers.move(0, len(curves_object.modifiers) - 1)
|
|
|
|
|
2023-03-27 20:51:35 +02:00
|
|
|
# Workaround for #105965: Rebuild UI data of modifier input properties.
|
|
|
|
for modifier in curves_object.modifiers:
|
|
|
|
modifier.node_group = modifier.node_group
|
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
return {'FINISHED'}
|
|
|
|
|
2011-06-15 00:16:30 +00:00
|
|
|
|
2019-03-19 17:16:49 +01:00
|
|
|
class QuickExplode(ObjectModeOperator, Operator):
|
2019-05-05 21:36:12 +02:00
|
|
|
"""Make selected objects explode"""
|
2011-06-12 11:14:28 +00:00
|
|
|
bl_idname = "object.quick_explode"
|
|
|
|
bl_label = "Quick Explode"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
style: EnumProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Explode Style",
|
|
|
|
items=(
|
|
|
|
('EXPLODE', "Explode", ""),
|
|
|
|
('BLEND', "Blend", ""),
|
|
|
|
),
|
|
|
|
default='EXPLODE',
|
|
|
|
)
|
2018-07-11 22:18:09 +02:00
|
|
|
amount: IntProperty(
|
2020-12-13 13:12:56 -08:00
|
|
|
name="Number of Pieces",
|
2018-06-26 19:41:37 +02:00
|
|
|
min=2, max=10000,
|
|
|
|
soft_min=2, soft_max=10000,
|
|
|
|
default=100,
|
|
|
|
)
|
2018-07-11 22:18:09 +02:00
|
|
|
frame_duration: IntProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Duration",
|
|
|
|
min=1, max=300000,
|
|
|
|
soft_min=1, soft_max=10000,
|
|
|
|
default=50,
|
|
|
|
)
|
2011-06-12 11:14:28 +00:00
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
frame_start: IntProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Start Frame",
|
|
|
|
min=1, max=300000,
|
|
|
|
soft_min=1, soft_max=10000,
|
|
|
|
default=1,
|
|
|
|
)
|
2018-07-11 22:18:09 +02:00
|
|
|
frame_end: IntProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="End Frame",
|
|
|
|
min=1, max=300000,
|
|
|
|
soft_min=1, soft_max=10000,
|
|
|
|
default=10,
|
|
|
|
)
|
2011-06-12 11:14:28 +00:00
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
velocity: FloatProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Outwards Velocity",
|
|
|
|
min=0, max=300000,
|
|
|
|
soft_min=0, soft_max=10,
|
|
|
|
default=1,
|
|
|
|
)
|
2011-06-12 11:14:28 +00:00
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
fade: BoolProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Fade",
|
|
|
|
description="Fade the pieces over time",
|
|
|
|
default=True,
|
|
|
|
)
|
2011-06-12 11:14:28 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
2013-01-23 07:52:31 +00:00
|
|
|
fake_context = context.copy()
|
2011-06-15 00:16:30 +00:00
|
|
|
obj_act = context.active_object
|
|
|
|
|
2011-07-01 13:26:20 +00:00
|
|
|
if obj_act is None or obj_act.type != 'MESH':
|
2011-06-15 00:16:30 +00:00
|
|
|
self.report({'ERROR'}, "Active object is not a mesh")
|
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
|
|
mesh_objects = [obj for obj in context.selected_objects
|
|
|
|
if obj.type == 'MESH' and obj != obj_act]
|
|
|
|
mesh_objects.insert(0, obj_act)
|
2011-06-12 11:14:28 +00:00
|
|
|
|
|
|
|
if self.style == 'BLEND' and len(mesh_objects) != 2:
|
2011-06-15 00:16:30 +00:00
|
|
|
self.report({'ERROR'}, "Select two mesh objects")
|
2012-06-19 16:45:48 +00:00
|
|
|
self.style = 'EXPLODE'
|
2011-06-12 11:14:28 +00:00
|
|
|
return {'CANCELLED'}
|
|
|
|
elif not mesh_objects:
|
2011-06-15 00:16:30 +00:00
|
|
|
self.report({'ERROR'}, "Select at least one mesh object")
|
2011-06-12 11:14:28 +00:00
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
|
|
for obj in mesh_objects:
|
2011-06-15 00:16:30 +00:00
|
|
|
if obj.particle_systems:
|
2011-07-25 05:54:32 +00:00
|
|
|
self.report({'ERROR'},
|
2022-11-16 12:06:14 +01:00
|
|
|
tip_("Object %r already has a "
|
|
|
|
"particle system") % obj.name)
|
2011-07-25 05:54:32 +00:00
|
|
|
|
2011-06-12 11:14:28 +00:00
|
|
|
return {'CANCELLED'}
|
|
|
|
|
|
|
|
if self.style == 'BLEND':
|
2011-06-15 00:16:30 +00:00
|
|
|
from_obj = mesh_objects[1]
|
|
|
|
to_obj = mesh_objects[0]
|
2011-06-12 11:14:28 +00:00
|
|
|
|
|
|
|
for obj in mesh_objects:
|
|
|
|
fake_context["object"] = obj
|
|
|
|
bpy.ops.object.particle_system_add(fake_context)
|
|
|
|
|
|
|
|
settings = obj.particle_systems[-1].settings
|
|
|
|
settings.count = self.amount
|
2017-01-04 10:13:28 +01:00
|
|
|
# first set frame end, to prevent frame start clamping
|
2011-06-15 00:16:30 +00:00
|
|
|
settings.frame_end = self.frame_end - self.frame_duration
|
2017-01-04 10:13:28 +01:00
|
|
|
settings.frame_start = self.frame_start
|
2011-06-15 00:16:30 +00:00
|
|
|
settings.lifetime = self.frame_duration
|
2011-06-12 11:14:28 +00:00
|
|
|
settings.normal_factor = self.velocity
|
|
|
|
settings.render_type = 'NONE'
|
|
|
|
|
2011-06-15 00:16:30 +00:00
|
|
|
explode = obj.modifiers.new(name='Explode', type='EXPLODE')
|
2011-06-12 11:14:28 +00:00
|
|
|
explode.use_edge_cut = True
|
|
|
|
|
|
|
|
if self.fade:
|
|
|
|
explode.show_dead = False
|
2019-01-07 13:04:39 +01:00
|
|
|
uv = obj.data.uv_layers.new(name="Explode fade")
|
2011-06-12 11:14:28 +00:00
|
|
|
explode.particle_uv = uv.name
|
|
|
|
|
2011-06-15 00:16:30 +00:00
|
|
|
mat = object_ensure_material(obj, "Explode Fade")
|
2019-01-07 15:42:46 +01:00
|
|
|
mat.blend_method = 'BLEND'
|
2019-04-07 12:43:20 +02:00
|
|
|
mat.shadow_method = 'HASHED'
|
2019-01-07 15:42:46 +01:00
|
|
|
if not mat.use_nodes:
|
|
|
|
mat.use_nodes = True
|
|
|
|
|
|
|
|
nodes = mat.node_tree.nodes
|
|
|
|
for node in nodes:
|
2019-07-07 22:24:11 +10:00
|
|
|
if node.type == 'OUTPUT_MATERIAL':
|
2019-01-07 15:42:46 +01:00
|
|
|
node_out_mat = node
|
|
|
|
break
|
|
|
|
|
|
|
|
node_surface = node_out_mat.inputs['Surface'].links[0].from_node
|
|
|
|
|
|
|
|
node_x = node_surface.location[0]
|
|
|
|
node_y = node_surface.location[1] - 400
|
|
|
|
offset_x = 200
|
|
|
|
|
|
|
|
node_mix = nodes.new('ShaderNodeMixShader')
|
|
|
|
node_mix.location = (node_x - offset_x, node_y)
|
2019-06-03 09:49:58 +02:00
|
|
|
mat.node_tree.links.new(node_surface.outputs[0], node_mix.inputs[1])
|
2019-01-07 15:42:46 +01:00
|
|
|
mat.node_tree.links.new(node_mix.outputs["Shader"], node_out_mat.inputs['Surface'])
|
|
|
|
offset_x += 200
|
|
|
|
|
|
|
|
node_trans = nodes.new('ShaderNodeBsdfTransparent')
|
|
|
|
node_trans.location = (node_x - offset_x, node_y)
|
|
|
|
mat.node_tree.links.new(node_trans.outputs["BSDF"], node_mix.inputs[2])
|
|
|
|
offset_x += 200
|
|
|
|
|
|
|
|
node_ramp = nodes.new('ShaderNodeValToRGB')
|
|
|
|
node_ramp.location = (node_x - offset_x, node_y)
|
|
|
|
offset_x += 200
|
|
|
|
mat.node_tree.links.new(node_ramp.outputs["Alpha"], node_mix.inputs["Fac"])
|
|
|
|
color_ramp = node_ramp.color_ramp
|
|
|
|
color_ramp.elements[0].color[3] = 0.0
|
|
|
|
color_ramp.elements[1].color[3] = 1.0
|
2011-06-12 11:14:28 +00:00
|
|
|
|
|
|
|
if self.style == 'BLEND':
|
2019-01-07 15:42:46 +01:00
|
|
|
color_ramp.elements[0].position = 0.333
|
|
|
|
color_ramp.elements[1].position = 0.666
|
2011-06-12 11:14:28 +00:00
|
|
|
if obj == to_obj:
|
2019-01-07 15:42:46 +01:00
|
|
|
# reverse ramp alpha
|
|
|
|
color_ramp.elements[0].color[3] = 1.0
|
|
|
|
color_ramp.elements[1].color[3] = 0.0
|
|
|
|
|
|
|
|
node_sep = nodes.new('ShaderNodeSeparateXYZ')
|
|
|
|
node_sep.location = (node_x - offset_x, node_y)
|
|
|
|
offset_x += 200
|
|
|
|
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"])
|
2011-06-12 11:14:28 +00:00
|
|
|
|
|
|
|
if self.style == 'BLEND':
|
|
|
|
settings.physics_type = 'KEYED'
|
|
|
|
settings.use_emit_random = False
|
|
|
|
settings.rotation_mode = 'NOR'
|
|
|
|
|
|
|
|
psys = obj.particle_systems[-1]
|
|
|
|
|
|
|
|
fake_context["particle_system"] = obj.particle_systems[-1]
|
|
|
|
bpy.ops.particle.new_target(fake_context)
|
|
|
|
bpy.ops.particle.new_target(fake_context)
|
|
|
|
|
|
|
|
if obj == from_obj:
|
|
|
|
psys.targets[1].object = to_obj
|
|
|
|
else:
|
|
|
|
psys.targets[0].object = from_obj
|
|
|
|
settings.normal_factor = -self.velocity
|
|
|
|
explode.show_unborn = False
|
|
|
|
explode.show_dead = True
|
|
|
|
else:
|
|
|
|
settings.factor_random = self.velocity
|
2011-06-15 00:16:30 +00:00
|
|
|
settings.angular_velocity_factor = self.velocity / 10.0
|
2011-06-12 11:14:28 +00:00
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
|
2019-05-09 09:15:01 +10:00
|
|
|
def invoke(self, context, _event):
|
2011-06-15 00:16:30 +00:00
|
|
|
self.frame_start = context.scene.frame_current
|
|
|
|
self.frame_end = self.frame_start + self.frame_duration
|
|
|
|
return self.execute(context)
|
2011-04-01 02:41:15 +00:00
|
|
|
|
2011-06-21 17:17:51 +00:00
|
|
|
|
2011-03-31 11:49:01 +00:00
|
|
|
def obj_bb_minmax(obj, min_co, max_co):
|
|
|
|
for i in range(0, 8):
|
2018-09-19 10:32:58 +02:00
|
|
|
bb_vec = obj.matrix_world @ Vector(obj.bound_box[i])
|
2011-03-31 11:49:01 +00:00
|
|
|
|
|
|
|
min_co[0] = min(bb_vec[0], min_co[0])
|
|
|
|
min_co[1] = min(bb_vec[1], min_co[1])
|
|
|
|
min_co[2] = min(bb_vec[2], min_co[2])
|
|
|
|
max_co[0] = max(bb_vec[0], max_co[0])
|
|
|
|
max_co[1] = max(bb_vec[1], max_co[1])
|
|
|
|
max_co[2] = max(bb_vec[2], max_co[2])
|
2014-09-17 18:36:17 +10:00
|
|
|
|
|
|
|
|
2014-09-07 05:15:26 +02:00
|
|
|
def grid_location(x, y):
|
|
|
|
return (x * 200, y * 150)
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-04-01 02:41:15 +00:00
|
|
|
|
2019-03-19 17:16:49 +01:00
|
|
|
class QuickSmoke(ObjectModeOperator, Operator):
|
2019-05-05 21:36:12 +02:00
|
|
|
"""Use selected objects as smoke emitters"""
|
2011-06-12 11:14:28 +00:00
|
|
|
bl_idname = "object.quick_smoke"
|
|
|
|
bl_label = "Quick Smoke"
|
2011-03-30 10:29:32 +00:00
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
style: EnumProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Smoke Style",
|
|
|
|
items=(
|
|
|
|
('SMOKE', "Smoke", ""),
|
|
|
|
('FIRE', "Fire", ""),
|
2020-12-10 18:22:16 -08:00
|
|
|
('BOTH', "Smoke & Fire", ""),
|
2018-06-26 19:41:37 +02:00
|
|
|
),
|
|
|
|
default='SMOKE',
|
|
|
|
)
|
2011-07-25 05:54:32 +00:00
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
show_flows: BoolProperty(
|
2018-06-26 19:41:37 +02:00
|
|
|
name="Render Smoke Objects",
|
|
|
|
description="Keep the smoke objects visible during rendering",
|
|
|
|
default=False,
|
|
|
|
)
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
def execute(self, context):
|
2019-12-16 15:42:07 +01:00
|
|
|
if not bpy.app.build_options.fluid:
|
|
|
|
self.report({'ERROR'}, "Built without Fluid modifier")
|
2016-12-05 23:33:21 +01:00
|
|
|
return {'CANCELLED'}
|
|
|
|
|
2013-01-23 07:52:31 +00:00
|
|
|
fake_context = context.copy()
|
2011-07-25 05:54:32 +00:00
|
|
|
mesh_objects = [obj for obj in context.selected_objects
|
|
|
|
if obj.type == 'MESH']
|
2011-06-15 00:16:30 +00:00
|
|
|
min_co = Vector((100000.0, 100000.0, 100000.0))
|
|
|
|
max_co = -min_co
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-31 11:49:01 +00:00
|
|
|
if not mesh_objects:
|
2011-09-19 14:00:42 +00:00
|
|
|
self.report({'ERROR'}, "Select at least one mesh object")
|
2011-03-31 11:49:01 +00:00
|
|
|
return {'CANCELLED'}
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-31 11:49:01 +00:00
|
|
|
for obj in mesh_objects:
|
2011-04-20 17:51:56 +00:00
|
|
|
fake_context["object"] = obj
|
2011-03-30 10:29:32 +00:00
|
|
|
# make each selected object a smoke flow
|
2019-12-16 15:42:07 +01:00
|
|
|
bpy.ops.object.modifier_add(fake_context, type='FLUID')
|
|
|
|
obj.modifiers[-1].fluid_type = 'FLOW'
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2014-09-07 17:01:24 +02:00
|
|
|
# set type
|
2019-12-16 15:42:07 +01:00
|
|
|
obj.modifiers[-1].flow_settings.flow_type = self.style
|
|
|
|
|
|
|
|
# set flow behavior
|
|
|
|
obj.modifiers[-1].flow_settings.flow_behavior = 'INFLOW'
|
|
|
|
|
|
|
|
# use some surface distance for smoke emission
|
|
|
|
obj.modifiers[-1].flow_settings.surface_distance = 1.5
|
2012-10-10 13:18:07 +00:00
|
|
|
|
2011-03-30 13:35:54 +00:00
|
|
|
if not self.show_flows:
|
2018-09-03 18:58:41 +02:00
|
|
|
obj.display_type = 'WIRE'
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
# store bounding box min/max for the domain object
|
2011-03-31 11:49:01 +00:00
|
|
|
obj_bb_minmax(obj, min_co, max_co)
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
# add the smoke domain object
|
|
|
|
bpy.ops.mesh.primitive_cube_add()
|
2011-03-31 11:49:01 +00:00
|
|
|
obj = context.active_object
|
|
|
|
obj.name = "Smoke Domain"
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
# give the smoke some room above the flows
|
2011-04-01 02:41:15 +00:00
|
|
|
obj.location = 0.5 * (max_co + min_co) + Vector((0.0, 0.0, 1.0))
|
|
|
|
obj.scale = 0.5 * (max_co - min_co) + Vector((1.0, 1.0, 2.0))
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
# setup smoke domain
|
2019-12-16 15:42:07 +01:00
|
|
|
bpy.ops.object.modifier_add(type='FLUID')
|
|
|
|
obj.modifiers[-1].fluid_type = 'DOMAIN'
|
2014-09-07 17:01:24 +02:00
|
|
|
if self.style == 'FIRE' or self.style == 'BOTH':
|
2019-12-16 15:42:07 +01:00
|
|
|
obj.modifiers[-1].domain_settings.use_noise = True
|
|
|
|
|
2020-06-24 18:38:56 +02:00
|
|
|
# ensure correct cache file format for smoke
|
2020-08-19 14:29:06 +02:00
|
|
|
if bpy.app.build_options.openvdb:
|
|
|
|
obj.modifiers[-1].domain_settings.cache_data_format = 'OPENVDB'
|
2020-06-24 18:38:56 +02:00
|
|
|
|
2014-09-07 05:15:26 +02:00
|
|
|
# Setup material
|
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
# Cycles and Eevee
|
|
|
|
bpy.ops.object.material_slot_add()
|
2014-09-07 05:15:26 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
mat = bpy.data.materials.new("Smoke Domain Material")
|
|
|
|
obj.material_slots[0].material = mat
|
2014-09-07 05:15:26 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
# Make sure we use nodes
|
|
|
|
mat.use_nodes = True
|
2014-09-07 05:15:26 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
# Set node variables and clear the default nodes
|
|
|
|
tree = mat.node_tree
|
|
|
|
nodes = tree.nodes
|
|
|
|
links = tree.links
|
2014-09-07 05:15:26 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
nodes.clear()
|
2014-09-25 12:44:06 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
# Create shader nodes
|
2014-09-07 05:15:26 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
# Material output
|
|
|
|
node_out = nodes.new(type='ShaderNodeOutputMaterial')
|
|
|
|
node_out.location = grid_location(6, 1)
|
2014-09-07 05:15:26 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
# Add Principled Volume
|
|
|
|
node_principled = nodes.new(type='ShaderNodeVolumePrincipled')
|
|
|
|
node_principled.location = grid_location(4, 1)
|
|
|
|
links.new(node_principled.outputs["Volume"],
|
2018-06-26 22:56:39 +02:00
|
|
|
node_out.inputs["Volume"])
|
2014-09-07 05:15:26 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
node_principled.inputs["Density"].default_value = 5.0
|
2014-09-07 17:01:24 +02:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
if self.style in {'FIRE', 'BOTH'}:
|
|
|
|
node_principled.inputs["Blackbody Intensity"].default_value = 1.0
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
return {'FINISHED'}
|
2011-03-30 15:02:02 +00:00
|
|
|
|
|
|
|
|
2019-12-16 15:42:07 +01:00
|
|
|
class QuickLiquid(Operator):
|
2021-03-20 13:39:59 +01:00
|
|
|
"""Make selected objects liquid"""
|
2019-12-16 15:42:07 +01:00
|
|
|
bl_idname = "object.quick_liquid"
|
|
|
|
bl_label = "Quick Liquid"
|
2011-03-30 10:29:32 +00:00
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2018-07-11 22:18:09 +02:00
|
|
|
show_flows: BoolProperty(
|
2019-12-16 15:42:07 +01:00
|
|
|
name="Render Liquid Objects",
|
|
|
|
description="Keep the liquid objects visible during rendering",
|
|
|
|
default=False,
|
|
|
|
)
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
def execute(self, context):
|
2019-12-16 15:42:07 +01:00
|
|
|
if not bpy.app.build_options.fluid:
|
|
|
|
self.report({'ERROR'}, "Built without Fluid modifier")
|
2016-12-05 23:33:21 +01:00
|
|
|
return {'CANCELLED'}
|
|
|
|
|
2013-01-23 07:52:31 +00:00
|
|
|
fake_context = context.copy()
|
2011-07-25 05:54:32 +00:00
|
|
|
mesh_objects = [obj for obj in context.selected_objects
|
2019-12-16 15:42:07 +01:00
|
|
|
if obj.type == 'MESH']
|
2013-04-20 13:23:53 +00:00
|
|
|
min_co = Vector((100000.0, 100000.0, 100000.0))
|
|
|
|
max_co = -min_co
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-31 11:49:01 +00:00
|
|
|
if not mesh_objects:
|
2011-09-19 14:00:42 +00:00
|
|
|
self.report({'ERROR'}, "Select at least one mesh object")
|
2011-03-31 11:49:01 +00:00
|
|
|
return {'CANCELLED'}
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2020-01-29 12:25:22 +01:00
|
|
|
# set shading type to wireframe so that liquid particles are visible
|
|
|
|
for area in bpy.context.screen.areas:
|
|
|
|
if area.type == 'VIEW_3D':
|
|
|
|
for space in area.spaces:
|
|
|
|
if space.type == 'VIEW_3D':
|
|
|
|
space.shading.type = 'WIREFRAME'
|
|
|
|
|
2011-03-31 11:49:01 +00:00
|
|
|
for obj in mesh_objects:
|
2011-04-20 17:51:56 +00:00
|
|
|
fake_context["object"] = obj
|
2019-12-16 15:42:07 +01:00
|
|
|
# make each selected object a liquid flow
|
|
|
|
bpy.ops.object.modifier_add(fake_context, type='FLUID')
|
|
|
|
obj.modifiers[-1].fluid_type = 'FLOW'
|
|
|
|
|
|
|
|
# set type
|
|
|
|
obj.modifiers[-1].flow_settings.flow_type = 'LIQUID'
|
|
|
|
|
|
|
|
# set flow behavior
|
|
|
|
obj.modifiers[-1].flow_settings.flow_behavior = 'GEOMETRY'
|
|
|
|
|
|
|
|
# use some surface distance for smoke emission
|
|
|
|
obj.modifiers[-1].flow_settings.surface_distance = 0.0
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 13:35:54 +00:00
|
|
|
if not self.show_flows:
|
2018-09-03 18:58:41 +02:00
|
|
|
obj.display_type = 'WIRE'
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
# store bounding box min/max for the domain object
|
2011-03-31 11:49:01 +00:00
|
|
|
obj_bb_minmax(obj, min_co, max_co)
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2019-12-16 15:42:07 +01:00
|
|
|
# add the liquid domain object
|
2021-02-18 13:51:39 -06:00
|
|
|
bpy.ops.mesh.primitive_cube_add(align='WORLD')
|
2011-03-31 11:49:01 +00:00
|
|
|
obj = context.active_object
|
2019-12-16 15:42:07 +01:00
|
|
|
obj.name = "Liquid Domain"
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2019-12-16 15:42:07 +01:00
|
|
|
# give the liquid some room above the flows
|
|
|
|
obj.location = 0.5 * (max_co + min_co) + Vector((0.0, 0.0, -1.0))
|
|
|
|
obj.scale = 0.5 * (max_co - min_co) + Vector((1.0, 1.0, 2.0))
|
|
|
|
|
|
|
|
# setup liquid domain
|
|
|
|
bpy.ops.object.modifier_add(type='FLUID')
|
|
|
|
obj.modifiers[-1].fluid_type = 'DOMAIN'
|
|
|
|
# set all domain borders to obstacle
|
|
|
|
obj.modifiers[-1].domain_settings.use_collision_border_front = True
|
|
|
|
obj.modifiers[-1].domain_settings.use_collision_border_back = True
|
|
|
|
obj.modifiers[-1].domain_settings.use_collision_border_right = True
|
|
|
|
obj.modifiers[-1].domain_settings.use_collision_border_left = True
|
|
|
|
obj.modifiers[-1].domain_settings.use_collision_border_top = True
|
|
|
|
obj.modifiers[-1].domain_settings.use_collision_border_bottom = True
|
|
|
|
|
2020-06-24 18:38:56 +02:00
|
|
|
# ensure correct cache file formats for liquid
|
2020-08-19 14:29:06 +02:00
|
|
|
if bpy.app.build_options.openvdb:
|
|
|
|
obj.modifiers[-1].domain_settings.cache_data_format = 'OPENVDB'
|
2019-12-16 15:42:07 +01:00
|
|
|
obj.modifiers[-1].domain_settings.cache_mesh_format = 'BOBJECT'
|
|
|
|
|
2020-01-15 15:51:33 +01:00
|
|
|
# change domain type, will also allocate and show particle system for FLIP
|
|
|
|
obj.modifiers[-1].domain_settings.domain_type = 'LIQUID'
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2020-09-15 21:21:14 +05:30
|
|
|
liquid_domain = obj.modifiers[-2]
|
|
|
|
|
|
|
|
# set color mapping field to show phi grid for liquid
|
|
|
|
liquid_domain.domain_settings.color_ramp_field = 'PHI'
|
|
|
|
|
2020-10-05 21:47:11 +05:30
|
|
|
# perform a single slice of the domain
|
|
|
|
liquid_domain.domain_settings.use_slice = True
|
2020-09-15 21:21:14 +05:30
|
|
|
|
|
|
|
# set display thickness to a lower value for more detailed display of phi grids
|
|
|
|
liquid_domain.domain_settings.display_thickness = 0.02
|
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
# make the domain smooth so it renders nicely
|
|
|
|
bpy.ops.object.shade_smooth()
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-03-30 10:29:32 +00:00
|
|
|
# create a ray-transparent material for the domain
|
2011-04-20 17:51:56 +00:00
|
|
|
bpy.ops.object.material_slot_add()
|
2011-04-10 10:45:56 +00:00
|
|
|
|
2019-12-16 15:42:07 +01:00
|
|
|
mat = bpy.data.materials.new("Liquid Domain Material")
|
2011-04-04 14:35:22 +00:00
|
|
|
obj.material_slots[0].material = mat
|
2011-03-30 15:02:02 +00:00
|
|
|
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
# 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 Glass
|
|
|
|
node_glass = nodes.new(type='ShaderNodeBsdfGlass')
|
|
|
|
node_glass.location = grid_location(4, 1)
|
|
|
|
links.new(node_glass.outputs["BSDF"], node_out.inputs["Surface"])
|
|
|
|
node_glass.inputs["IOR"].default_value = 1.33
|
|
|
|
|
|
|
|
# Add Absorption
|
|
|
|
node_absorption = nodes.new(type='ShaderNodeVolumeAbsorption')
|
|
|
|
node_absorption.location = grid_location(4, 2)
|
|
|
|
links.new(node_absorption.outputs["Volume"], node_out.inputs["Volume"])
|
|
|
|
node_absorption.inputs["Color"].default_value = (0.8, 0.9, 1.0, 1.0)
|
2011-03-30 15:02:02 +00:00
|
|
|
|
2011-06-15 00:16:30 +00:00
|
|
|
return {'FINISHED'}
|
2017-03-18 20:03:24 +11:00
|
|
|
|
2020-12-16 18:02:40 +11:00
|
|
|
|
2017-03-18 20:03:24 +11:00
|
|
|
classes = (
|
|
|
|
QuickExplode,
|
|
|
|
QuickFur,
|
|
|
|
QuickSmoke,
|
2019-12-16 15:42:07 +01:00
|
|
|
QuickLiquid,
|
2017-03-25 11:07:05 +11:00
|
|
|
)
|