diff --git a/main.py b/main.py index e3da74a..1f346fd 100644 --- a/main.py +++ b/main.py @@ -30,7 +30,9 @@ def automate_function( } Path("./automate_data.json").write_text(json.dumps(data)) - + + print("Starting blender") + process = run( [ 'blender', @@ -42,16 +44,17 @@ def automate_function( capture_output=True, text=True, ) + print(process.stdout) + print(process.stderr) + if (returncode := process.returncode) != 0: - automate_context.mark_run_failed(f"The blender process exited with code {returncode}\n{process.stdout}") + automate_context.mark_run_failed(f"The blender process exited with error code {returncode}\n{process.stdout}") else: - print(process.stdout) - print(process.stderr) - - for file_path in Path("./Screenshots").glob("**/*.png") : + files = Path("./Screenshots").glob("**/*.png") + for file_path in files: automate_context.store_file_result(file_path) - automate_context.mark_run_success("YAYAY!!! we did it!") + automate_context.mark_run_success(f"YAYAY!!! we did it! - {len(files}} exported") diff --git a/speckle_import.py b/speckle_import.py index 2320ebd..2524f2b 100644 --- a/speckle_import.py +++ b/speckle_import.py @@ -3,7 +3,7 @@ import json from pathlib import Path -from mathutils import Vector +from mathutils import Color, Vector from bpy_speckle.convert.to_native import _deep_conversion, can_convert_to_native, convert_to_native, display_value_to_native, get_scale_factor from specklepy.api import operations @@ -41,22 +41,29 @@ def set_filename(fileName): converted_objects = {} _deep_conversion(root_object, converted_objects, True) -#Make all materials blank +#Make all materials white for mat in bpy.data.materials: - mat.diffuse_color = (1.0, 1.0, 1.0, 1.0) + COLOR = (1.0, 1.0, 1.0, 1.0) + mat.diffuse_color = COLOR + inputs = mat.node_tree.nodes["Principled BSDF"].inputs + inputs["Base Color"].default_value = COLOR + # Convert all rooms as lights traversal_func = get_default_traversal_func(can_convert_to_native) rooms = [x.current for x in traversal_func.traverse(root_object) if x.current.speckle_type == "Objects.BuiltElements.Room"] light = bpy.data.lights.new("myLight", 'POINT') +light.color = Color((1, 0.34, 0.1)) +light.energy = 100 #watts +print(f"Found {len(rooms)} rooms") for room in rooms: (converted, _) = display_value_to_native(room, f"FakeRoom{room.id}", get_scale_factor(room)) #calculate bounds - minimum = Vector((-math.inf, -math.inf, -math.inf)) - maximum = Vector((math.inf, math.inf, math.inf)) + minimum = Vector((+math.inf, +math.inf, +math.inf)) + maximum = Vector((-math.inf, -math.inf, -math.inf)) for vert in converted.vertices: minimum.x = min(minimum.x, vert.co.x) @@ -66,9 +73,12 @@ def set_filename(fileName): maximum.y = max(maximum.y, vert.co.y) maximum.z = max(maximum.z, vert.co.z) - bpy.data.objects.new(f"FakeLight{room.id}", light) + light_pos = minimum.lerp(maximum, 0.5) + light_object = bpy.data.objects.new(f"FakeLight{room.id}", light) + light_object.matrix_local.translation = light_pos + bpy.context.collection.objects.link(light_object) all_cameras = [o for o in bpy.context.scene.objects if o.type == "CAMERA"] @@ -83,6 +93,6 @@ def set_filename(fileName): # Render camera to output directory set_filename(f"{ob.name}") bpy.ops.render.render(write_still=True) - print(f"Render {i}/{total} complete! saved at {bpy.context.scene.render.filepath}") + print(f"Render {i + 1}/{total} complete! saved at {bpy.context.scene.render.filepath}") print(f"All Done!")