diff options
author | metamuffin <metamuffin@disroot.org> | 2025-02-17 22:19:46 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-02-17 22:19:46 +0100 |
commit | aa6158cb24785871b21e60eed378e3205d1be0b6 (patch) | |
tree | 056cf9c78464a51377287131608f6d7a417b8c1a /world/src/main.rs | |
parent | 0315b90767ccbaa1dcde11d450976f1dc0c928ba (diff) | |
download | weareserver-aa6158cb24785871b21e60eed378e3205d1be0b6.tar weareserver-aa6158cb24785871b21e60eed378e3205d1be0b6.tar.bz2 weareserver-aa6158cb24785871b21e60eed378e3205d1be0b6.tar.zst |
import particles
Diffstat (limited to 'world/src/main.rs')
-rw-r--r-- | world/src/main.rs | 48 |
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) |