3D model viewer: STL and OBJ
git clone https://git.lucas.co/cce-model.git
Background quad is a screen_space draw (cce-ui 38bcad1)
cce-ui replaced its z = 9.99 vertex sentinel with SceneDraw::screen_space,
and the repin to 38bcad1 left this crate not building. The gradient's
corners now sit at z 0 in a draw that says it is screen-space; fit_to_unit
stays, for the camera only.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/main.rs | 9 +++++----
src/mesh.rs | 9 ++++-----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 22988fe..8dd3557 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -193,6 +193,7 @@ fn draw(mesh: MeshId, mvp: [[f32; 4]; 4]) -> SceneDraw {
prelit: false,
see_through: false,
instances: None,
+ screen_space: false,
}
}
@@ -279,9 +280,9 @@ impl Application for ModelApp {
/// Once per renderer, the first and any replacement after a reconnect:
/// a new renderer holds no meshes, so the model goes up again.
fn init_3d(&mut self, stage: &mut dyn Stage3D) {
- let bg = |x: f32, y: f32, color: [f32; 3]| Vertex3D { position: [x, y, 9.99], color };
- // z = 9.99 is the scene pass's screen-space sentinel: these corners
- // are NDC, drawn behind everything, untouched by the mvp.
+ // Drawn as a `screen_space` draw: these corners are NDC, at the far
+ // plane, untouched by the mvp; their z is ignored.
+ let bg = |x: f32, y: f32, color: [f32; 3]| Vertex3D { position: [x, y, 0.0], color };
let background = stage.create_mesh(&[
bg(-1.0, -1.0, SKY_BOTTOM),
bg(1.0, -1.0, SKY_BOTTOM),
@@ -313,7 +314,7 @@ impl Application for ModelApp {
}
let (pw, ph) = ((size.width as f64 * scale) as u32, (size.height as f64 * scale) as u32);
let mvp = self.camera.view_proj(pw as f32 / ph.max(1) as f32).to_cols_array_2d();
- let mut draws = vec![draw(gpu.background, mvp)];
+ let mut draws = vec![SceneDraw { screen_space: true, ..draw(gpu.background, mvp) }];
if let (Some(id), Some(_)) = (gpu.model, &self.model) {
draws.push(SceneDraw { prelit: true, ..draw(id, mvp) });
}
diff --git a/src/mesh.rs b/src/mesh.rs
index 2b751d1..e7f3b5f 100644
--- a/src/mesh.rs
+++ b/src/mesh.rs
@@ -67,11 +67,10 @@ impl Mesh {
/// sit 1.7 times farther out than any of its points, and framing those
/// left a framed sphere small in the window.
///
- /// Not only for a tidy camera: cce-ui's scene pass reads any vertex
- /// whose z is within 0.01 of 9.99 as a corner of the screen-space
- /// background quad (`scene3d.wgsl`), whatever mesh it is in. A model
- /// spanning z = 9.99 in its own units had a ring of its points flung
- /// across the screen. Inside a unit sphere no point comes near it.
+ /// The camera frames the unit sphere, so every model opens the same way
+ /// whatever its file's units. (It was also a workaround until cce-ui
+ /// 38bcad1, when any vertex near z = 9.99 was drawn as a corner of the
+ /// screen-space background; that is a per-draw flag now.)
pub fn fit_to_unit(&mut self) -> (Vec3, f32) {
let Some((lo, hi)) = self.bounds() else { return (Vec3::ZERO, 1.0) };
let centre = (lo + hi) / 2.0;