summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/resources.md83
-rw-r--r--shared/src/helper.rs42
-rw-r--r--shared/src/resources.rs25
-rw-r--r--world/src/main.rs1
-rw-r--r--world/src/mesh.rs22
5 files changed, 137 insertions, 36 deletions
diff --git a/doc/resources.md b/doc/resources.md
index afb6bb8..9a38215 100644
--- a/doc/resources.md
+++ b/doc/resources.md
@@ -33,42 +33,45 @@ array. ombinations of g_\*, va_\* and tex_\* are multiplied except normal which
is added. Defaults should be the identity for that operation, so default is 1 /
white except normals are zero.
-| Key | Value Type | |
-| -------------------- | -------------- | ------------------ |
-| `name` | `String` | |
-| `index` | `Res` | |
-| `g_metallic` | `Float` | |
-| `g_roughness` | `Float` | |
-| `g_albedo` | `Vec3` | |
-| `g_alpha` | `Float` | |
-| `g_transmission` | `Float` | |
-| `g_emission` | `Vec3` | |
-| `g_refractive_index` | `Float` | |
-| `g_attenuation` | `Vec3` | |
-| `g_dispersion` | `Float` | |
-| `g_thickness` | `Float` | |
-| `g_unlit` | | |
-| `g_double_sided` | | |
-| `va_position` | `Res<[Vec3]>` | |
-| `va_normal` | `Res<[Vec3]>` | |
-| `va_tangent` | `Res<[Vec3]>` | |
-| `va_texcoord` | `Res<[Vec2]>` | |
-| `va_roughness` | `Res<[Float]>` | |
-| `va_metallic` | `Res<[Float]>` | |
-| `va_albedo` | `Res<[Vec3]>` | |
-| `va_alpha` | `Res<[Float]>` | |
-| `va_transmission` | `Res<[Float]>` | |
-| `va_emission` | `Res<[Vec3]>` | |
-| `tex_normal` | `Res<Texture>` | Use color channels |
-| `tex_roughness` | `Res<Texture>` | Use green channel |
-| `tex_metallic` | `Res<Texture>` | Use blue channel |
-| `tex_albedo` | `Res<Texture>` | Use color channels |
-| `tex_alpha` | `Res<Texture>` | Use alpha channel |
-| `tex_transmission` | `Res<Texture>` | Use red channel |
-| `tex_emission` | `Res<Texture>` | Use color channels |
-| `tex_thickness` | `Res<Texture>` | Use green channel |
-| `tex_occlusion` | `Res<Texture>` | Use red channel |
-| `hint_mirror` | | |
+| Key | Value Type | |
+| -------------------- | ----------------- | ------------------ |
+| `name` | `String` | |
+| `index` | `Res<[u32; 3]>` | |
+| `armature` | `Res<Armature>` | |
+| `g_metallic` | `Float` | |
+| `g_roughness` | `Float` | |
+| `g_albedo` | `Vec3` | |
+| `g_alpha` | `Float` | |
+| `g_transmission` | `Float` | |
+| `g_emission` | `Vec3` | |
+| `g_refractive_index` | `Float` | |
+| `g_attenuation` | `Vec3` | |
+| `g_dispersion` | `Float` | |
+| `g_thickness` | `Float` | |
+| `g_unlit` | | |
+| `g_double_sided` | | |
+| `va_position` | `Res<[Vec3]>` | |
+| `va_normal` | `Res<[Vec3]>` | |
+| `va_tangent` | `Res<[Vec3]>` | |
+| `va_texcoord` | `Res<[Vec2]>` | |
+| `va_roughness` | `Res<[Float]>` | |
+| `va_metallic` | `Res<[Float]>` | |
+| `va_albedo` | `Res<[Vec3]>` | |
+| `va_alpha` | `Res<[Float]>` | |
+| `va_transmission` | `Res<[Float]>` | |
+| `va_emission` | `Res<[Vec3]>` | |
+| `va_joint_weight` | `Res<[[f32; 4]]>` | |
+| `va_joint_index` | `Res<[[u16; 4]]>` | |
+| `tex_normal` | `Res<Texture>` | Use color channels |
+| `tex_roughness` | `Res<Texture>` | Use green channel |
+| `tex_metallic` | `Res<Texture>` | Use blue channel |
+| `tex_albedo` | `Res<Texture>` | Use color channels |
+| `tex_alpha` | `Res<Texture>` | Use alpha channel |
+| `tex_transmission` | `Res<Texture>` | Use red channel |
+| `tex_emission` | `Res<Texture>` | Use color channels |
+| `tex_thickness` | `Res<Texture>` | Use green channel |
+| `tex_occlusion` | `Res<Texture>` | Use red channel |
+| `hint_mirror` | | |
- **Attenuation**: Attenuation coefficient for each color channel due to
scattering within the material volume expressed as e-folding distance (m^-1).
@@ -88,6 +91,14 @@ white except normals are zero.
properly e.g. show use a texture that shows output of another render pass from
the mirrors perspective. It can be assumed that the mesh is on a single plane.
+## Armature
+
+| Key | Value Type | |
+| ----------- | ------------------- | ------------------------------------ |
+| `parent` | `[u32]` | Parent indecies |
+| `transform` | `[(Matrix3, Vec3)]` | |
+| `names` | `[String]` | Each string prefixed with u16 length |
+
## LightPart
| Key | Value Type |
diff --git a/shared/src/helper.rs b/shared/src/helper.rs
index d46a830..723f91e 100644
--- a/shared/src/helper.rs
+++ b/shared/src/helper.rs
@@ -161,6 +161,48 @@ impl ReadWrite for Vec<[u32; 3]> {
.collect())
}
}
+impl ReadWrite for Vec<[u16; 4]> {
+ fn write(&self, w: &mut dyn Write) -> Result<()> {
+ for e in self {
+ w.write_all(&e[0].to_be_bytes())?;
+ w.write_all(&e[1].to_be_bytes())?;
+ w.write_all(&e[2].to_be_bytes())?;
+ w.write_all(&e[3].to_be_bytes())?;
+ }
+ Ok(())
+ }
+ fn read(r: &mut dyn Read) -> Result<Self> {
+ let mut buf = Vec::new();
+ r.read_to_end(&mut buf)?;
+ Ok(buf
+ .into_iter()
+ .array_chunks::<{ size_of::<u16>() }>()
+ .map(u16::from_be_bytes)
+ .array_chunks::<4>()
+ .collect())
+ }
+}
+impl ReadWrite for Vec<[f32; 4]> {
+ fn write(&self, w: &mut dyn Write) -> Result<()> {
+ for e in self {
+ w.write_all(&e[0].to_be_bytes())?;
+ w.write_all(&e[1].to_be_bytes())?;
+ w.write_all(&e[2].to_be_bytes())?;
+ w.write_all(&e[3].to_be_bytes())?;
+ }
+ Ok(())
+ }
+ fn read(r: &mut dyn Read) -> Result<Self> {
+ let mut buf = Vec::new();
+ r.read_to_end(&mut buf)?;
+ Ok(buf
+ .into_iter()
+ .array_chunks::<{ size_of::<f32>() }>()
+ .map(f32::from_be_bytes)
+ .array_chunks::<4>()
+ .collect())
+ }
+}
impl ReadWrite for Vec<f32> {
fn write(&self, w: &mut dyn Write) -> Result<()> {
for e in self {
diff --git a/shared/src/resources.rs b/shared/src/resources.rs
index 54a34b8..59d88b6 100644
--- a/shared/src/resources.rs
+++ b/shared/src/resources.rs
@@ -50,6 +50,7 @@ pub struct EnvironmentPart {
pub struct MeshPart {
pub name: Option<String>,
pub index: Option<Resource<Vec<[u32; 3]>>>,
+ pub armature: Option<Armature>,
pub g_metallic: Option<f32>,
pub g_roughness: Option<f32>,
pub g_albedo: Option<Vec3A>,
@@ -72,6 +73,8 @@ pub struct MeshPart {
pub va_transmission: Option<Resource<Vec<f32>>>,
pub va_alpha: Option<Resource<Vec<f32>>>,
pub va_emission: Option<Resource<Vec<Vec3A>>>,
+ pub va_joint_index: Option<Resource<Vec<[u16; 4]>>>,
+ pub va_joint_weight: Option<Resource<Vec<[f32; 4]>>>,
pub tex_normal: Option<Resource<Image<'static>>>,
pub tex_roughness: Option<Resource<Image<'static>>>,
pub tex_metallic: Option<Resource<Image<'static>>>,
@@ -81,6 +84,14 @@ pub struct MeshPart {
pub tex_emission: Option<Resource<Image<'static>>>,
pub tex_thickness: Option<Resource<Image<'static>>>,
pub tex_occlusion: Option<Resource<Image<'static>>>,
+ pub hint_mirror: Option<()>,
+}
+
+#[derive(Debug, Default, Clone)]
+pub struct Armature {
+ pub parent: Option<Vec<u32>>,
+ pub transform: Option<Vec<Affine3A>>,
+ pub name: Option<Vec<String>>,
}
#[derive(Debug, Default, Clone)]
@@ -122,6 +133,14 @@ impl ReadWrite for PrefabIndex {
}
}
+impl ReadWrite for Armature {
+ fn write(&self, w: &mut dyn Write) -> Result<()> {
+ todo!()
+ }
+ fn read(r: &mut dyn Read) -> Result<Self> {
+ todo!()
+ }
+}
impl ReadWrite for CollisionPart {
fn write(&self, w: &mut dyn Write) -> Result<()> {
write_kv_opt(w, b"restitution_coeff", &self.restitution_coeff)?;
@@ -249,6 +268,8 @@ impl ReadWrite for MeshPart {
write_kv_opt(w, b"va_transmission", &self.va_transmission)?;
write_kv_opt(w, b"va_alpha", &self.va_transmission)?;
write_kv_opt(w, b"va_emission", &self.va_emission)?;
+ write_kv_opt(w, b"va_joint_weight", &self.va_joint_weight)?;
+ write_kv_opt(w, b"va_joint_index", &self.va_joint_index)?;
write_kv_opt(w, b"tex_normal", &self.tex_normal)?;
write_kv_opt(w, b"tex_roughness", &self.tex_roughness)?;
write_kv_opt(w, b"tex_metallic", &self.tex_metallic)?;
@@ -257,6 +278,7 @@ impl ReadWrite for MeshPart {
write_kv_opt(w, b"tex_alpha", &self.tex_alpha)?;
write_kv_opt(w, b"tex_emission", &self.tex_emission)?;
write_kv_opt(w, b"tex_occlusion", &self.tex_occlusion)?;
+ write_kv_opt(w, b"hint_mirror", &self.hint_mirror)?;
Ok(())
}
fn read(r: &mut dyn Read) -> Result<Self> {
@@ -282,6 +304,8 @@ impl ReadWrite for MeshPart {
b"va_transmission" => Ok(s.va_transmission = Some(read_slice(v)?)),
b"va_alpha" => Ok(s.va_alpha = Some(read_slice(v)?)),
b"va_emission" => Ok(s.va_emission = Some(read_slice(v)?)),
+ b"va_joint_weight" => Ok(s.va_joint_weight = Some(read_slice(v)?)),
+ b"va_joint_index" => Ok(s.va_joint_index = Some(read_slice(v)?)),
b"tex_normal" => Ok(s.tex_normal = Some(read_slice(v)?)),
b"tex_roughness" => Ok(s.tex_roughness = Some(read_slice(v)?)),
b"tex_metallic" => Ok(s.tex_metallic = Some(read_slice(v)?)),
@@ -290,6 +314,7 @@ impl ReadWrite for MeshPart {
b"tex_alpha" => Ok(s.tex_alpha = Some(read_slice(v)?)),
b"tex_emission" => Ok(s.tex_emission = Some(read_slice(v)?)),
b"tex_occlusion" => Ok(s.tex_occlusion = Some(read_slice(v)?)),
+ b"hint_mirror" => Ok(s.hint_mirror = Some(read_slice(v)?)),
x => Ok(warn!(
"unknown mesh part key: {:?}",
String::from_utf8_lossy(x)
diff --git a/world/src/main.rs b/world/src/main.rs
index a2d25ca..67a7c5d 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -122,6 +122,7 @@ fn main() -> Result<()> {
.par_iter()
.map(|(trans, node)| {
let mut prefab = Prefab::default();
+
if let Some(mesh) = node.mesh() {
import_mesh(
mesh,
diff --git a/world/src/mesh.rs b/world/src/mesh.rs
index 3d9ee8d..1b25cbe 100644
--- a/world/src/mesh.rs
+++ b/world/src/mesh.rs
@@ -74,6 +74,24 @@ pub fn import_mesh(
})
.transpose()?;
+ let va_joint_index = reader
+ .read_joints(0)
+ .map(|iter| {
+ let a = iter.into_u16().collect::<Vec<_>>();
+ debug!("{} vertex joint indecies", a.len());
+ Ok::<_, anyhow::Error>(store.set(&a)?)
+ })
+ .transpose()?;
+
+ let va_joint_weight = reader
+ .read_weights(0)
+ .map(|iter| {
+ let a = iter.into_f32().collect::<Vec<_>>();
+ debug!("{} vertex joint weights", a.len());
+ Ok::<_, anyhow::Error>(store.set(&a)?)
+ })
+ .transpose()?;
+
let va_texcoord = reader
.read_tex_coords(0)
.map(|iter| {
@@ -325,6 +343,7 @@ pub fn import_mesh(
let mesh = store.set(&MeshPart {
name,
index,
+ armature: None,
g_albedo,
g_alpha,
g_metallic,
@@ -343,6 +362,8 @@ pub fn import_mesh(
va_texcoord,
va_albedo,
va_alpha,
+ va_joint_index,
+ va_joint_weight,
tex_albedo,
tex_normal,
tex_roughness,
@@ -353,6 +374,7 @@ pub fn import_mesh(
tex_thickness,
tex_occlusion,
// not supported by gltf
+ hint_mirror: None, // TODO
va_transmission: None,
va_emission: None,
va_metallic: None,