[blender] preview: use Freestyle for line art shading

This commit is contained in:
Loïc Vital 2023-06-19 15:48:23 +02:00
parent 05b9ece40f
commit b3d2b18f44

View file

@ -216,37 +216,20 @@ def setupWireframeShading(mesh, color):
def setupLineArtShading(obj, mesh, color): def setupLineArtShading(obj, mesh, color):
'''Setup materials and Solidify modifier for line art shading.''' '''Setup line art shading using Freestyle.'''
# Transparent filling material # Freestyle
matFill = bpy.data.materials.new('Fill') bpy.context.scene.render.use_freestyle = True
matFill.use_backface_culling = True bpy.data.linestyles["LineStyle"].color = (color[0], color[1], color[2])
matFill.use_nodes = True # Holdout material
matFill.blend_method = 'BLEND' material = bpy.data.materials.new('Holdout')
matFill.show_transparent_back = False material.use_nodes = True
matFill.node_tree.links.clear() material.node_tree.links.clear()
nodeTransparent = matFill.node_tree.nodes.new(type='ShaderNodeBsdfTransparent') nodeHoldout = material.node_tree.nodes.new(type='ShaderNodeHoldout')
nodeOutputFill = matFill.node_tree.nodes['Material Output'] nodeOutput = material.node_tree.nodes['Material Output']
matFill.node_tree.links.new(nodeTransparent.outputs['BSDF'], nodeOutputFill.inputs['Surface']) material.node_tree.links.new(nodeHoldout.outputs['Holdout'], nodeOutput.inputs['Surface'])
# Colored edge material # Apply material to mesh
matEdge = bpy.data.materials.new('Edge')
matEdge.use_backface_culling = True
matEdge.use_nodes = True
matEdge.blend_method = 'BLEND'
matEdge.node_tree.links.clear()
nodeEmission = matEdge.node_tree.nodes.new(type='ShaderNodeEmission')
nodeEmission.inputs['Color'].default_value = color
nodeOutputEdge = matEdge.node_tree.nodes['Material Output']
matEdge.node_tree.links.new(nodeEmission.outputs['Emission'], nodeOutputEdge.inputs['Surface'])
# Apply materials to mesh
mesh.materials.clear() mesh.materials.clear()
mesh.materials.append(matFill) mesh.materials.append(material)
mesh.materials.append(matEdge)
# Solidify modifier
solidify = obj.modifiers.new('Solidify', type='SOLIDIFY')
solidify.thickness = -0.01
solidify.use_rim = False
solidify.use_flip_normals = True
solidify.material_offset = 1
def setupPointCloudShading(obj, color, size): def setupPointCloudShading(obj, color, size):