Skip to content

Commit b3d2b18

Browse files
committed
[blender] preview: use Freestyle for line art shading
1 parent 05b9ece commit b3d2b18

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

meshroom/nodes/blender/scripts/preview.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -216,37 +216,20 @@ def setupWireframeShading(mesh, color):
216216

217217

218218
def setupLineArtShading(obj, mesh, color):
219-
'''Setup materials and Solidify modifier for line art shading.'''
220-
# Transparent filling material
221-
matFill = bpy.data.materials.new('Fill')
222-
matFill.use_backface_culling = True
223-
matFill.use_nodes = True
224-
matFill.blend_method = 'BLEND'
225-
matFill.show_transparent_back = False
226-
matFill.node_tree.links.clear()
227-
nodeTransparent = matFill.node_tree.nodes.new(type='ShaderNodeBsdfTransparent')
228-
nodeOutputFill = matFill.node_tree.nodes['Material Output']
229-
matFill.node_tree.links.new(nodeTransparent.outputs['BSDF'], nodeOutputFill.inputs['Surface'])
230-
# Colored edge material
231-
matEdge = bpy.data.materials.new('Edge')
232-
matEdge.use_backface_culling = True
233-
matEdge.use_nodes = True
234-
matEdge.blend_method = 'BLEND'
235-
matEdge.node_tree.links.clear()
236-
nodeEmission = matEdge.node_tree.nodes.new(type='ShaderNodeEmission')
237-
nodeEmission.inputs['Color'].default_value = color
238-
nodeOutputEdge = matEdge.node_tree.nodes['Material Output']
239-
matEdge.node_tree.links.new(nodeEmission.outputs['Emission'], nodeOutputEdge.inputs['Surface'])
240-
# Apply materials to mesh
219+
'''Setup line art shading using Freestyle.'''
220+
# Freestyle
221+
bpy.context.scene.render.use_freestyle = True
222+
bpy.data.linestyles["LineStyle"].color = (color[0], color[1], color[2])
223+
# Holdout material
224+
material = bpy.data.materials.new('Holdout')
225+
material.use_nodes = True
226+
material.node_tree.links.clear()
227+
nodeHoldout = material.node_tree.nodes.new(type='ShaderNodeHoldout')
228+
nodeOutput = material.node_tree.nodes['Material Output']
229+
material.node_tree.links.new(nodeHoldout.outputs['Holdout'], nodeOutput.inputs['Surface'])
230+
# Apply material to mesh
241231
mesh.materials.clear()
242-
mesh.materials.append(matFill)
243-
mesh.materials.append(matEdge)
244-
# Solidify modifier
245-
solidify = obj.modifiers.new('Solidify', type='SOLIDIFY')
246-
solidify.thickness = -0.01
247-
solidify.use_rim = False
248-
solidify.use_flip_normals = True
249-
solidify.material_offset = 1
232+
mesh.materials.append(material)
250233

251234

252235
def setupPointCloudShading(obj, color, size):

0 commit comments

Comments
 (0)