summaryrefslogtreecommitdiff
path: root/world
diff options
context:
space:
mode:
Diffstat (limited to 'world')
-rw-r--r--world/src/main.rs153
1 files changed, 80 insertions, 73 deletions
diff --git a/world/src/main.rs b/world/src/main.rs
index 7548d8f..f67febb 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -50,8 +50,8 @@ use weareshared::{
#[derive(Parser)]
pub struct Args {
address: SocketAddr,
- /// Path to a glTF file, binary or json format
- scene: PathBuf,
+ /// Path(s) to a glTF file, binary or json format
+ scene: Vec<PathBuf>,
/// Send all resources to the server then quit
#[arg(short, long)]
push: bool,
@@ -87,74 +87,78 @@ fn main() -> Result<()> {
let store = ResourceStore::new_memory();
- let path_base = args.scene.parent().unwrap();
- let mut gltf = Gltf::from_reader_without_validation(File::open(&args.scene)?)?;
- let blob = gltf.blob.take();
- let buffers = import_buffers(&gltf, Some(path_base), blob)?;
+ let mut prefabs = Vec::new();
- let mut prefab = gltf
- .nodes()
- .par_bridge()
- .map(|node| {
- let mut prefab = Prefab::default();
- if let Some(mesh) = node.mesh() {
- import_mesh(mesh, &buffers, &store, path_base, &node, &mut prefab, &args)?;
- }
- let (position, _, _) = node.transform().decomposed();
- if let Some(light) = node.light() {
- let name = node.name().map(|e| e.to_owned());
- if let Some(name) = &name {
- info!("adding light {name:?}");
- } else {
- info!("adding light");
+ for scenepath in &args.scene {
+ let path_base = scenepath.parent().unwrap();
+ let mut gltf = Gltf::from_reader_without_validation(File::open(scenepath)?)?;
+ let blob = gltf.blob.take();
+ let buffers = import_buffers(&gltf, Some(path_base), blob)?;
+
+ let mut prefab = gltf
+ .nodes()
+ .par_bridge()
+ .map(|node| {
+ let mut prefab = Prefab::default();
+ if let Some(mesh) = node.mesh() {
+ import_mesh(mesh, &buffers, &store, path_base, &node, &mut prefab, &args)?;
}
- let emission = Some(Vec3A::from_array(light.color()) * light.intensity());
- if let Some(e) = emission {
- debug!("emission is {e}");
+ let (position, _, _) = node.transform().decomposed();
+ if let Some(light) = node.light() {
+ let name = node.name().map(|e| e.to_owned());
+ if let Some(name) = &name {
+ info!("adding light {name:?}");
+ } else {
+ info!("adding light");
+ }
+ let emission = Some(Vec3A::from_array(light.color()) * light.intensity());
+ if let Some(e) = emission {
+ debug!("emission is {e}");
+ }
+ prefab.light.push((
+ Vec3A::from_array(position),
+ store.set(&LightPart {
+ emission,
+ name,
+ radius: None,
+ })?,
+ ));
}
- prefab.light.push((
- Vec3A::from_array(position),
- store.set(&LightPart {
- emission,
- name,
- radius: None,
- })?,
- ));
- }
- import_physics(&gltf, &node, &mut prefab, &store, &buffers, &args)?;
- Ok::<_, anyhow::Error>(prefab)
- })
- .reduce(
- || Ok(Prefab::default()),
- |a, b| {
- let mut a = a?;
- let b = b?;
- a.collision.extend(b.collision);
- a.mesh.extend(b.mesh);
- a.light.extend(b.light);
- a.environment = a.environment.or(b.environment);
- a.name = a.name.or(b.name);
- Ok(a)
- },
- )?;
+ import_physics(&gltf, &node, &mut prefab, &store, &buffers, &args)?;
+ Ok::<_, anyhow::Error>(prefab)
+ })
+ .reduce(
+ || Ok(Prefab::default()),
+ |a, b| {
+ let mut a = a?;
+ let b = b?;
+ a.collision.extend(b.collision);
+ a.mesh.extend(b.mesh);
+ a.light.extend(b.light);
+ a.environment = a.environment.or(b.environment);
+ a.name = a.name.or(b.name);
+ Ok(a)
+ },
+ )?;
+
+ if let Some(skybox) = &args.skybox {
+ let mut buf = Vec::new();
+ File::open(skybox)?.read_to_end(&mut buf)?;
+ prefab.environment = Some(store.set(&EnvironmentPart {
+ skybox: Some(store.set(&Image(Cow::Owned(buf)))?),
+ ..Default::default()
+ })?);
+ }
- prefab.name = args.name.clone().or(gltf
- .default_scene()
- .map(|n| n.name())
- .flatten()
- .map(|n| n.to_owned()));
+ prefab.name = args.name.clone().or(gltf
+ .default_scene()
+ .map(|n| n.name())
+ .flatten()
+ .map(|n| n.to_owned()));
- if let Some(skybox) = args.skybox {
- let mut buf = Vec::new();
- File::open(skybox)?.read_to_end(&mut buf)?;
- prefab.environment = Some(store.set(&EnvironmentPart {
- skybox: Some(store.set(&Image(Cow::Owned(buf)))?),
- ..Default::default()
- })?);
+ prefabs.push(store.set(&prefab)?);
}
- let pres = store.set(&prefab)?;
-
let mut size = 0;
store.iter(|d| size += d.len()).unwrap();
info!(
@@ -168,20 +172,23 @@ fn main() -> Result<()> {
let mut sock = TcpStream::connect(args.address)?;
Packet::Connect(random()).write(&mut sock)?;
- Packet::AnnouncePrefab(pres.clone()).write(&mut sock)?;
+ for p in &prefabs {
+ Packet::AnnouncePrefab(p.clone()).write(&mut sock)?;
+ }
sock.flush()?;
- let ob = if args.add {
- let ob = Object::new();
- Packet::Add(ob, pres.clone()).write(&mut sock)?;
+ let mut obs = Vec::new();
+ if args.add {
+ for p in &prefabs {
+ let ob = Object::new();
+ Packet::Add(ob, p.clone()).write(&mut sock)?;
+ obs.push(ob);
+ }
sock.flush()?;
- Some(ob)
- } else {
- None
- };
+ }
if args.spin {
- let ob = ob.clone().unwrap();
+ let ob = obs[0].clone();
let mut sock2 = sock.try_clone().unwrap();
thread::spawn(move || {
let mut x = 0.;
@@ -215,7 +222,7 @@ fn main() -> Result<()> {
}
Packet::Add(ob_a, _) => {
if args.clear {
- if Some(ob_a) != ob {
+ if !obs.contains(&ob_a) {
info!("removing object {ob_a}");
Packet::Remove(ob_a).write(&mut sock)?;
sock.flush()?;