vdm-brush-baker: Fix #105028 #105033
@ -16,7 +16,7 @@ bl_info = {
|
|||||||
'author': 'Robin Hohnsbeen',
|
'author': 'Robin Hohnsbeen',
|
||||||
'description': 'Bake vector displacement brushes easily from a plane',
|
'description': 'Bake vector displacement brushes easily from a plane',
|
||||||
'blender': (3, 5, 0),
|
'blender': (3, 5, 0),
|
||||||
'version': (1, 0, 2),
|
'version': (1, 0, 3),
|
||||||
'location': 'Sculpt Mode: View3D > Sidebar > Tool Tab',
|
'location': 'Sculpt Mode: View3D > Sidebar > Tool Tab',
|
||||||
'warning': '',
|
'warning': '',
|
||||||
'category': 'Baking',
|
'category': 'Baking',
|
||||||
@ -88,7 +88,6 @@ class PT_VDMBaker(bpy.types.Panel):
|
|||||||
|
|
||||||
layout.use_property_split = True
|
layout.use_property_split = True
|
||||||
layout.use_property_decorate = False
|
layout.use_property_decorate = False
|
||||||
|
|
||||||
layout.operator(create_sculpt_plane.bl_idname, icon='ADD')
|
layout.operator(create_sculpt_plane.bl_idname, icon='ADD')
|
||||||
|
|
||||||
layout.separator()
|
layout.separator()
|
||||||
@ -187,7 +186,6 @@ class create_vdm_brush(bpy.types.Operator):
|
|||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
vdm_plane = context.active_object
|
vdm_plane = context.active_object
|
||||||
|
|
||||||
addon_data = get_addon_data()
|
addon_data = get_addon_data()
|
||||||
new_brush_name = addon_data.draft_brush_name
|
new_brush_name = addon_data.draft_brush_name
|
||||||
reference_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')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
|
|
||||||
vdm_bake_material = bakematerial.get_vdm_bake_material()
|
vdm_bake_material = bakematerial.get_vdm_bake_material()
|
||||||
|
vdm_texture_image = None
|
||||||
try:
|
try:
|
||||||
# Prepare baking
|
# Prepare baking
|
||||||
scene.render.engine = 'CYCLES'
|
scene.render.engine = 'CYCLES'
|
||||||
|
@ -12,56 +12,62 @@ def get_vdm_bake_material():
|
|||||||
material: Baking material
|
material: Baking material
|
||||||
"""
|
"""
|
||||||
material_name = 'VDM_baking_material'
|
material_name = 'VDM_baking_material'
|
||||||
if material_name not in bpy.data.materials:
|
if material_name in bpy.data.materials:
|
||||||
new_material = bpy.data.materials.new(name=material_name)
|
# 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
|
new_material = bpy.data.materials.new(name=material_name)
|
||||||
nodes = new_material.node_tree.nodes
|
|
||||||
nodes.remove(nodes['Principled BSDF'])
|
|
||||||
material_output = nodes['Material Output']
|
|
||||||
|
|
||||||
# Create relevant nodes
|
new_material.use_nodes = True
|
||||||
combine_node = nodes.new('ShaderNodeCombineXYZ')
|
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')
|
# Create relevant nodes
|
||||||
separate_node2 = nodes.new('ShaderNodeSeparateXYZ')
|
combine_node = nodes.new('ShaderNodeCombineXYZ')
|
||||||
|
|
||||||
vector_subtract_node = nodes.new('ShaderNodeVectorMath')
|
separate_node1 = nodes.new('ShaderNodeSeparateXYZ')
|
||||||
vector_subtract_node.operation = 'SUBTRACT'
|
separate_node2 = nodes.new('ShaderNodeSeparateXYZ')
|
||||||
|
|
||||||
vector_multiply_node = nodes.new('ShaderNodeVectorMath')
|
vector_subtract_node = nodes.new('ShaderNodeVectorMath')
|
||||||
vector_multiply_node.operation = 'MULTIPLY'
|
vector_subtract_node.operation = 'SUBTRACT'
|
||||||
vector_multiply_node.inputs[1].default_value = [2.0, 2.0, 2.0]
|
|
||||||
|
|
||||||
vector_add_node = nodes.new('ShaderNodeVectorMath')
|
vector_multiply_node = nodes.new('ShaderNodeVectorMath')
|
||||||
vector_add_node.operation = 'ADD'
|
vector_multiply_node.operation = 'MULTIPLY'
|
||||||
vector_add_node.inputs[1].default_value = [-0.5, -0.5, -0.5]
|
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')
|
tex_coord_node = nodes.new('ShaderNodeTexCoord')
|
||||||
image_node.name = "VDMTexture"
|
|
||||||
|
|
||||||
# Connect nodes
|
image_node = nodes.new('ShaderNodeTexImage')
|
||||||
tree = new_material.node_tree
|
image_node.name = "VDMTexture"
|
||||||
tree.links.new(combine_node.outputs[0], material_output.inputs[0])
|
|
||||||
|
|
||||||
tree.links.new(separate_node1.outputs[0], combine_node.inputs[0])
|
# Connect nodes
|
||||||
tree.links.new(separate_node1.outputs[1], combine_node.inputs[1])
|
tree = new_material.node_tree
|
||||||
|
tree.links.new(combine_node.outputs[0], material_output.inputs[0])
|
||||||
|
|
||||||
tree.links.new(
|
tree.links.new(separate_node1.outputs[0], combine_node.inputs[0])
|
||||||
vector_subtract_node.outputs[0], separate_node1.inputs[0])
|
tree.links.new(separate_node1.outputs[1], combine_node.inputs[1])
|
||||||
|
|
||||||
tree.links.new(
|
tree.links.new(
|
||||||
vector_multiply_node.outputs[0], vector_subtract_node.inputs[1])
|
vector_subtract_node.outputs[0], separate_node1.inputs[0])
|
||||||
|
|
||||||
tree.links.new(
|
tree.links.new(
|
||||||
vector_add_node.outputs[0], vector_multiply_node.inputs[0])
|
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(
|
||||||
tree.links.new(
|
vector_add_node.outputs[0], vector_multiply_node.inputs[0])
|
||||||
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(tex_coord_node.outputs[2], vector_add_node.inputs[0])
|
||||||
tree.links.new(separate_node2.outputs[2], combine_node.inputs[2])
|
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]
|
return bpy.data.materials[material_name]
|
||||||
|
Loading…
Reference in New Issue
Block a user