Single-object viewer POC (#14)

This commit implements a Sketchfab-style single-object viewer as a minimal
proof-of-concept.

### `@storyteller/studio-web`
This is a new package to house web components for interfacing with the
`@storyteller/studio` WASM library. It currently includes a single component,
`<sts-viewer />`, which is exported from `@storyteller/studio-web/viewer`.

### `react-frontend`
This is a new application intended as a proof-of-concept and testbed for React
interop with `@storyteller/studio-web`.

Web components are currently a little bit fiddly to use in a React application.
`react-frontend/src/app/studio-viewer.tsx` demonstrates how a React-idiomatic
component can be written as a thin wrapper around a web component, and
`react-frontend/src/app/app.tsx` demonstrates that wrapper component in use.
This commit is contained in:
Danny McGee
2023-12-07 15:46:32 -05:00
committed by GitHub
parent 155272a5ba
commit cba70a62ae
70 changed files with 71793 additions and 1157 deletions
+50 -1
View File
@@ -1,7 +1,7 @@
use bevy::{
math::vec3,
prelude::*,
render::{mesh::Indices, render_resource::PrimitiveTopology},
render::{mesh::Indices, primitives::Aabb, render_resource::PrimitiveTopology},
};
pub struct Cone {
@@ -111,3 +111,52 @@ impl From<Plane2Sided> for Mesh {
mesh
}
}
pub trait Extrema {
type Output: Sized;
fn extrema(&self) -> Self::Output;
}
impl Extrema for Aabb {
type Output = [Vec3; 8];
fn extrema(&self) -> Self::Output {
let min = Vec3::from(self.min());
let max = Vec3::from(self.max());
[
min,
vec3(min.x, min.y, max.z),
vec3(min.x, max.y, min.z),
vec3(max.x, min.y, min.z),
vec3(min.x, max.y, max.z),
vec3(max.x, min.y, max.z),
vec3(max.x, max.y, min.z),
max,
]
}
}
pub trait Combinable {
type IterItem<'a>;
type Output;
fn combine<'a>(elements: impl Iterator<Item = Self::IterItem<'a>>) -> Self::Output;
}
impl Combinable for Aabb {
type IterItem<'a> = (&'a Self, &'a GlobalTransform);
type Output = Option<Self>;
fn combine<'a>(elements: impl Iterator<Item = Self::IterItem<'a>>) -> Self::Output {
let points = elements.flat_map(|(aabb, world_xform)| {
let min = world_xform.transform_point(aabb.min().into());
let max = world_xform.transform_point(aabb.max().into());
[min, max]
});
Aabb::enclosing(points)
}
}