summaryrefslogtreecommitdiff
path: root/world
diff options
context:
space:
mode:
Diffstat (limited to 'world')
-rw-r--r--world/src/main.rs48
1 files changed, 44 insertions, 4 deletions
diff --git a/world/src/main.rs b/world/src/main.rs
index 7552dde..1931fdb 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -20,7 +20,7 @@ pub mod mesh;
pub mod physics;
pub mod vrm;
-use anyhow::{Result, anyhow};
+use anyhow::{Context, Result, anyhow};
use clap::Parser;
use gltf::{Gltf, Node, image::Source, import_buffers, scene::Transform};
use humansize::BINARY;
@@ -30,6 +30,8 @@ use mesh::import_mesh;
use physics::import_physics;
use rand::random;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
+use serde::Deserialize;
+use serde_json::Value;
use std::{
borrow::Cow,
collections::{BTreeMap, HashMap},
@@ -47,7 +49,7 @@ use weareshared::{
Affine3A, Vec3A,
helper::ReadWrite,
packets::{Data, Object, Packet, Resource},
- resources::{ArmaturePart, EnvironmentPart, Image, LightPart, Prefab},
+ resources::{ArmaturePart, EnvironmentPart, Image, LightPart, ParticlesPart, Prefab},
store::ResourceStore,
vec3a,
};
@@ -230,7 +232,14 @@ fn main() -> Result<()> {
// eprintln!("{:?}", node.extensions());
// eprintln!("{:?}", node.extras());
// }
- if !node.name().unwrap_or_default().ends_with("-collider") {
+ let name = node.name().unwrap_or_default();
+ let extras: Value = node
+ .extras()
+ .to_owned()
+ .map(|v| serde_json::from_str(v.get()).unwrap())
+ .unwrap_or(Value::Object(Default::default()));
+
+ if !name.ends_with("-collider") {
if let Some(mesh) = node.mesh() {
import_mesh(
mesh,
@@ -248,7 +257,36 @@ fn main() -> Result<()> {
)?;
}
}
- let (position, _, _) = node.transform().decomposed();
+ if extras.get("particles") == Some(&Value::Bool(true)) {
+ #[derive(Deserialize)]
+ struct ParticlesAttr {
+ density: Option<f32>,
+ lifetime: Option<f32>,
+ lifetime_spread: Option<f32>,
+ velocity: Option<Vec3A>,
+ velocity_spread: Option<Vec3A>,
+ }
+ // let sprite = extras
+ // .get("sprite")
+ // .ok_or(anyhow!("particle volume is missing sprite"))?;
+
+ let attr: ParticlesAttr =
+ serde_json::from_value(extras).context("particles attributes")?;
+
+ info!("adding particles part");
+ prefab.particles.push((
+ transform_to_affine(node.transform()),
+ store.set(&ParticlesPart {
+ sprite: None,
+ density: attr.density,
+ lifetime: attr.lifetime,
+ lifetime_spread: attr.lifetime_spread,
+ velocity: attr.velocity,
+ velocity_spread: attr.velocity_spread,
+ })?,
+ ));
+ }
+
if let Some(light) = node.light() {
let name = node.name().map(|e| e.to_owned());
if let Some(name) = &name {
@@ -260,6 +298,7 @@ fn main() -> Result<()> {
if let Some(e) = emission {
debug!("emission is {e}");
}
+ let (position, _, _) = node.transform().decomposed();
prefab.light.push((
Vec3A::from_array(position),
store.set(&LightPart {
@@ -280,6 +319,7 @@ fn main() -> Result<()> {
a.collision.extend(b.collision);
a.mesh.extend(b.mesh);
a.light.extend(b.light);
+ a.particles.extend(b.particles);
a.environment = a.environment.or(b.environment);
a.name = a.name.or(b.name);
Ok(a)