diff options
Diffstat (limited to 'shared/src/resources.rs')
-rw-r--r-- | shared/src/resources.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/shared/src/resources.rs b/shared/src/resources.rs index 76e52f8..19ce6b2 100644 --- a/shared/src/resources.rs +++ b/shared/src/resources.rs @@ -31,6 +31,7 @@ pub struct Prefab { pub collision: Vec<(Affine3A, Resource<CollisionPart>)>, pub light: Vec<(Vec3A, Resource<LightPart>)>, pub armature: Vec<Resource<ArmaturePart>>, + pub particles: Vec<(Affine3A, Resource<ParticlesPart>)>, pub environment: Option<Resource<EnvironmentPart>>, } @@ -48,6 +49,16 @@ pub struct EnvironmentPart { } #[derive(Debug, Default, Clone)] +pub struct ParticlesPart { + pub sprite: Option<Resource<MeshPart>>, + pub density: Option<f32>, + pub lifetime: Option<f32>, + pub lifetime_spread: Option<f32>, + pub velocity: Option<Vec3A>, + pub velocity_spread: Option<Vec3A>, +} + +#[derive(Debug, Default, Clone)] pub struct MeshPart { pub name: Option<String>, pub index: Option<Resource<Vec<[u32; 3]>>>, @@ -209,6 +220,9 @@ impl ReadWrite for Prefab { for x in &self.armature { write_kv_opt(w, b"armature", &Some(x.clone()))?; } + for x in &self.particles { + write_kv_opt(w, b"particles", &Some(x.clone()))?; + } write_kv_opt(w, b"environment", &self.environment)?; Ok(()) } @@ -220,6 +234,7 @@ impl ReadWrite for Prefab { b"collision" => Ok(s.collision.push(read_slice(v)?)), b"light" => Ok(s.light.push(read_slice(v)?)), b"armature" => Ok(s.armature.push(read_slice(v)?)), + b"particles" => Ok(s.particles.push(read_slice(v)?)), b"environment" => Ok(s.environment = Some(read_slice(v)?)), x => Ok(warn!( "unknown prefab key: {:?}", @@ -270,6 +285,33 @@ impl ReadWrite for EnvironmentPart { Ok(s) } } +impl ReadWrite for ParticlesPart { + fn write(&self, w: &mut dyn Write) -> Result<()> { + write_kv_opt(w, b"density", &self.density)?; + write_kv_opt(w, b"sprite", &self.sprite)?; + write_kv_opt(w, b"lifetime", &self.lifetime)?; + write_kv_opt(w, b"lifetime_spread", &self.lifetime_spread)?; + write_kv_opt(w, b"velocity", &self.velocity)?; + write_kv_opt(w, b"velocity_spread", &self.velocity_spread)?; + Ok(()) + } + fn read(r: &mut dyn Read) -> Result<Self> { + let mut s = Self::default(); + read_kv_iter(r, |k, v| match k { + b"density" => Ok(s.density = Some(read_slice(v)?)), + b"sprite" => Ok(s.sprite = Some(read_slice(v)?)), + b"lifetime" => Ok(s.lifetime = Some(read_slice(v)?)), + b"lifetime_spread" => Ok(s.lifetime_spread = Some(read_slice(v)?)), + b"velocity" => Ok(s.velocity = Some(read_slice(v)?)), + b"velocity_spread" => Ok(s.velocity_spread = Some(read_slice(v)?)), + x => Ok(warn!( + "unknown environment part key: {:?}", + String::from_utf8_lossy(x) + )), + })?; + Ok(s) + } +} impl ReadWrite for MeshPart { fn write(&self, w: &mut dyn Write) -> Result<()> { write_kv_opt(w, b"name", &self.name)?; |