Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

PV1: the pick and the layer pass walk the drawn meshes through one function; the licence catalog follows meshopt

shinyobjectz551b2102bb86
diff --git a/LICENSES/float-cmp-0.10.0/LICENSE b/LICENSES/float-cmp-0.10.0/LICENSE
deleted file mode 100644
index e2e600a0..00000000
--- a/LICENSES/float-cmp-0.10.0/LICENSE
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2014-2020 Optimal Computing (NZ) Ltd
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-IN THE SOFTWARE.
diff --git a/LICENSES/meshopt-0.6.2/LICENSE.txt b/LICENSES/meshopt-0.6.2/LICENSE.txt
deleted file mode 100644
index 08256829..00000000
--- a/LICENSES/meshopt-0.6.2/LICENSE.txt
+++ /dev/null
@@ -1,20 +0,0 @@
-meshopt 0.6.2 ships no licence file of its own. Its Cargo.toml declares MIT OR Apache-2.0, by Graham Wihlidal <[email protected]>.
-
----- Apache-2.0: the text is LICENSES/texts/Apache-2.0.txt ----
-
----- MIT ----
-
-Copyright (c) Graham Wihlidal <[email protected]>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
-rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
-persons to whom the Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
-Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/NOTICE b/NOTICE
index 175eaa59..563505e1 100644
--- a/NOTICE
+++ b/NOTICE
@@ -197,7 +197,6 @@ LICENSES/<crate>-<version>/.
fixed 1.31.0: MIT/Apache-2.0
flagset 0.4.7: Apache-2.0
float_next_after 2.0.0: MIT
- float-cmp 0.10.0: MIT
float-ord 0.3.2: MIT / Apache-2.0
fs_extra 1.3.0: MIT
fsevent-sys 4.1.0: MIT
@@ -274,7 +273,6 @@ LICENSES/<crate>-<version>/.
louds-rs 0.7.0: MIT OR Apache-2.0
lz4_flex 0.13.1: MIT
memoffset 0.9.1: MIT
- meshopt 0.6.2: MIT OR Apache-2.0
metis-sys 0.3.2: MIT OR Apache-2.0
metis 0.2.2: MIT OR Apache-2.0
metrics-util 0.20.4: MIT
diff --git a/apps/media/src/lod.rs b/apps/media/src/lod.rs
index 23837529..62a748a6 100644
--- a/apps/media/src/lod.rs
+++ b/apps/media/src/lod.rs
@@ -55,7 +55,7 @@ fn write(path: &Path, doc: &Value, bin: &[u8]) -> R<()> {
}
fn n(v: &Value, k: &str) -> Option<usize> {
- v.get(k).and_then(Value::as_u64).map(|x| x as usize)
+ Some(v.get(k)?.as_u64()? as usize)
}
/// An accessor's bytes in the buffer: where they start, the step between elements, how many.
diff --git a/systems/frame/src/layer.rs b/systems/frame/src/layer.rs
index 5f0d1273..0755ff08 100644
--- a/systems/frame/src/layer.rs
+++ b/systems/frame/src/layer.rs
@@ -27,7 +27,27 @@ pub fn record(world: &mut World, f: i64) {
let clip_from_world = cam.clip_from_view() * Mat4::from(at.affine().inverse());
let mut layers: Vec<raea_sys_layers::Layer> = Vec::new();
let mut tris: Vec<raea_sys_layers::Tri> = Vec::new();
+ drawn(world, |world, e, posed, corners| {
+ let clip: Vec<[f32; 4]> = posed.iter().map(|p| (clip_from_world * p.extend(1.0)).to_array()).collect();
+ let v = keyed(world, e).map_or(0, |(key, name)| match layers.iter().position(|l| l.key == key) {
+ Some(i) => i as u16 + 1,
+ None => {
+ layers.push(raea_sys_layers::Layer::of(key, "mesh", name, None, None));
+ layers.len() as u16
+ }
+ });
+ tris.extend(corners.chunks_exact(3).filter_map(|t| Some(([*clip.get(t[0])?, *clip.get(t[1])?, *clip.get(t[2])?], v))));
+ });
+ let mask = raea_sys_layers::raster((size.x, size.y), tris);
+ raea_sys_layers::with(|r| r.frame_3d(f, size.x, &mask, &layers));
+}
+
+/// Every shown triangle-list mesh as the frame draws it, handed to `each`: its entity, its vertices in the world (a
+/// skinned mesh's as its joints pose them) and its triangles' corners. What the layer pass rasters and a pick's ray
+/// is cast against (pick.rs), so both see the same geometry.
+pub(crate) fn drawn(world: &mut World, mut each: impl FnMut(&World, Entity, Vec<Vec3>, Vec<usize>)) {
let mut parts = world.query::<(Entity, &Mesh3d, &GlobalTransform, Option<&InheritedVisibility>, Option<&bevy::mesh::skinning::SkinnedMesh>)>();
+ let world: &World = world;
let (meshes, binds) = (world.resource::<Assets<Mesh>>(), world.resource::<Assets<bevy::mesh::skinning::SkinnedMeshInverseBindposes>>());
for (e, m, place, shown, skin) in parts.iter(world) {
if shown.is_some_and(|s| !s.get()) {
@@ -37,26 +57,16 @@ pub fn record(world: &mut World, f: i64) {
let Ok(Some(bevy::mesh::VertexAttributeValues::Float32x3(pos))) = mesh.try_attribute_option(Mesh::ATTRIBUTE_POSITION) else { continue };
let joints = skin.and_then(|s| Some((s, binds.get(&s.inverse_bindposes)?))).map(|(s, b)| s.joints.iter().zip(b.iter()).map(|(j, ib)| world.get::<GlobalTransform>(*j).map_or(Mat4::IDENTITY, |g| Mat4::from(g.affine()) * *ib)).collect::<Vec<_>>());
let posed = posed(mesh, pos, joints.as_deref(), Mat4::from(place.affine()));
- let clip: Vec<[f32; 4]> = posed.iter().map(|p| (clip_from_world * p.extend(1.0)).to_array()).collect();
- let v = keyed(world, e).map_or(0, |(key, name)| match layers.iter().position(|l| l.key == key) {
- Some(i) => i as u16 + 1,
- None => {
- layers.push(raea_sys_layers::Layer::of(key, "mesh", name, None, None));
- layers.len() as u16
- }
- });
let corners: Vec<usize> = match mesh.try_indices_option() {
Ok(Some(ix)) => ix.iter().collect(),
- _ => (0..clip.len()).collect(),
+ _ => (0..posed.len()).collect(),
};
- tris.extend(corners.chunks_exact(3).filter_map(|t| Some(([*clip.get(t[0])?, *clip.get(t[1])?, *clip.get(t[2])?], v))));
+ each(world, e, posed, corners);
}
- let mask = raea_sys_layers::raster((size.x, size.y), tris);
- raea_sys_layers::with(|r| r.frame_3d(f, size.x, &mask, &layers));
}
/// A mesh's vertices in the world: posed by its joints' matrices (a skin's, in place of its transform) or `place`.
-pub(crate) fn posed(mesh: &Mesh, pos: &[[f32; 3]], joints: Option<&[Mat4]>, place: Mat4) -> Vec<Vec3> {
+fn posed(mesh: &Mesh, pos: &[[f32; 3]], joints: Option<&[Mat4]>, place: Mat4) -> Vec<Vec3> {
use bevy::mesh::VertexAttributeValues as A;
let joints = joints.filter(|_| !raea_sys_layers::mutant("bind"));
let skin = joints.zip(mesh.try_attribute_option(Mesh::ATTRIBUTE_JOINT_INDEX).ok().flatten()).zip(mesh.try_attribute_option(Mesh::ATTRIBUTE_JOINT_WEIGHT).ok().flatten());
diff --git a/systems/frame/src/pick.rs b/systems/frame/src/pick.rs
index cc9fe1cc..5f23d446 100644
--- a/systems/frame/src/pick.rs
+++ b/systems/frame/src/pick.rs
@@ -5,7 +5,7 @@
use bevy::prelude::*;
-use crate::layer::{LayerKey, posed};
+use crate::layer::{LayerKey, drawn};
/// A part hit: its key when it or a parent is stamped, its name, where the ray met it and how far along, and the box
/// on the frame (x, y, w, h in 0..1) of every mesh of that part.
@@ -30,19 +30,10 @@ pub fn part_at(world: &mut World, nx: f32, ny: f32) -> Option<PartHit> {
return None;
}
let clip_from_world = cam.clip_from_view() * Mat4::from(at.affine().inverse());
- let mut parts = world.query::<(Entity, &Mesh3d, &GlobalTransform, Option<&InheritedVisibility>, Option<&bevy::mesh::skinning::SkinnedMesh>)>();
- let (meshes, binds) = (world.resource::<Assets<Mesh>>(), world.resource::<Assets<bevy::mesh::skinning::SkinnedMeshInverseBindposes>>());
// each mesh drawn: the part it belongs to and its box on the frame, and the nearest hit among them
- let mut drawn: Vec<(Entity, [f32; 4])> = Vec::new();
+ let mut found: Vec<(Entity, [f32; 4])> = Vec::new();
let mut best: Option<(f32, Vec3, Entity)> = None;
- for (e, m, place, shown, skin) in parts.iter(world) {
- if shown.is_some_and(|s| !s.get()) {
- continue;
- }
- let Some(mesh) = meshes.get(&m.0).filter(|m| m.primitive_topology() == bevy::mesh::PrimitiveTopology::TriangleList) else { continue };
- let Ok(Some(bevy::mesh::VertexAttributeValues::Float32x3(pos))) = mesh.try_attribute_option(Mesh::ATTRIBUTE_POSITION) else { continue };
- let joints = skin.and_then(|s| Some((s, binds.get(&s.inverse_bindposes)?))).map(|(s, b)| s.joints.iter().zip(b.iter()).map(|(j, ib)| world.get::<GlobalTransform>(*j).map_or(Mat4::IDENTITY, |g| Mat4::from(g.affine()) * *ib)).collect::<Vec<_>>());
- let posed = posed(mesh, pos, joints.as_deref(), Mat4::from(place.affine()));
+ drawn(world, |world, e, posed, corners| {
let root = root_of(world, e);
let (mut lo, mut hi) = (Vec2::splat(f32::MAX), Vec2::splat(f32::MIN));
for p in &posed {
@@ -53,12 +44,8 @@ pub fn part_at(world: &mut World, nx: f32, ny: f32) -> Option<PartHit> {
}
}
if lo.x <= hi.x {
- drawn.push((root, [lo.x, lo.y, hi.x, hi.y]));
+ found.push((root, [lo.x, lo.y, hi.x, hi.y]));
}
- let corners: Vec<usize> = match mesh.try_indices_option() {
- Ok(Some(ix)) => ix.iter().collect(),
- _ => (0..posed.len()).collect(),
- };
for t in corners.chunks_exact(3) {
let (Some(p0), Some(p1), Some(p2)) = (posed.get(t[0]), posed.get(t[1]), posed.get(t[2])) else { continue };
if let Some(d) = ray_tri(near, dir, *p0, *p1, *p2) {
@@ -67,9 +54,9 @@ pub fn part_at(world: &mut World, nx: f32, ny: f32) -> Option<PartHit> {
}
}
}
- }
+ });
let (distance, point, root) = best?;
- let rect = drawn.iter().filter(|(r, _)| *r == root).fold([f32::MAX, f32::MAX, f32::MIN, f32::MIN], |a, (_, b)| [a[0].min(b[0]), a[1].min(b[1]), a[2].max(b[2]), a[3].max(b[3])]);
+ let rect = found.iter().filter(|(r, _)| *r == root).fold([f32::MAX, f32::MAX, f32::MIN, f32::MIN], |a, (_, b)| [a[0].min(b[0]), a[1].min(b[1]), a[2].max(b[2]), a[3].max(b[3])]);
let (x0, y0, x1, y1) = (rect[0].clamp(0.0, 1.0), rect[1].clamp(0.0, 1.0), rect[2].clamp(0.0, 1.0), rect[3].clamp(0.0, 1.0));
Some(PartHit {
key: world.get::<LayerKey>(root).map(|k| k.0.clone()),