diff --git a/src/Main.hs b/src/Main.hs index d651dc4..3e43665 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -203,7 +203,7 @@ screwPos = do tn <- asks _topNotch isSplit <- asks _split ps <- outlinePos - let d = (sw / 2) - 2 + let d = max 1 ((sw / 2) - 2) (br, tr, tl, bl) = (head ps, ps !! 1, ps !! 2, ps !! 4) return [ bl + (0, d) @@ -449,8 +449,6 @@ render k = do callProcess fp [ "--background" - , "-e" - , "CYCLES" , "--factory-startup" , "--python" , "svgto3dpng.py" diff --git a/svgto3dpng.py b/svgto3dpng.py index 738c34a..7101002 100644 --- a/svgto3dpng.py +++ b/svgto3dpng.py @@ -5,6 +5,8 @@ import mathutils +mm = 0.001 + def get_objects(l): return list(filter(lambda x: x.type in l, bpy.context.scene.objects)) @@ -29,7 +31,6 @@ def create(fp): objs = get_objects(['MESH','CURVE']) - mm = 0.001 heights = [3.0 * mm, 3.0 * mm, 3.0 * mm, 1.5 * mm, 3.0 * mm] gap = 0.05 * mm @@ -81,16 +82,38 @@ def adjust_materials(): elif obj.name == 'Curve.001': obj.active_material.blend_method = 'BLEND' obj.active_material.use_nodes = True - obj.active_material.node_tree.nodes["Principled BSDF"].inputs[18].default_value = 0.8 + obj.active_material.node_tree.nodes["Principled BSDF"].inputs[18].default_value = 0.7 def adjust_view(): # move camera closer camera = bpy.data.objects['Camera'] - looking_direction = camera.location - mathutils.Vector((0.0, 0.0, 0.0)) + camera.location = (0.3, -0.4, 0.3) + looking_direction = camera.location - mathutils.Vector((0.0, 0.1, 0.0)) rot_quat = looking_direction.to_track_quat('Z', 'Y') camera.rotation_euler = rot_quat.to_euler() camera.location = rot_quat @ mathutils.Vector((0.0, 0.0, 0.5)) + +def postprocess(): + # create backgroung plane + mat = bpy.data.materials.new("BKG") + mat.diffuse_color = (0.0, 0.0, 0.0, 1.0) + mat.roughness = 0.7 + bpy.ops.mesh.primitive_plane_add(location=(0,0,0)) + o = bpy.context.selected_objects[0] + o.active_material = mat + + light_data = bpy.data.lights.new(name="light_", type='POINT') + light_data.energy = 5 + light_data.use_shadow = True + light_data.use_contact_shadow = True + light_object = bpy.data.objects.new(name="light_", object_data=light_data) + bpy.context.collection.objects.link(light_object) + bpy.context.view_layer.objects.active = light_object + light_object.location = (0, 0, 100 * mm) + + bpy.context.scene.world.light_settings.use_ambient_occlusion = True + bpy.context.scene.world.light_settings.ao_factor = 0.5 def render(rp): # render scene @@ -125,7 +148,9 @@ def export(rp): move() adjust_materials() adjust_view() -render(rp) export(rp) +postprocess() +render(rp) +