Merged PR #28: v0.1.2 — scale calibration, façade detail, export preset Co-authored-by: Zwitschi <zwitschi82@gmail.com>
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
# Scale-test scene builder and FBX exporter for the Blender -> Unreal pipeline.
|
|
#
|
|
# Builds three 1 m cubes in the project geographic frame (EPSG:26911, origin
|
|
# Hollywood x Highland, X east / Y north / Z up):
|
|
# ScaleTest_A centred at (0, 0, 0.5) - origin + 1 m size reference
|
|
# ScaleTest_B centred at (10, 0, 0.5) - +10 m east probe
|
|
# ScaleTest_C centred at (0, 10, 0.5) - +10 m north probe
|
|
# and exports them as one FBX with the named export preset "ue_metric_v1".
|
|
#
|
|
# Run headless (see Art/blender/README.md for the Flatpak invocation):
|
|
# blender -b --factory-startup --python Tools/scale_test_export.py -- \
|
|
# --out /tmp/gigline/scaletest.fbx --save-blend Art/blender/scaletest/scale-test-<date>.blend
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
import bpy
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import fbx_export_preset as fbx_preset # noqa: E402
|
|
|
|
|
|
|
|
def build_scene():
|
|
scene = bpy.context.scene
|
|
for obj in list(bpy.data.objects):
|
|
bpy.data.objects.remove(obj, do_unlink=True)
|
|
|
|
mat = bpy.data.materials.new("M_ScaleTest_Red")
|
|
mat.use_nodes = True
|
|
bsdf = mat.node_tree.nodes.get("Principled BSDF")
|
|
bsdf.inputs["Base Color"].default_value = (0.8, 0.05, 0.05, 1.0)
|
|
|
|
specs = {
|
|
"ScaleTest_A": (0.0, 0.0, 0.5),
|
|
"ScaleTest_B": (10.0, 0.0, 0.5),
|
|
"ScaleTest_C": (0.0, 10.0, 0.5),
|
|
}
|
|
for name, loc in specs.items():
|
|
bpy.ops.mesh.primitive_cube_add(size=1.0, location=loc)
|
|
obj = bpy.context.active_object
|
|
obj.name = name
|
|
obj.data.materials.append(mat)
|
|
print(f"[scale_test] created {name} at {loc}")
|
|
|
|
|
|
def export_fbx(path):
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
# Named export preset "ue_metric_v1" - change only via a new preset name.
|
|
fbx_preset.export_static(path)
|
|
print(f"[scale_test] exported FBX preset ue_metric_v1 -> {path}")
|
|
|
|
|
|
def main():
|
|
argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--out", default="/tmp/gigline/scaletest.fbx")
|
|
parser.add_argument("--save-blend", default=None)
|
|
args = parser.parse_args(argv)
|
|
|
|
build_scene()
|
|
|
|
if args.save_blend:
|
|
os.makedirs(os.path.dirname(args.save_blend), exist_ok=True)
|
|
bpy.ops.wm.save_as_mainfile(filepath=args.save_blend)
|
|
print(f"[scale_test] saved {args.save_blend}")
|
|
|
|
export_fbx(args.out)
|
|
|
|
|
|
main()
|