Add modular assembly verification blend pipeline

This commit is contained in:
krustophski 2026-06-18 06:30:06 +03:00
parent 3857424cfa
commit 68e8423fa2
10 changed files with 512 additions and 8 deletions

View file

@ -89,6 +89,27 @@ Example:
& "C:/Program Files/Blender Foundation/Blender 5.1/blender.exe" --background --python "C:/Users/post/Documents/mrPlow/mrPlow58/Tools/VehiclePipeline/prepare_vehicle_exports.py" -- --input-root "C:/Users/post/Documents/mrPlow/in" --output-root "C:/Users/post/Documents/mrPlow/mrPlow58/VehicleExports"
```
## Build Visual Verification Assembly
Use this before Unreal import when checking whether every module fits the truck:
```powershell
& "C:/Program Files/Blender Foundation/Blender 5.1/blender.exe" --background --python "C:/Users/post/Documents/mrPlow/mrPlow58/Tools/VehiclePipeline/build_modular_assembly_verify.py" -- --input-root "C:/Users/post/Documents/mrPlow/in" --export-report "C:/Users/post/Documents/mrPlow/mrPlow58/VehicleExports/mrplow_modular_assembly_verify_report.json"
```
This writes one visual master file:
- `C:/Users/post/Documents/mrPlow/in/mrplow_modular_assembly_verify.blend`
Open it in Blender and inspect:
- `MrPlow_Chassis`: clean KAMAZ chassis and rig source
- `MrPlow_Modules`: original KAMAZ modules still in the master file
- `Verify_02_KAMAZ_With_KRAZ_Modules`: side-by-side fit check with KRAZ `body for bulk` and `blade bucket`
- `Verify_Labels`: socket markers and labels
The visual verification file is for checking fit. Unreal import remains modular: chassis as skeletal mesh, equipment as separate static/skeletal modules.
## Scale And Axis Validation
Before importing a vehicle into Unreal, run:

View file

@ -0,0 +1,296 @@
import argparse
import json
import math
import sys
from pathlib import Path
import bpy
from mathutils import Vector
KAMAZ_CLEAN_FILE = "kamaz_65115_clean.blend"
KRAZ_FILE = "kraz_6322 .blend"
VERIFY_FILE = "mrplow_modular_assembly_verify.blend"
VERIFY_REPORT = "mrplow_modular_assembly_verify_report.json"
KAMAZ_MODULE_NAMES = ["KUZOV", "GRUZ", "broom"]
KRAZ_MODULE_NAMES = ["body for bulk", "blade bucket"]
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--input-root", required=True)
parser.add_argument("--export-report", default="")
argv = sys.argv
if "--" in argv:
argv = argv[argv.index("--") + 1:]
else:
argv = []
return parser.parse_args(argv)
def ensure_collection(name):
collection = bpy.data.collections.get(name)
if collection is None:
collection = bpy.data.collections.new(name)
bpy.context.scene.collection.children.link(collection)
return collection
def clear_collection(name):
collection = ensure_collection(name)
for obj in list(collection.objects):
bpy.data.objects.remove(obj, do_unlink=True)
return collection
def move_to_collection(obj, collection):
for source_collection in list(obj.users_collection):
source_collection.objects.unlink(obj)
collection.objects.link(obj)
def link_to_collection(obj, collection):
if obj.name not in collection.objects:
collection.objects.link(obj)
def mesh_objects():
return [obj for obj in bpy.context.scene.objects if obj.type == "MESH"]
def bounds(objects):
points = []
for obj in objects:
for corner in obj.bound_box:
points.append(obj.matrix_world @ Vector(corner))
if not points:
zero = Vector((0, 0, 0))
return zero, zero, zero
min_v = Vector((min(p.x for p in points), min(p.y for p in points), min(p.z for p in points)))
max_v = Vector((max(p.x for p in points), max(p.y for p in points), max(p.z for p in points)))
return min_v, max_v, max_v - min_v
def center(objects):
min_v, max_v, _ = bounds(objects)
return (min_v + max_v) * 0.5
def object_report(obj):
min_v, max_v, size = bounds([obj])
return {
"name": obj.name,
"type": obj.type,
"locationM": [round(obj.location.x, 4), round(obj.location.y, 4), round(obj.location.z, 4)],
"boundsMinM": [round(min_v.x, 4), round(min_v.y, 4), round(min_v.z, 4)],
"boundsMaxM": [round(max_v.x, 4), round(max_v.y, 4), round(max_v.z, 4)],
"sizeCm": {
"x": round(size.x * 100.0, 2),
"y": round(size.y * 100.0, 2),
"z": round(size.z * 100.0, 2),
},
"nonUnitScale": any(abs(value - 1.0) > 0.001 for value in (obj.scale.x, obj.scale.y, obj.scale.z)),
"negativeScale": obj.scale.x < 0 or obj.scale.y < 0 or obj.scale.z < 0,
}
def append_objects_from_blend(blend_path, names):
with bpy.data.libraries.load(str(blend_path), link=False) as (data_from, data_to):
data_to.objects = [name for name in names if name in data_from.objects]
appended = []
for obj in data_to.objects:
if obj:
bpy.context.scene.collection.objects.link(obj)
appended.append(obj)
return appended
def duplicate_linked(obj, suffix, offset, collection):
dup = obj.copy()
dup.data = obj.data
dup.animation_data_clear()
dup.name = f"{obj.name}{suffix}"
dup.location = obj.location + offset
collection.objects.link(dup)
return dup
def duplicate_collection_objects(source_collection_name, suffix, offset, target_collection):
source = bpy.data.collections.get(source_collection_name)
if not source:
return []
duplicated = []
for obj in source.objects:
if obj.type != "MESH":
continue
duplicated.append(duplicate_linked(obj, suffix, offset, target_collection))
return duplicated
def align_bottom_center(obj, target_center, target_bottom_z):
min_v, max_v, size = bounds([obj])
obj_center = (min_v + max_v) * 0.5
delta = Vector((
target_center.x - obj_center.x,
target_center.y - obj_center.y,
target_bottom_z - min_v.z,
))
obj.location += delta
def add_text_label(name, text, location, collection):
bpy.ops.object.text_add(location=location, rotation=(math.radians(65), 0, 0))
obj = bpy.context.object
obj.name = name
obj.data.name = f"{name}_Text"
obj.data.body = text
obj.data.align_x = "CENTER"
obj.data.align_y = "CENTER"
obj.data.size = 0.22
obj.data.extrude = 0.005
move_to_collection(obj, collection)
return obj
def add_marker_empty(name, location, collection):
obj = bpy.data.objects.new(name, None)
obj.empty_display_type = "SPHERE"
obj.empty_display_size = 0.25
obj.location = location
collection.objects.link(obj)
return obj
def set_view_assets():
bpy.ops.object.light_add(type="AREA", location=(0, -7, 8))
light = bpy.context.object
light.name = "Verify_AreaLight"
light.data.energy = 700
light.data.size = 8
bpy.ops.object.camera_add(location=(4, -12, 6), rotation=(math.radians(62), 0, math.radians(28)))
camera = bpy.context.object
bpy.context.scene.camera = camera
camera.name = "Verify_Camera"
camera.data.lens = 24
def main():
args = parse_args()
input_root = Path(args.input_root)
kamaz_clean_path = input_root / KAMAZ_CLEAN_FILE
kraz_path = input_root / KRAZ_FILE
verify_path = input_root / VERIFY_FILE
report_path = input_root / VERIFY_REPORT
bpy.ops.wm.open_mainfile(filepath=str(kamaz_clean_path))
labels_collection = clear_collection("Verify_Labels")
variant_collection = clear_collection("Verify_02_KAMAZ_With_KRAZ_Modules")
parking_collection = clear_collection("Verify_03_Module_Parking")
ensure_collection("Verify_01_KAMAZ_Default")
kraz_modules = append_objects_from_blend(kraz_path, KRAZ_MODULE_NAMES)
for obj in kraz_modules:
move_to_collection(obj, parking_collection)
obj.name = f"KRAZ_{obj.name}"
# Apply transforms from the imported source so module dimensions and pivots are explicit.
bpy.ops.object.select_all(action="DESELECT")
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
variant_offset = Vector((0, 5.0, 0))
variant_chassis = duplicate_collection_objects("MrPlow_Chassis", "_VerifyKrazVariant", variant_offset, variant_collection)
kuzov = bpy.data.objects.get("KUZOV")
kamaz_modules = [bpy.data.objects.get(name) for name in KAMAZ_MODULE_NAMES]
kamaz_modules = [obj for obj in kamaz_modules if obj]
kraz_body = bpy.data.objects.get("KRAZ_body for bulk")
kraz_blade = bpy.data.objects.get("KRAZ_blade bucket")
placed_modules = []
if kuzov and kraz_body:
target_min, target_max, _ = bounds([kuzov])
target = (target_min + target_max) * 0.5 + variant_offset
align_bottom_center(kraz_body, target, target_min.z)
link_to_collection(kraz_body, variant_collection)
placed_modules.append(kraz_body)
if variant_chassis and kraz_blade:
min_v, max_v, _ = bounds(variant_chassis)
blade_min, blade_max, blade_size = bounds([kraz_blade])
target_center = Vector((max_v.x + blade_size.x * 0.5 + 0.15, variant_offset.y, min_v.z + 0.05))
align_bottom_center(kraz_blade, target_center, min_v.z + 0.05)
link_to_collection(kraz_blade, variant_collection)
placed_modules.append(kraz_blade)
for obj in placed_modules:
if obj.name in parking_collection.objects:
parking_collection.objects.unlink(obj)
default_center = center(mesh_objects())
add_text_label(
"Label_Default_Kamaz",
"01 KAMAZ default assembly: chassis + KUZOV + GRUZ + broom",
Vector((default_center.x, -2.9, 3.4)),
labels_collection,
)
add_text_label(
"Label_Kraz_Modules",
"02 KAMAZ fit check: KRAZ body for bulk + blade bucket",
Vector((default_center.x, 5.0 - 2.9, 3.4)),
labels_collection,
)
for socket_name in ["Socket_FrontBlade", "Socket_RearModule", "Socket_Cargo", "Socket_Broom", "Socket_Hitch"]:
socket = bpy.data.objects.get(socket_name)
if socket:
add_marker_empty(f"VerifyMarker_{socket_name}", socket.location, labels_collection)
add_text_label(f"Label_{socket_name}", socket_name, socket.location + Vector((0, 0, 0.35)), labels_collection)
set_view_assets()
default_objects = variant_chassis + kamaz_modules
report = {
"sourceFiles": {
"kamazClean": str(kamaz_clean_path),
"kraz": str(kraz_path),
"verifyBlend": str(verify_path),
},
"axisConvention": {
"x": "forward",
"y": "right",
"z": "up",
"sourceUnits": "meters",
"unrealUnits": "centimeters",
},
"verificationCollections": [
"MrPlow_Chassis",
"MrPlow_Modules",
"MrPlow_Rig",
"Verify_02_KAMAZ_With_KRAZ_Modules",
"Verify_03_Module_Parking",
"Verify_Labels",
],
"kamazModules": [object_report(obj) for obj in kamaz_modules],
"krazModulesPlacedOnKamaz": [object_report(obj) for obj in placed_modules],
"variantChassisBounds": object_report(variant_chassis[0]) if variant_chassis else {},
"notes": [
"KAMAZ default modules remain in the clean source file and are exported separately.",
"KRAZ modules are placed in a side-by-side fit variant, offset by +5m on Y.",
"Final Unreal import still uses separate FBX assets, not one combined mesh.",
],
}
report_path.write_text(json.dumps(report, indent=2), encoding="utf-8")
if args.export_report:
export_report_path = Path(args.export_report)
export_report_path.parent.mkdir(parents=True, exist_ok=True)
export_report_path.write_text(json.dumps(report, indent=2), encoding="utf-8")
bpy.ops.wm.save_as_mainfile(filepath=str(verify_path))
if __name__ == "__main__":
main()

View file

@ -235,11 +235,11 @@ def add_socket_markers(chassis_objects, modules, collection):
cargo_center = center_of([gruz]) if gruz else rear_center
broom_center = center_of([broom]) if broom else Vector((chassis_center.x, chassis_center.y, min_v.z + 0.35))
add_socket_empty("Socket_FrontBlade", Vector((min_v.x - 0.25, 0, min_v.z + 0.65)), collection)
add_socket_empty("Socket_FrontBlade", Vector((max_v.x + 0.25, 0, min_v.z + 0.65)), collection)
add_socket_empty("Socket_RearModule", rear_center, collection)
add_socket_empty("Socket_Cargo", cargo_center, collection)
add_socket_empty("Socket_Broom", broom_center, collection)
add_socket_empty("Socket_Hitch", Vector((max_v.x + 0.2, 0, min_v.z + 0.75)), collection)
add_socket_empty("Socket_Hitch", Vector((min_v.x - 0.2, 0, min_v.z + 0.75)), collection)
def summarize(objects, wheel_bones):

BIN
VehicleExports/SK_Kamaz_Chassis.fbx (Stored with Git LFS)

Binary file not shown.

BIN
VehicleExports/SM_Kamaz_Broom.fbx (Stored with Git LFS)

Binary file not shown.

BIN
VehicleExports/SM_Kamaz_Gruz.fbx (Stored with Git LFS)

Binary file not shown.

BIN
VehicleExports/SM_Kamaz_Kuzov.fbx (Stored with Git LFS)

Binary file not shown.

BIN
VehicleExports/SM_Kraz_BladeBucket.fbx (Stored with Git LFS)

Binary file not shown.

BIN
VehicleExports/SM_Kraz_BodyForBulk.fbx (Stored with Git LFS)

Binary file not shown.

View file

@ -0,0 +1,187 @@
{
"sourceFiles": {
"kamazClean": "C:\\Users\\post\\Documents\\mrPlow\\in\\kamaz_65115_clean.blend",
"kraz": "C:\\Users\\post\\Documents\\mrPlow\\in\\kraz_6322 .blend",
"verifyBlend": "C:\\Users\\post\\Documents\\mrPlow\\in\\mrplow_modular_assembly_verify.blend"
},
"axisConvention": {
"x": "forward",
"y": "right",
"z": "up",
"sourceUnits": "meters",
"unrealUnits": "centimeters"
},
"verificationCollections": [
"MrPlow_Chassis",
"MrPlow_Modules",
"MrPlow_Rig",
"Verify_02_KAMAZ_With_KRAZ_Modules",
"Verify_03_Module_Parking",
"Verify_Labels"
],
"kamazModules": [
{
"name": "KUZOV",
"type": "MESH",
"locationM": [
-3.4906,
0.0,
1.2474
],
"boundsMinM": [
-4.7618,
-1.3031,
1.1767
],
"boundsMaxM": [
1.5685,
1.3031,
2.9522
],
"sizeCm": {
"x": 633.03,
"y": 260.62,
"z": 177.55
},
"nonUnitScale": false,
"negativeScale": false
},
{
"name": "GRUZ",
"type": "MESH",
"locationM": [
-1.8611,
-0.0007,
2.2818
],
"boundsMinM": [
-4.4458,
-1.1559,
2.1823
],
"boundsMaxM": [
0.6498,
1.1545,
2.3859
],
"sizeCm": {
"x": 509.55,
"y": 231.04,
"z": 20.36
},
"nonUnitScale": false,
"negativeScale": false
},
{
"name": "broom",
"type": "MESH",
"locationM": [
-2.1234,
0.0,
0.2514
],
"boundsMinM": [
-3.8952,
-1.1416,
0.63
],
"boundsMaxM": [
-3.8048,
1.1621,
0.9406
],
"sizeCm": {
"x": 9.04,
"y": 230.37,
"z": 31.06
},
"nonUnitScale": false,
"negativeScale": false
}
],
"krazModulesPlacedOnKamaz": [
{
"name": "KRAZ_body for bulk",
"type": "MESH",
"locationM": [
-1.5932,
5.0,
2.4404
],
"boundsMinM": [
-4.419,
3.8139,
1.1767
],
"boundsMaxM": [
1.2257,
6.1861,
3.7037
],
"sizeCm": {
"x": 564.47,
"y": 237.22,
"z": 252.7
},
"nonUnitScale": false,
"negativeScale": false
},
{
"name": "KRAZ_blade bucket",
"type": "MESH",
"locationM": [
4.509,
5.0,
0.7053
],
"boundsMinM": [
3.6118,
3.0193,
0.0494
],
"boundsMaxM": [
5.4063,
6.9807,
1.3612
],
"sizeCm": {
"x": 179.45,
"y": 396.15,
"z": 131.18
},
"nonUnitScale": false,
"negativeScale": false
}
],
"variantChassisBounds": {
"name": "CABIN_VerifyKrazVariant",
"type": "MESH",
"locationM": [
2.3732,
5.0,
2.6343
],
"boundsMinM": [
1.6665,
3.7525,
0.4178
],
"boundsMaxM": [
3.3353,
6.2475,
2.8561
],
"sizeCm": {
"x": 166.88,
"y": 249.51,
"z": 243.83
},
"nonUnitScale": false,
"negativeScale": false
},
"notes": [
"KAMAZ default modules remain in the clean source file and are exported separately.",
"KRAZ modules are placed in a side-by-side fit variant, offset by +5m on Y.",
"Final Unreal import still uses separate FBX assets, not one combined mesh."
]
}