adjust the stand a bit
This commit is contained in:
@@ -4,6 +4,7 @@ Usage: blender --background --python script/render_previews.py -- model.3mf outp
|
||||
"""
|
||||
|
||||
import math
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import zipfile
|
||||
@@ -13,12 +14,15 @@ import bpy
|
||||
from mathutils import Vector
|
||||
|
||||
|
||||
def args():
|
||||
marker = sys.argv.index("--")
|
||||
return os.path.abspath(sys.argv[marker + 1]), os.path.abspath(sys.argv[marker + 2])
|
||||
|
||||
|
||||
source, output = args()
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("source")
|
||||
parser.add_argument("output")
|
||||
parser.add_argument("--moon", help="Existing Moon 3MF to show on the stand, without modifying it")
|
||||
parser.add_argument("--moon-center-z", type=float, default=0.0)
|
||||
parser.add_argument("--focus", nargs=3, type=float, help="Center a detail view at X Y Z")
|
||||
parser.add_argument("--span", type=float, help="Detail-view span in millimeters")
|
||||
options = parser.parse_args(sys.argv[sys.argv.index("--") + 1:])
|
||||
source, output = os.path.abspath(options.source), os.path.abspath(options.output)
|
||||
os.makedirs(output, exist_ok=True)
|
||||
bpy.ops.object.select_all(action="SELECT")
|
||||
bpy.ops.object.delete(use_global=False)
|
||||
@@ -37,6 +41,7 @@ def import_3mf(path):
|
||||
material = bpy.data.materials.new(base.attrib.get("name", "material"))
|
||||
material.diffuse_color = rgba
|
||||
materials.append(material)
|
||||
imported = []
|
||||
for element in root.findall("m:resources/m:object", namespace):
|
||||
mesh_node = element.find("m:mesh", namespace)
|
||||
if mesh_node is None:
|
||||
@@ -50,11 +55,17 @@ def import_3mf(path):
|
||||
data.update()
|
||||
obj = bpy.data.objects.new(element.attrib.get("name", "object"), data)
|
||||
bpy.context.collection.objects.link(obj)
|
||||
imported.append(obj)
|
||||
if materials and "pindex" in element.attrib:
|
||||
obj.data.materials.append(materials[int(element.attrib["pindex"])])
|
||||
return imported
|
||||
|
||||
|
||||
import_3mf(source)
|
||||
if options.moon:
|
||||
for obj in import_3mf(options.moon):
|
||||
obj.location.z += options.moon_center_z
|
||||
bpy.context.view_layer.update()
|
||||
|
||||
objects = [obj for obj in bpy.context.scene.objects if obj.type == "MESH"]
|
||||
if not objects:
|
||||
@@ -67,6 +78,10 @@ minimum = Vector((min(p.x for p in corners), min(p.y for p in corners), min(p.z
|
||||
maximum = Vector((max(p.x for p in corners), max(p.y for p in corners), max(p.z for p in corners)))
|
||||
center = (minimum + maximum) / 2
|
||||
extent = max(maximum - minimum)
|
||||
if options.focus:
|
||||
center = Vector(options.focus)
|
||||
if options.span:
|
||||
extent = options.span
|
||||
|
||||
world = bpy.context.scene.world
|
||||
world.color = (0.035, 0.035, 0.035)
|
||||
@@ -86,7 +101,9 @@ camera.data.ortho_scale = extent * 1.25
|
||||
|
||||
for energy, direction in [(1800, Vector((1, -1, 2))), (900, Vector((-2, 1, 0.5)) )]:
|
||||
light_data = bpy.data.lights.new(name="Area", type="AREA")
|
||||
light_data.energy = energy
|
||||
# Imported coordinates are millimeters; scale light power with distance
|
||||
# squared so large models do not turn into unreadable silhouettes.
|
||||
light_data.energy = energy * extent * extent * 0.1
|
||||
light_data.shape = "DISK"
|
||||
light_data.size = extent
|
||||
light = bpy.data.objects.new(name="Area", object_data=light_data)
|
||||
|
||||
Reference in New Issue
Block a user