vdm-brush-baker: Fix #105028 #105033

Merged
Germano Cavalcante merged 1 commits from robin.hohni/blender-addons:vdm-brush-baker into main 2023-11-30 15:36:47 +01:00
2 changed files with 45 additions and 40 deletions
Showing only changes of commit aa29a26392 - Show all commits

View File

@ -16,7 +16,7 @@ bl_info = {
'author': 'Robin Hohnsbeen',
'description': 'Bake vector displacement brushes easily from a plane',
'blender': (3, 5, 0),
'version': (1, 0, 2),
'version': (1, 0, 3),
'location': 'Sculpt Mode: View3D > Sidebar > Tool Tab',
'warning': '',
'category': 'Baking',
@ -88,7 +88,6 @@ class PT_VDMBaker(bpy.types.Panel):
layout.use_property_split = True
layout.use_property_decorate = False
layout.operator(create_sculpt_plane.bl_idname, icon='ADD')
layout.separator()
@ -187,7 +186,6 @@ class create_vdm_brush(bpy.types.Operator):
return {'CANCELLED'}
vdm_plane = context.active_object
addon_data = get_addon_data()
new_brush_name = addon_data.draft_brush_name
reference_brush_name = addon_data.draft_brush_name
@ -214,6 +212,7 @@ class create_vdm_brush(bpy.types.Operator):
bpy.ops.object.mode_set(mode='OBJECT')
vdm_bake_material = bakematerial.get_vdm_bake_material()
vdm_texture_image = None
try:
# Prepare baking
scene.render.engine = 'CYCLES'

View File

@ -12,56 +12,62 @@ def get_vdm_bake_material():
material: Baking material
"""
material_name = 'VDM_baking_material'
if material_name not in bpy.data.materials:
new_material = bpy.data.materials.new(name=material_name)
if material_name in bpy.data.materials:
# Recreate material every time to ensure it is unchanged by the user which could lead to issues.
# I would like to keep it directly after bake though so people could look
# at how it is made, if they are interested.
bpy.data.materials.remove(bpy.data.materials[material_name])
new_material.use_nodes = True
nodes = new_material.node_tree.nodes
nodes.remove(nodes['Principled BSDF'])
material_output = nodes['Material Output']
new_material = bpy.data.materials.new(name=material_name)
# Create relevant nodes
combine_node = nodes.new('ShaderNodeCombineXYZ')
new_material.use_nodes = True
nodes = new_material.node_tree.nodes
principled_node = next(n for n in new_material.node_tree.nodes if n.type == "BSDF_PRINCIPLED")
nodes.remove(principled_node)
material_output = next(n for n in new_material.node_tree.nodes if n.type == "OUTPUT_MATERIAL")
separate_node1 = nodes.new('ShaderNodeSeparateXYZ')
separate_node2 = nodes.new('ShaderNodeSeparateXYZ')
# Create relevant nodes
combine_node = nodes.new('ShaderNodeCombineXYZ')
vector_subtract_node = nodes.new('ShaderNodeVectorMath')
vector_subtract_node.operation = 'SUBTRACT'
separate_node1 = nodes.new('ShaderNodeSeparateXYZ')
separate_node2 = nodes.new('ShaderNodeSeparateXYZ')
vector_multiply_node = nodes.new('ShaderNodeVectorMath')
vector_multiply_node.operation = 'MULTIPLY'
vector_multiply_node.inputs[1].default_value = [2.0, 2.0, 2.0]
vector_subtract_node = nodes.new('ShaderNodeVectorMath')
vector_subtract_node.operation = 'SUBTRACT'
vector_add_node = nodes.new('ShaderNodeVectorMath')
vector_add_node.operation = 'ADD'
vector_add_node.inputs[1].default_value = [-0.5, -0.5, -0.5]
vector_multiply_node = nodes.new('ShaderNodeVectorMath')
vector_multiply_node.operation = 'MULTIPLY'
vector_multiply_node.inputs[1].default_value = [2.0, 2.0, 2.0]
tex_coord_node = nodes.new('ShaderNodeTexCoord')
vector_add_node = nodes.new('ShaderNodeVectorMath')
vector_add_node.operation = 'ADD'
vector_add_node.inputs[1].default_value = [-0.5, -0.5, -0.5]
image_node = nodes.new('ShaderNodeTexImage')
image_node.name = "VDMTexture"
tex_coord_node = nodes.new('ShaderNodeTexCoord')
# Connect nodes
tree = new_material.node_tree
tree.links.new(combine_node.outputs[0], material_output.inputs[0])
image_node = nodes.new('ShaderNodeTexImage')
image_node.name = "VDMTexture"
tree.links.new(separate_node1.outputs[0], combine_node.inputs[0])
tree.links.new(separate_node1.outputs[1], combine_node.inputs[1])
# Connect nodes
tree = new_material.node_tree
tree.links.new(combine_node.outputs[0], material_output.inputs[0])
tree.links.new(
vector_subtract_node.outputs[0], separate_node1.inputs[0])
tree.links.new(separate_node1.outputs[0], combine_node.inputs[0])
tree.links.new(separate_node1.outputs[1], combine_node.inputs[1])
tree.links.new(
vector_multiply_node.outputs[0], vector_subtract_node.inputs[1])
tree.links.new(
vector_subtract_node.outputs[0], separate_node1.inputs[0])
tree.links.new(
vector_add_node.outputs[0], vector_multiply_node.inputs[0])
tree.links.new(
vector_multiply_node.outputs[0], vector_subtract_node.inputs[1])
tree.links.new(tex_coord_node.outputs[2], vector_add_node.inputs[0])
tree.links.new(
tex_coord_node.outputs[3], vector_subtract_node.inputs[0])
tree.links.new(tex_coord_node.outputs[3], separate_node2.inputs[0])
tree.links.new(separate_node2.outputs[2], combine_node.inputs[2])
tree.links.new(
vector_add_node.outputs[0], vector_multiply_node.inputs[0])
tree.links.new(tex_coord_node.outputs[2], vector_add_node.inputs[0])
tree.links.new(
tex_coord_node.outputs[3], vector_subtract_node.inputs[0])
tree.links.new(tex_coord_node.outputs[3], separate_node2.inputs[0])
tree.links.new(separate_node2.outputs[2], combine_node.inputs[2])
return bpy.data.materials[material_name]