makepad/libs/mesh_edit/tests/orientation.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

65 lines
3.3 KiB
Rust

use makepad_mesh_edit::*;
#[test]
fn flipping_shell_changes_inside_outside_and_preserves_every_attribute() {
let mut mesh = Mesh::cube([2.; 3], &mut Context::default()).unwrap();
let faces = mesh.faces().iter().map(|f|f.id).collect::<Vec<_>>();
let corner = mesh.corners()[0].id;
let vertex = mesh.vertices()[0].id;
let edge = *mesh.adjacency(&mut Context::default()).unwrap().edges.keys().next().unwrap();
mesh.set_vertex_weights(vertex, &[JointWeight {joint: 2, weight: 1.}], &mut Context::default()).unwrap();
mesh.set_face_material(faces[0], 7, &mut Context::default()).unwrap();
mesh.set_corner_uv(corner, [0.2, 0.7], &mut Context::default()).unwrap();
mesh.pin_uv(&[corner], true, &mut Context::default()).unwrap();
mesh.set_edge_attributes(edge, EdgeAttributes {seam: true, crease: 0.8}, &mut Context::default()).unwrap();
mesh.recalculate_normals(false, 0., &mut Context::default()).unwrap();
let original = mesh.clone();
assert!(mesh.validate_global(&mut Context::default()).unwrap().is_valid_solid);
let changes = mesh.flip_faces(&faces, &mut Context::default()).unwrap();
assert!(changes.created.is_empty() && changes.deleted.is_empty());
assert_eq!(mesh.vertices(), original.vertices());
assert_eq!(mesh.faces(), original.faces());
assert_eq!(mesh.edge_attributes(), original.edge_attributes());
assert_eq!(mesh.uv_pins(), original.uv_pins());
for old in original.corners() {
let new = mesh.corner(old.id).unwrap();
assert_eq!((new.vertex,new.uv), (old.vertex,old.uv));
assert_eq!(new.normal, old.normal.map(|v|v.map(|x|-x)));
}
let report = mesh.validate_global(&mut Context::default()).unwrap();
assert!(report.is_embedded_surface);
assert_eq!(report.orientation_errors, 1);
assert!(!report.is_valid_solid);
let bytes = mesh.to_bytes(&mut Context::default()).unwrap();
mesh = Mesh::from_bytes(&bytes, &mut Context::default()).unwrap();
mesh.flip_faces(&faces, &mut Context::default()).unwrap();
assert_eq!(mesh, original);
}
#[test]
fn invalid_selections_budget_and_cancellation_leave_winding_unchanged() {
let mut mesh = Mesh::cube([1.; 3], &mut Context::default()).unwrap();
let original = mesh.clone();
let face = mesh.faces()[0].id;
for ids in [vec![face,face],vec![FaceId(u64::MAX)]] {
assert!(mesh.flip_faces(&ids, &mut Context::default()).is_err());
assert_eq!(mesh, original);
}
let mut budget = Limits::default();
budget.max_work = 2;
assert!(mesh.flip_faces(&[face], &mut Context::new(budget,None)).is_err());
assert_eq!(mesh, original);
assert_eq!(mesh.flip_faces(&[face], &mut Context::new(Limits::default(),Some(&||true))).unwrap_err(), MeshError::Cancelled);
assert_eq!(mesh, original);
}
#[test]
fn flipping_an_open_pane_changes_its_visible_side_without_inventing_a_solid() {
let mut mesh = Mesh::plane([2.,3.], &mut Context::default()).unwrap();
let faces = mesh.faces().iter().map(|f|f.id).collect::<Vec<_>>();
let before = mesh.triangulate(&mut Context::default()).unwrap();
mesh.flip_faces(&faces, &mut Context::default()).unwrap();
let after = mesh.triangulate(&mut Context::default()).unwrap();
assert_eq!(before.vertices[0].normal.map(|v|-v),after.vertices[0].normal);
assert!(!mesh.validate(&mut Context::default()).unwrap().is_closed);
}