VDM brush baker #104580

Merged
Joseph Eagar merged 10 commits from robin.hohni/blender-addons:vdm-brush-baker into main 2023-05-12 15:42:12 +02:00
3 changed files with 62 additions and 18 deletions
Showing only changes of commit 05b03be3e3 - Show all commits

View File

@ -20,6 +20,9 @@ from datetime import datetime
from pathlib import Path
import os
import bpy
from . import bakematerial
import importlib
importlib.reload(bakematerial)
bl_info = {
'name': 'VDM Brush Baker',
@ -136,22 +139,6 @@ def get_new_brush_name():
return False, f'vdm-{dateformat}'
def get_vdm_bake_material():
if bpy.data.materials.find('VDM_baking_material') == -1:
script_file = os.path.realpath(__file__)
AddonDirectory = Path(os.path.dirname(script_file))
bpy.ops.wm.append(
filepath='VDM_baking_setup.blend',
directory=str(Path.joinpath(
AddonDirectory, 'VDM_baking_setup.blend', 'Material')),
filename='VDM_baking_material'
)
bpy.data.materials['VDM_baking_material'].use_fake_user = True
return bpy.data.materials['VDM_baking_material']
class create_sculpt_plane(bpy.types.Operator):
bl_idname = 'sculptplane.create'
bl_label = 'Create sculpting plane'
@ -209,7 +196,7 @@ class create_vdm_brush(bpy.types.Operator):
default_compute_device = scene.cycles.device
default_scene_samples = scene.cycles.samples
vdm_bake_material = get_vdm_bake_material()
vdm_bake_material = bakematerial.get_vdm_bake_material()
try:
# Prepare baking
scene.render.engine = 'CYCLES'
@ -293,7 +280,6 @@ class create_vdm_brush(bpy.types.Operator):
scene.render.engine = default_render_engine
vdm_plane.data.materials.clear()
bpy.data.materials.remove(vdm_bake_material)
bpy.ops.object.mode_set(mode='SCULPT')

View File

@ -0,0 +1,58 @@
import bpy
def get_vdm_bake_material():
material_name = 'VDM_baking_material'
if material_name not in bpy.data.materials:
new_material = bpy.data.materials.new(name=material_name)
new_material.use_nodes = True
nodes = new_material.node_tree.nodes
nodes.remove(nodes['Principled BSDF'])
material_output = nodes['Material Output']
# Create relevant nodes
combine_node = nodes.new('ShaderNodeCombineXYZ')
separate_node1 = nodes.new('ShaderNodeSeparateXYZ')
separate_node2 = nodes.new('ShaderNodeSeparateXYZ')
vector_subtract_node = nodes.new('ShaderNodeVectorMath')
vector_subtract_node.operation = 'SUBTRACT'
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_add_node = nodes.new('ShaderNodeVectorMath')
vector_add_node.operation = 'ADD'
vector_add_node.inputs[1].default_value = [-0.5, -0.5, -0.5]
tex_coord_node = nodes.new('ShaderNodeTexCoord')
image_node = nodes.new('ShaderNodeTexImage')
image_node.name = "VDMTexture"
# Connect nodes
tree = new_material.node_tree
tree.links.new(combine_node.outputs[0], material_output.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_subtract_node.outputs[0], separate_node1.inputs[0])
tree.links.new(
vector_multiply_node.outputs[0], vector_subtract_node.inputs[1])
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['VDM_baking_material']