diff options
Diffstat (limited to 'world')
-rw-r--r-- | world/Cargo.toml | 1 | ||||
-rw-r--r-- | world/src/main.rs | 75 |
2 files changed, 61 insertions, 15 deletions
diff --git a/world/Cargo.toml b/world/Cargo.toml index ee74e2b..bdfc1f1 100644 --- a/world/Cargo.toml +++ b/world/Cargo.toml @@ -10,3 +10,4 @@ env_logger = "0.11.6" gltf = { version = "1.4.1", features = ["extras", "names"] } log = "0.4.22" weareshared = { path = "../shared" } +rand = "0.9.0-beta.1"
\ No newline at end of file diff --git a/world/src/main.rs b/world/src/main.rs index fe71e79..4f433ba 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -1,21 +1,28 @@ #![feature(iter_array_chunks)] use anyhow::Result; use clap::Parser; +use rand::random; use std::{ + io::Write, net::{SocketAddr, TcpStream}, path::PathBuf, + thread::{self, sleep}, + time::Duration, }; use weareshared::{ - Affine3A, Mat3A, Vec3A, - packets::{Object, Packet, ReadWrite}, + Affine3A, Vec3A, + packets::{Data, Object, Packet, ReadWrite}, resources::{Attribute, AttributeArray, IndexArray, Part, Prefab}, store::ResourceStore, + vec3a, }; #[derive(Parser)] struct Args { address: SocketAddr, scene: PathBuf, + #[arg(short, long)] + push: bool, } fn main() -> Result<()> { @@ -25,6 +32,8 @@ fn main() -> Result<()> { let mut sock = TcpStream::connect(args.address)?; let store = ResourceStore::new_memory(); + Packet::Connect(random()).write(&mut sock)?; + let (gltf, buffers, _) = gltf::import(args.scene)?; let mut prefab = Prefab::default(); @@ -38,6 +47,8 @@ fn main() -> Result<()> { let mut norm_x = vec![]; let mut norm_y = vec![]; let mut norm_z = vec![]; + let mut uv_x = vec![]; + let mut uv_y = vec![]; for p in reader.read_positions().unwrap() { pos_x.push(p[0]); pos_y.push(p[1]); @@ -48,6 +59,10 @@ fn main() -> Result<()> { norm_y.push(p[1]); norm_z.push(p[2]); } + for p in reader.read_tex_coords(0).unwrap().into_f32() { + uv_x.push(p[0]); + uv_y.push(p[1]); + } let index = reader .read_indices() .unwrap() @@ -56,6 +71,8 @@ fn main() -> Result<()> { .array_chunks::<3>() .collect::<Vec<_>>(); + if let Some(tex) = p.material().pbr_metallic_roughness().base_color_texture() {} + let part = store.set( &Part { va_position: Some([ @@ -68,6 +85,15 @@ fn main() -> Result<()> { Attribute::Vertex(store.set(&AttributeArray(norm_y).write_alloc())?), Attribute::Vertex(store.set(&AttributeArray(norm_z).write_alloc())?), ]), + va_texcoord: Some([ + 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), + ]), index: Some(store.set(&IndexArray(index).write_alloc())?), ..Part::default() } @@ -86,23 +112,42 @@ fn main() -> Result<()> { } } - Packet::Add(Object::new(), store.set(&prefab.write_alloc())?).write(&mut sock)?; + let ob = Object::new(); + Packet::Add(ob, store.set(&prefab.write_alloc())?).write(&mut sock)?; - store.iter(|d| { - Packet::RespondResource(d.to_vec()) - .write(&mut sock) - .unwrap(); - })?; + let mut sock2 = sock.try_clone().unwrap(); + thread::spawn(move || { + let mut x = 0.; + loop { + Packet::Position(ob, Vec3A::ZERO, vec3a(x, x * 0.3, x * 0.1)) + .write(&mut sock2) + .unwrap(); + sock2.flush().unwrap(); + x += 0.1; + sleep(Duration::from_millis(50)); + } + }); - loop { - let packet = Packet::read(&mut sock)?; - match packet { - Packet::RequestResource(hash) => { - if let Some(d) = store.get(hash)? { - Packet::RespondResource(d).write(&mut sock)?; + if args.push { + store.iter(|d| { + Packet::RespondResource(Data(d.to_vec())) + .write(&mut sock) + .unwrap(); + })?; + sock.flush()?; + } else { + loop { + let packet = Packet::read(&mut sock)?; + match packet { + Packet::RequestResource(hash) => { + if let Some(d) = store.get(hash)? { + Packet::RespondResource(Data(d)).write(&mut sock)?; + sock.flush()?; + } } + _ => (), } - _ => (), } } + Ok(()) } |