makepad/libs/model/examples/polish_headlights.rs
Admin d2130e6550 libs: model, mesh_edit, csg, scene, sim, render, xr
Squash of 25 work commits (Sep 1–12):
  237da90  render: the sprite lane hands the screen draw back the way it found it
  895b9a7  particles: an emitter can ride a body's own frame
  914471f  ai-hub: a feed session whose last socket left ends on its idle timeout; skin: parent, skinned centroid and a nodes-only rig for retargets
  3fcccf3  sim: the whole world is implicitly editable, and one seam says where the ground is
  5692fab  sim: the landform world proves itself — walker through the tunnel included
  f4af6df  sim: terrain knows who changed it — a plan layer over player history
  adbb078  render: a water volume can be physics without a picture
  c17480f  render: a non-rigid body may carry its own orientation
  acad401  sim: an agent with no route holds and retries instead of walking into the wall
  22b2bf9  sim + chat: the composed world surface takes a map floor; the chat gets plan tools
  faf8112  web path: the tessellator's lap timer, the trace span and the fusion cycle timer have no clock on the web
  d3472eb  tsdf: the clock-taking XR helpers are native-only — the browser has no depth camera and no Instant
  4946c9e  sim + render: a repaint is not a world edit — colour and glow restyles never rebake the lightmap
  4317f58  sim + render + chat: walk decks as a surface, the filmed body is no obstruction, the brief never asks
  9791279  render: support rigged models and custom materials across viewers
  3ce2792  sim: use deck geometry for collision and sensing
  c8b79ff  Add portable PBR, rig and soft-body authoring support
  108d423  Add transactional polygon modeling and editable asset documents
  38f4d3b  Refine editable modeling and firm yarn character behavior
  08a2637  sim: add entity-owned lights and vehicle headlights
  00d96a7  render: add clustered lights, local shadows and incremental GI
  cf916af  render: import glTF asset extensions and wire clustered GI
  c6d2cca  model: cut transaction memory and raise capacity limits
  41af47a  raytrace: add a CPU probe-ray BVH budget example
  c963d0a  libs: the game sim splits into makepad-scene and makepad-soft-body; render, model, fab and the asset importer retarget

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-15 13:40:31 +02:00

30 lines
2.9 KiB
Rust

//! Source-preserving material/normal revision for the authored workshop car.
//! No beam/steering/collider or vertex positions are changed.
use makepad_model::*;
fn main()->std::result::Result<(),Box<dyn std::error::Error>>{
let args=std::env::args().skip(1).collect::<Vec<_>>();
if args.len()!=2{return Err("usage: polish_headlights <source.mpmodel> <output.mpmodel>".into());}
let mut doc=Document::from_bytes(&std::fs::read(&args[0])?,Limits{max_joints:128,..Default::default()},None)?;
let before=doc.head();let scene=doc.scene().clone();
let before_positions=doc.objects().map(|(name,m)|(name.to_string(),m.vertices().iter().map(|v|(v.id,v.position)).collect::<Vec<_>>())).collect::<Vec<_>>();
let lens=doc.object("headlamp-lens").ok_or("expected headlamp-lens source object")?;
let faces=lens.faces().iter().map(|f|f.id).collect();
let material=doc.materials().keys().copied().max().unwrap_or(0)+1;
let mut operations=vec![Operation::SetMaterial{material,value:Material{color:[1.,0.88,0.68],base_color_png:Vec::new()}},
Operation::Surface(SurfaceOperation::Material{material,value:SurfaceMaterial{base_color:[1.,0.91,0.76,1.],metallic:0.,roughness:0.14,
emissive:[1.,0.80,0.52],emissive_strength:3.5,..Default::default()}}),
Operation::AssignMaterial{object:"headlamp-lens".into(),faces,material}];
let curved=doc.objects().filter(|(name,_)|name.starts_with("headlamp")||*name=="hubcap"||name.contains("fender")||name.contains("tire")).map(|(name,_)|name.to_string()).collect::<Vec<_>>();
for name in &curved {
let args=json::obj(vec![("op",json::s("normals")),("object",json::s(name)),("smooth",json::Value::Bool(true)),("angle",json::Value::F64(1.2))]);
operations.extend(parse_operations(&json::Value::Arr(vec![args]),doc.limits())?);
}
doc.apply(Transaction{request_id:"warm-luminous-headlamp-lenses".into(),expected:before,operations},None)?;
assert_eq!(doc.scene(),&scene,"beam lights, wheel contracts and placement must stay identical");
for(name,vertices)in before_positions{assert_eq!(vertices,doc.object(&name).unwrap().vertices().iter().map(|v|(v.id,v.position)).collect::<Vec<_>>());}
let checks=doc.publication_checks(None)?;if checks.get("valid")!=Some(&json::Value::Bool(true)){return Err(checks.to_json().into());}
let compiled=doc.compile(None)?;let source=doc.to_snapshot_bytes(None)?;
std::fs::write(&args[1],&source)?;
let output=std::path::Path::new(&args[1]);std::fs::write(output.with_extension("glb"),&compiled.glb)?;
println!("{}",json::obj(vec![("head",head_json(doc.head())),("lens_material",json::Value::Int(material as i64)),("emissive_strength",json::Value::F64(3.5)),("smoothed",json::Value::Arr(curved.into_iter().map(json::s).collect())),("triangles",json::Value::Int(compiled.triangles as i64)),("vertices_unchanged",json::Value::Bool(true)),("lights_wheels_scene_unchanged",json::Value::Bool(true))]).to_json());Ok(())
}