Skip to content

Commit

Permalink
add compatibility code for smoke nodes (fixes #371), add argument to …
Browse files Browse the repository at this point in the history
…specify if pointers should be followd in find_nodes()/has_nodes()
  • Loading branch information
Theverat committed Jan 27, 2020
1 parent 83217ef commit 7490706
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 47 deletions.
2 changes: 1 addition & 1 deletion export/caches/object_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

def uses_pointiness(node_tree):
# Check if a pointiness node exists, better check would be if the node is linked
return utils_node.has_nodes(node_tree, "LuxCoreNodeTexPointiness")
return utils_node.has_nodes(node_tree, "LuxCoreNodeTexPointiness", True)


def get_material(obj, material_index, exporter, depsgraph, is_viewport_render):
Expand Down
2 changes: 1 addition & 1 deletion export/hair.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def convert_colors(obj, psys, settings, vertex_colors, engine, strands_count, st
def warn_about_missing_uvs(obj, node_tree):
# TODO once we have a triplanar option for imagemaps, ignore imagemaps with
# triplanar in this check because they have no problems with missing UVs
has_imagemaps = utils_node.has_nodes(node_tree, "LuxCoreNodeTexImagemap")
has_imagemaps = utils_node.has_nodes(node_tree, "LuxCoreNodeTexImagemap", True)
if has_imagemaps and not utils_node.has_valid_uv_map(obj):
msg = ("Image textures used, but no UVs defined. "
"In case of bumpmaps this can lead to artifacts")
Expand Down
8 changes: 4 additions & 4 deletions handlers/frame_change_pre.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ def handler(scene):
if not mat.luxcore.node_tree:
continue

if (utils_node.has_nodes(mat.luxcore.node_tree, "LuxCoreNodeTexOpenVDB") or
utils_node.has_nodes(mat.luxcore.node_tree, "LuxCoreNodeTexSmoke")):
if (utils_node.has_nodes(mat.luxcore.node_tree, "LuxCoreNodeTexOpenVDB", True) or
utils_node.has_nodes(mat.luxcore.node_tree, "LuxCoreNodeTexSmoke", True)):
found_smoke_sequence = True
for node in mat.luxcore.node_tree.nodes:
if node.bl_idname == "LuxCoreNodeMatOutput" and node.active:
# Force a viewport update
mat.luxcore.node_tree.links.new(node.inputs["Material"], node.inputs["Material"].links[0].from_socket)
break

for node in utils_node.find_nodes(mat.luxcore.node_tree, "LuxCoreNodeTexImagemap") or \
utils_node.find_nodes(mat.luxcore.node_tree, "LuxCoreNodeTexTimeInfo"):
for node in utils_node.find_nodes(mat.luxcore.node_tree, "LuxCoreNodeTexImagemap", True) or \
utils_node.find_nodes(mat.luxcore.node_tree, "LuxCoreNodeTexTimeInfo", True):
found_image_sequence = True
# Force a viewport update
mat.diffuse_color = mat.diffuse_color
Expand Down
20 changes: 9 additions & 11 deletions nodes/textures/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ def poll_domain(self, obj):

domain: PointerProperty(update=utils_node.force_viewport_update, name="Domain", type=bpy.types.Object, poll=poll_domain)

def update_source(self, context):
value_output = self.outputs["Value"]
color_output = self.outputs["Color"]
was_value_enabled = value_output.enabled

value_output.enabled = self.source in {"density", "fire", "heat"}
color_output.enabled = self.source in {"color", "velocity"}

utils_node.copy_links_after_socket_swap(value_output, color_output, was_value_enabled)
utils_node.force_viewport_update(self, context)
# NOTE: The source property is no longer used, just here for backwards compatibility (utils/compatibility.py)
source_items = [
("density", "Density", "Smoke density grid, 1 value per voxel", 0),
("fire", "Fire", "Fire grid, 1 value per voxel", 1),
("heat", "Heat", "Smoke heat grid, 1 value per voxel", 2),
("color", "Color", "Smoke color grid, 3 values per voxel (RGB)", 3),
("velocity", "Velocity", "Smoke velocity grid, 3 values per voxel", 4),
]
source: EnumProperty(name="Grid Type", items=source_items, default="density")

precision_items = [
("byte", "Byte", "Only 1 byte per value. Required memory is 1/2 of Half and 1/4 of Float", 0),
Expand Down Expand Up @@ -59,7 +58,6 @@ def draw_buttons(self, context, layout):
layout.label(text="Select the smoke domain object", icon=icons.WARNING)

col = layout.column()
#col.prop(self, "source")
col.prop(self, "precision")

def sub_export(self, exporter, depsgraph, props, luxcore_name=None, output_socket=None):
Expand Down
65 changes: 42 additions & 23 deletions utils/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def run():
update_output_nodes_volume_change(node_tree)
update_glossy_nodes_ior_change(node_tree)
update_volume_nodes_asymmetry_change(node_tree)
update_smoke_nodes_add_color_output(node_tree)
update_colormix_remove_min_max_sockets(node_tree)
update_imagemap_remove_gamma_brightness_sockets(node_tree)
update_cloth_remove_repeat_sockets(node_tree)
update_imagemap_add_alpha_output(node_tree)
update_smoke_multiple_output_channels(node_tree)

for scene in bpy.data.scenes:
config = scene.luxcore.config
Expand All @@ -34,7 +34,7 @@ def run():
def update_output_nodes_volume_change(node_tree):
# commit 3078719a9a33a7e2a798965294463dce6c8b7749

for old_output in find_nodes(node_tree, "LuxCoreNodeMatOutput"):
for old_output in find_nodes(node_tree, "LuxCoreNodeMatOutput", False):
if "Interior Volume" in old_output.inputs:
continue

Expand Down Expand Up @@ -72,8 +72,8 @@ def update_output_nodes_volume_change(node_tree):
def update_glossy_nodes_ior_change(node_tree):
# commit c3152dec8e0e07e676a60be56ba4578dbe297df6

affected_nodes = find_nodes(node_tree, "LuxCoreNodeMatGlossy2")
affected_nodes += find_nodes(node_tree, "LuxCoreNodeMatGlossyCoating")
affected_nodes = find_nodes(node_tree, "LuxCoreNodeMatGlossy2", False)
affected_nodes += find_nodes(node_tree, "LuxCoreNodeMatGlossyCoating", False)

for node in affected_nodes:
if "IOR" not in node.inputs:
Expand All @@ -89,8 +89,8 @@ def update_volume_nodes_asymmetry_change(node_tree):
if node_tree.bl_idname != "luxcore_volume_nodes":
return

affected_nodes = find_nodes(node_tree, "LuxCoreNodeVolHeterogeneous")
affected_nodes += find_nodes(node_tree, "LuxCoreNodeVolHomogeneous")
affected_nodes = find_nodes(node_tree, "LuxCoreNodeVolHeterogeneous", False)
affected_nodes += find_nodes(node_tree, "LuxCoreNodeVolHomogeneous", False)

for node in affected_nodes:
asymmetry_socket = node.inputs["Asymmetry"]
Expand All @@ -100,23 +100,10 @@ def update_volume_nodes_asymmetry_change(node_tree):
print('Updated %s node "%s" in tree "%s" to new version' % (node.bl_idname, node.name, node_tree.name))


def update_smoke_nodes_add_color_output(node_tree):
# commit f31f3be5409df9866c9b7364ce79e8e7aee0e875

if node_tree.bl_idname != "luxcore_volume_nodes":
return

for node in find_nodes(node_tree, "LuxCoreNodeTexSmoke"):
if "Color" not in node.outputs:
color = node.outputs.new("LuxCoreSocketColor", "Color")
color.enabled = False
print('Updated %s node "%s" in tree "%s" to new version' % (node.bl_idname, node.name, node_tree.name))


def update_colormix_remove_min_max_sockets(node_tree):
# commit 432b1ba020b07f46758fd19b4b3af91cca0c90ff

for node in find_nodes(node_tree, "LuxCoreNodeTexColorMix"):
for node in find_nodes(node_tree, "LuxCoreNodeTexColorMix", False):
if node.mode == "clamp" and "Min" in node.inputs and "Max" in node.inputs:
socket_min = node.inputs["Min"]
socket_max = node.inputs["Max"]
Expand All @@ -130,7 +117,7 @@ def update_colormix_remove_min_max_sockets(node_tree):
def update_imagemap_remove_gamma_brightness_sockets(node_tree):
# commit 428110b2c1bdbf8c54a54030939b3c76cb018644

for node in find_nodes(node_tree, "LuxCoreNodeTexImagemap"):
for node in find_nodes(node_tree, "LuxCoreNodeTexImagemap", False):
updated = False
if "Gamma" in node.inputs:
socket_gamma = node.inputs["Gamma"]
Expand All @@ -151,7 +138,7 @@ def update_imagemap_remove_gamma_brightness_sockets(node_tree):
def update_cloth_remove_repeat_sockets(node_tree):
# commit ec3fccdccb3e4c95a4230df8b38f6494bb8e4583

for node in find_nodes(node_tree, "LuxCoreNodeMatCloth"):
for node in find_nodes(node_tree, "LuxCoreNodeMatCloth", False):
if "Repeat U" in node.inputs and "Repeat V" in node.inputs:
socket_repeat_u = node.inputs["Repeat U"]
socket_repeat_v = node.inputs["Repeat V"]
Expand All @@ -165,7 +152,39 @@ def update_cloth_remove_repeat_sockets(node_tree):
def update_imagemap_add_alpha_output(node_tree):
# commit 09f23b0d758bce9383a0fa8c64ccbeb73706bccf

for node in find_nodes(node_tree, "LuxCoreNodeTexImagemap"):
for node in find_nodes(node_tree, "LuxCoreNodeTexImagemap", False):
if "Alpha" not in node.outputs:
node.outputs.new("LuxCoreSocketFloatUnbounded", "Alpha")
print('Updated %s node "%s" in tree "%s" to new version' % (node.bl_idname, node.name, node_tree.name))


def update_smoke_multiple_output_channels(node_tree):
# commit 204c96ec0d7f5d8d0dbdd183da61b69718aa1747

for node in find_nodes(node_tree, "LuxCoreNodeTexSmoke", False):
if "density" in node.outputs:
continue

node.outputs.new("LuxCoreSocketFloatPositive", "density")
node.outputs.new("LuxCoreSocketFloatPositive", "fire")
node.outputs.new("LuxCoreSocketFloatPositive", "heat")
node.outputs.new("LuxCoreSocketColor", "color")
node.outputs.new("LuxCoreSocketColor", "velocity")

map_source_to_old_output_name = {
"density": "Value",
"fire": "Value",
"heat": "Value",
"color": "Color",
"velocity": "Color",
}
old_output_name = map_source_to_old_output_name[node.source]
new_output_name = node.source

for link in node.outputs[old_output_name].links:
node_tree.links.new(node.outputs[new_output_name], link.to_socket)

node.outputs.remove(node.outputs["Color"])
node.outputs.remove(node.outputs["Value"])

print('Updated %s node "%s" in tree "%s" to new version' % (node.bl_idname, node.name, node_tree.name))
14 changes: 7 additions & 7 deletions utils/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ def get_linked_node(socket):
return link.from_node


def find_nodes(node_tree, bl_idname):
def find_nodes(node_tree, bl_idname, follow_pointers):
result = []

for node in node_tree.nodes:
if node.bl_idname == "LuxCoreNodeTreePointer" and node.node_tree:
if follow_pointers and node.bl_idname == "LuxCoreNodeTreePointer" and node.node_tree:
try:
result += find_nodes(node.node_tree, bl_idname)
result += find_nodes(node.node_tree, bl_idname, follow_pointers)
except RecursionError:
msg = (f'Pointer nodes in node trees "{node_tree.name}" and "{node.node_tree.name}" '
"create a dependency cycle! Delete one of them.")
Expand All @@ -143,11 +143,11 @@ def find_nodes(node_tree, bl_idname):
return result


def has_nodes(node_tree, bl_idname):
def has_nodes(node_tree, bl_idname, follow_pointers):
for node in node_tree.nodes:
if node.bl_idname == "LuxCoreNodeTreePointer" and node.node_tree:
if follow_pointers and node.bl_idname == "LuxCoreNodeTreePointer" and node.node_tree:
try:
if has_nodes(node.node_tree, bl_idname):
if has_nodes(node.node_tree, bl_idname, follow_pointers):
return True
except RecursionError:
msg = (f'Pointer nodes in node trees "{node_tree.name}" and "{node.node_tree.name}" '
Expand All @@ -156,7 +156,7 @@ def has_nodes(node_tree, bl_idname):
# Mark the faulty nodes in red
node.use_custom_color = True
node.color = (0.9, 0, 0)
return result
return False
if node.bl_idname == bl_idname:
return True

Expand Down

0 comments on commit 7490706

Please sign in to comment.