feat(playcanvas): share dockable scene tools and persistent model editing

This commit is contained in:
DCCONSTRUCTIONS
2026-11-04 00:42:59 +03:00
parent 038337783f
commit 2f0a066dde
40 changed files with 3238 additions and 126 deletions
+34
View File
@@ -0,0 +1,34 @@
DCD-006 v022 — PlayCanvas visual assembly
Source: DCD-006_rover_v022_CAM_R09_K1_C22_REVIEW.blend
SHA-256: 4fae2c9928b3254475d01929f042d1604af3fbc196bb93ad39543384f15d8a86
Approved for PlayCanvas integration by the owner on 2026-10-31.
From the canonical Mission Core repository root:
/Applications/Blender.app/Contents/MacOS/Blender --background --disable-autoexec <source.blend> --python tools/rover-scene/export_rover.py -- --revision v022 --equipment-collection '04 ОБОРУДОВАНИЕ • актуальная сборка'
Outputs:
- apps/control-station/public/rover-scene/dcd006-v022.glb
- apps/control-station/public/rover-scene/dcd006-v022.json
- apps/control-station/src/core/roverScene/equipmentMaterials.json
The export evaluates the source geometry, keeps 1281 visible geometry instances,
and batches them into 40 editable material meshes (3,246,371 triangles).
It does not decimate geometry or save the source Blend. Review lights, cameras,
reference images, hidden Boolean tools and empty anchors are not rendered.
The nine existing chassis/case material groups preserve operator edits. The 31
equipment material groups retain authored PBR values except owner-approved finishes:
CAM MOLLE and K1 base/holder/cap match the matte black frame; X4 is dark polymer.
The previous v022 pale palette migrates once. CAD pieces whose shader
was untouched default gray use their authored Blender viewport color instead.
Legacy v020 scene documents and model selections migrate to v022; environment,
textures, custom materials and assignments remain. The historical IndexedDB
slot stays stable. The motion GLB and simulation/physics profiles stay v020.
The manifest includes all 16 original engineering world matrices in metres and
an explicit source-to-GLTF matrix for the viewer's centering and Y-up transform.
CAM remains at (0.173, 0.0065, 0.603940785) m; K1 follows the C22 CAD assembly.
These are mounting references, not calibrated camera or LiDAR extrinsics.
Insta360 X4 remains an envelope; its tripod/hinge and antenna placement are
approximate from IMG_2844. No commercial model was acquired.
+44
View File
@@ -0,0 +1,44 @@
"""Carry v022 equipment PBR and authored CAD viewport colors into editable groups."""
import hashlib
import re
import bpy
from materials import specs
PRINTED_MATERIALS={"V2 · base", "V2 · holder", "V2 · cap", "Graphite"}
DARK_PLASTIC_MATERIALS={"R01 | X4 габаритный макет"}
def equipment_material(source):
name = re.sub(r'\.\d{3}$', '', source.name)
key = 'equipment-' + hashlib.sha256(name.encode()).hexdigest()[:12]
node = source.node_tree.nodes.get('Principled BSDF') if source.use_nodes else None
color = list(node.inputs['Base Color'].default_value) if node else list(source.diffuse_color)
# Several manufacturing parts only set diffuse_color; their untouched node
# still has Blender's default 0.8 gray. Do not export those parts as white.
viewport = list(source.diffuse_color)
fallback = node is not None and all(abs(v - .8) < 1e-6 for v in color[:3]) and any(abs(v - .8) > 1e-6 for v in viewport[:3])
if fallback:
color = viewport
metal = float(source.metallic if fallback or node is None else node.inputs['Metallic'].default_value)
rough = float(source.roughness if fallback or node is None else node.inputs['Roughness'].default_value)
color_source = 'viewport' if fallback else 'shader'
# Owner's physical finish: printed CAM/K1 parts match the frame; X4 is dark plastic.
finish = 'body' if name in PRINTED_MATERIALS else 'polymer' if name in DARK_PLASTIC_MATERIALS else None
if finish:
_, rgb, metal, rough = specs[finish]
color = [*rgb, 1]
color_source = 'owner/' + finish
material = bpy.data.materials.new('rover/' + key)
material.use_nodes = True
bs = material.node_tree.nodes.get('Principled BSDF')
bs.inputs['Base Color'].default_value = color
bs.inputs['Metallic'].default_value = metal
bs.inputs['Roughness'].default_value = rough
return key, (name, tuple(color[:3]), metal, rough), material, color_source
def srgb_hex(color):
def channel(c):
v = 12.92 * c if c <= .0031308 else 1.055 * c ** (1 / 2.4) - .055
return round(max(0, min(1, v)) * 255)
return '#' + ''.join(f'{channel(c):02x}' for c in color)
+35 -7
View File
@@ -1,5 +1,9 @@
"""Evaluated v020 geometry, semantic PBR groups and UVs; never saves the source."""
import bpy, json, hashlib
"""Evaluated geometry and editable PBR groups; never saves the source.
Blender -b <source.blend> --python tools/rover-scene/export_rover.py -- \
--revision v022 --equipment-collection "04 ОБОРУДОВАНИЕ • актуальная сборка"
"""
import bpy, json, hashlib, argparse
from collections import defaultdict
from pathlib import Path
from mathutils import Vector, Matrix
@@ -7,6 +11,16 @@ root=Path.cwd();source=Path(bpy.data.filepath)
import sys
sys.path.insert(0,str(Path(__file__).resolve().parent))
from materials import specs, materials, classify
from equipment_materials import equipment_material, srgb_hex
parser=argparse.ArgumentParser()
parser.add_argument('--revision',default='v020')
parser.add_argument('--equipment-collection')
args=parser.parse_args(sys.argv[sys.argv.index('--')+1:] if '--' in sys.argv else [])
if args.revision not in {'v020','v022'}:parser.error('Unsupported rover revision')
equipment=set(bpy.data.collections[args.equipment_collection].all_objects) if args.equipment_collection else set()
bpy.context.view_layer.update()
equipment_cache={};color_sources={};frames={o.name:[list(row) for row in o.matrix_world] for o in bpy.context.scene.objects if o.name.startswith('FRAME_') and o.type=='EMPTY'}
bpy.context.scene.frame_set(1);dg=bpy.context.evaluated_depsgraph_get();instances=[];assignment=defaultdict(set)
for inst in dg.object_instances:
@@ -16,7 +30,14 @@ for inst in dg.object_instances:
if not inst.is_instance and not src.visible_get():continue
mesh=bpy.data.meshes.new_from_object(o,preserve_all_data_layers=True,depsgraph=dg)
for idx in range(len(mesh.materials)):
name=mesh.materials[idx].name if mesh.materials[idx] else '';key=classify(name,src.name)
source_material=mesh.materials[idx]
name=source_material.name if source_material else ''
if src in equipment and source_material:
if name not in equipment_cache:
key,spec,mat,color_source=equipment_material(source_material)
equipment_cache[name]=key;specs[key]=spec;materials[key]=mat;color_sources[key]=color_source
key=equipment_cache[name]
else:key=classify(name,src.name)
mesh.materials[idx]=materials[key];assignment[key].add(src.name)
if not mesh.materials:mesh.materials.append(materials['body']);assignment['body'].add(src.name)
instances.append((src.name,mesh,inst.matrix_world.copy()))
@@ -30,7 +51,7 @@ shift=Vector((-(lo.x+hi.x)/2,-(lo.y+hi.y)/2,-lo.z))
for o in objects:o.matrix_world=Matrix.Translation(shift)@o.matrix_world
count=len(objects)
bpy.ops.object.select_all(action='SELECT');bpy.context.view_layer.objects.active=objects[0];bpy.ops.object.join()
# Separate by material keeps picking exact while avoiding 1,426 draw calls.
# Batch by material to keep exact surface picking with a bounded draw-call count.
bpy.ops.object.mode_set(mode='EDIT');bpy.ops.mesh.select_all(action='SELECT');bpy.ops.mesh.separate(type='MATERIAL');bpy.ops.object.mode_set(mode='OBJECT')
for o in list(scene.objects):
bpy.ops.object.select_all(action='DESELECT');o.select_set(True);bpy.context.view_layer.objects.active=o
@@ -38,8 +59,15 @@ for o in list(scene.objects):
for uv in list(o.data.uv_layers):o.data.uv_layers.remove(uv)
bpy.ops.object.mode_set(mode='EDIT');bpy.ops.mesh.select_all(action='SELECT');bpy.ops.uv.cube_project(cube_size=.2);bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='SELECT')
out=root/'apps/control-station/public/rover-scene/dcd006-v020.glb'
out=root/f'apps/control-station/public/rover-scene/dcd006-{args.revision}.glb'
bpy.ops.export_scene.gltf(filepath=str(out),export_format='GLB',use_selection=True,use_active_scene=True,export_animations=False,export_cameras=False,export_lights=False,export_extras=False,export_yup=True,export_apply=False,export_texcoords=True,export_attributes=False,export_vertex_color='NONE')
manifest={'source':source.name,'source_sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'model':'DCD-006 v020 complete rover','revision':'materials-v2','source_object_count':count,'render_mesh_count':len(scene.objects),'original_bounds':[list(lo),list(hi)],'dimensions_m':list(hi-lo),'translation_m':list(shift),'glb_bytes':out.stat().st_size,'glb_sha256':hashlib.sha256(out.read_bytes()).hexdigest(),'source_saved':False,'uv':'cube projection, 0.2 m','materials':{k:{'name':v[0],'baseColorLinear':v[1],'metalness':v[2],'roughness':v[3],'sourceObjects':sorted(assignment[k])} for k,v in specs.items()}}
(out.parent/'dcd006-v020.json').write_text(json.dumps(manifest,ensure_ascii=False,indent=2)+'\n')
manifest={'source':source.name,'source_sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'model':f'DCD-006 {args.revision} complete rover','revision':'materials-v2' if args.revision=='v022' else 'materials-v2','source_object_count':count,'render_mesh_count':len(scene.objects),'original_bounds':[list(lo),list(hi)],'dimensions_m':list(hi-lo),'translation_m':list(shift),'glb_bytes':out.stat().st_size,'glb_sha256':hashlib.sha256(out.read_bytes()).hexdigest(),'source_saved':False,'uv':'cube projection, 0.2 m','materials':{k:{'name':v[0],'baseColorLinear':v[1],'metalness':v[2],'roughness':v[3],'sourceObjects':sorted(assignment[k])} for k,v in specs.items()}}
# Source anchors remain in engineering coordinates. The explicit transform maps
# each original Blender point to the centered Y-up GLB without losing placement.
manifest['mount_frames']={'units':'metres','source_axes':'+X forward, +Z up','source_world_matrices':frames,'source_to_gltf_matrix':[[1,0,0,shift.x],[0,0,1,shift.z],[0,-1,0,-shift.y],[0,0,0,1]]}
manifest['equipment_color_sources']=color_sources
if equipment:
equipment_defaults={key:{'name':specs[key][0],'color':srgb_hex(specs[key][1]),'metalness':specs[key][2],'roughness':specs[key][3],'finish':color_sources[key].removeprefix('owner/') if color_sources[key].startswith('owner/') else ''} for key in sorted(color_sources)}
(root/'apps/control-station/src/core/roverScene/equipmentMaterials.json').write_text(json.dumps(equipment_defaults,ensure_ascii=False,indent=2)+'\n')
(out.with_suffix('.json')).write_text(json.dumps(manifest,ensure_ascii=False,indent=2)+'\n')
print('ROVER EXPORT',out.stat().st_size,'bytes;',len(scene.objects),'material groups')