summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-07 00:56:35 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-07 00:56:35 +0100
commit31ae23b7eb8cd0b688be07ae6cb4b5a96ee02a68 (patch)
tree4684c2716b8ec2963b4ad97eb3adc2162c9bc499
parent32d493db1d897a61fd3e1170136fa3e812704837 (diff)
downloadweareserver-31ae23b7eb8cd0b688be07ae6cb4b5a96ee02a68.tar
weareserver-31ae23b7eb8cd0b688be07ae6cb4b5a96ee02a68.tar.bz2
weareserver-31ae23b7eb8cd0b688be07ae6cb4b5a96ee02a68.tar.zst
a
-rw-r--r--client/src/scene_prepare.rs6
-rw-r--r--shared/src/packets.rs3
-rw-r--r--shared/src/resources.rs28
-rw-r--r--world/src/main.rs21
4 files changed, 38 insertions, 20 deletions
diff --git a/client/src/scene_prepare.rs b/client/src/scene_prepare.rs
index 7b81c93..85db160 100644
--- a/client/src/scene_prepare.rs
+++ b/client/src/scene_prepare.rs
@@ -138,7 +138,7 @@ impl ScenePreparer {
self.vertex_buffers_needed.insert(resource);
};
}
- Attribute::Texture(_resource) => todo!(),
+ Attribute::Texture(_resource, _ch) => todo!(),
}
}
let mut normal = Vec::new();
@@ -152,7 +152,7 @@ impl ScenePreparer {
self.vertex_buffers_needed.insert(resource);
};
}
- Attribute::Texture(_resource) => todo!(),
+ Attribute::Texture(_resource, _ch) => todo!(),
}
}
let mut texcoord = Vec::new();
@@ -166,7 +166,7 @@ impl ScenePreparer {
self.vertex_buffers_needed.insert(resource);
};
}
- Attribute::Texture(_resource) => todo!(),
+ Attribute::Texture(_resource, _ch) => todo!(),
}
}
if texcoord.len() == 2 && normal.len() == 3 && position.len() == 3 {
diff --git a/shared/src/packets.rs b/shared/src/packets.rs
index a1636cd..0f1a886 100644
--- a/shared/src/packets.rs
+++ b/shared/src/packets.rs
@@ -125,7 +125,8 @@ impl ReadWrite for Packet {
0x07 => Packet::Parent(Object(read_u128(r)?), Object(read_u128(r)?)),
0x08 => Packet::Sound(Object(read_u128(r)?), Data::read(r)?),
_ => {
- for _ in 0..u16::from_be_bytes([size_tag[0], size_tag[1]]) - 1 {
+ let len = u16::from_be_bytes([size_tag[0], size_tag[1]]);
+ for _ in 0..len.max(1) - 1 {
r.read_exact(&mut [0])?;
}
bail!("unknown packet tag");
diff --git a/shared/src/resources.rs b/shared/src/resources.rs
index 042dff3..a071f1c 100644
--- a/shared/src/resources.rs
+++ b/shared/src/resources.rs
@@ -2,10 +2,7 @@ use crate::packets::{ReadWrite, Resource};
use anyhow::{Result, bail};
use glam::{Affine3A, Vec3A};
use log::warn;
-use std::{
- fs::File,
- io::{Read, Write},
-};
+use std::io::{Read, Write};
#[derive(Debug, Default, Clone)]
pub struct Prefab(pub Vec<(Affine3A, Resource)>);
@@ -26,7 +23,7 @@ pub struct Part {
pub enum Attribute {
Constant(f32),
Vertex(Resource),
- Texture(Resource),
+ Texture(Resource, u8),
}
#[derive(Debug, Default, Clone)]
@@ -171,25 +168,36 @@ impl ReadWrite for Attribute {
w.write_all(&[0x02])?;
resource.write(w)?;
}
- Attribute::Texture(resource) => {
+ Attribute::Texture(resource, channel) => {
w.write_all(&[0x03])?;
resource.write(w)?;
+ channel.write(w)?;
}
}
Ok(())
}
fn read(r: &mut dyn Read) -> Result<Self> {
- let mut tag = [0u8; 1];
- r.read_exact(&mut tag)?;
- Ok(match tag[0] {
+ Ok(match u8::read(r)? {
0x01 => Self::Constant(f32::read(r)?),
0x02 => Self::Vertex(Resource::read(r)?),
- 0x03 => Self::Texture(Resource::read(r)?),
+ 0x03 => Self::Texture(Resource::read(r)?, u8::read(r)?),
_ => bail!("unknown attribute tag"),
})
}
}
+impl ReadWrite for u8 {
+ fn write(&self, w: &mut dyn Write) -> Result<()> {
+ w.write_all(&[*self])?;
+ Ok(())
+ }
+ fn read(r: &mut dyn Read) -> Result<Self> {
+ let mut buf = [0u8; 1];
+ r.read_exact(&mut buf)?;
+ Ok(buf[0])
+ }
+}
+
impl ReadWrite for Vec3A {
fn write(&self, w: &mut dyn Write) -> Result<()> {
w.write_all(&self.x.to_be_bytes())?;
diff --git a/world/src/main.rs b/world/src/main.rs
index 2823540..033d176 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -73,7 +73,14 @@ fn main() -> Result<()> {
.array_chunks::<3>()
.collect::<Vec<_>>();
- if let Some(tex) = p.material().pbr_metallic_roughness().base_color_texture() {}
+ let mut albedo = None;
+ if let Some(tex) = p.material().pbr_metallic_roughness().base_color_texture() {
+ let s = tex.texture().source().source();
+ if let gltf::image::Source::View { view, mime_type } = s {
+ let buf = &buffers[view.buffer().index()];
+ albedo = Some(store.set(&buf.0)?);
+ }
+ }
let part = store.set(
&Part {
@@ -91,11 +98,13 @@ fn main() -> Result<()> {
Attribute::Vertex(store.set(&AttributeArray(uv_x).write_alloc())?),
Attribute::Vertex(store.set(&AttributeArray(uv_y).write_alloc())?),
]),
- va_pbr_albedo: Some([
- Attribute::Constant(0.9),
- Attribute::Constant(0.1),
- Attribute::Constant(0.1),
- ]),
+ va_pbr_albedo: albedo.map(|a| {
+ [
+ Attribute::Texture(a, 0),
+ Attribute::Texture(a, 1),
+ Attribute::Texture(a, 2),
+ ]
+ }),
index: Some(store.set(&IndexArray(index).write_alloc())?),
..Part::default()
}