diff --git a/rust/lightwave/README.md b/rust/lightwave/README.md index e6d13a0..845af81 100644 --- a/rust/lightwave/README.md +++ b/rust/lightwave/README.md @@ -1,5 +1,7 @@ # LightWave 3D Rust Parser +Complete LWO2 parser for Rust. + Basic Usage ```rust @@ -14,7 +16,7 @@ fn main() { ## LightWave Object (LWO2) -Progress: About 90% ([LWO2 Spec](http://static.lightwave3d.com/sdk/2015/html/filefmts/lwo2.html)) +Fully feature complete following the [LWO2 Spec](http://static.lightwave3d.com/sdk/2015/html/filefmts/lwo2.html). | Chunk | Tag | Status | |--------------------------------------------|--------|--------| @@ -107,7 +109,7 @@ Progress: About 90% ([LWO2 Spec](http://static.lightwave3d.com/sdk/2015/html/fil Ordinal Strings: * ✅ [Image Texture Map](#image-texture-map) `IMAP` -* ❌ [Procedural Texture](#procedural-texture) `PROC` +* ✅ [Procedural Texture](#procedural-texture) `PROC` * ✅ [Gradient Texture](#gradient-texture) `GRAD` * ✅ [Shader Plugin](#shaders) `SHDR` @@ -150,9 +152,9 @@ Ordinal Strings: | Chunk | Tag | Status | |--------------------------|--------|--------| -| Axis | `AXIS` | ❌ | -| Basic Value | `VALU` | ❌ | -| Algorithm and Parameters | `FUNC` | ❌ | +| Axis | `AXIS` | ✅ | +| Basic Value | `VALU` | ✅ | +| Algorithm and Parameters | `FUNC` | ✅ | #### Gradient Texture diff --git a/rust/lightwave/src/lwo2/sub_tags/blocks/mod.rs b/rust/lightwave/src/lwo2/sub_tags/blocks/mod.rs index 688de19..f58f89b 100644 --- a/rust/lightwave/src/lwo2/sub_tags/blocks/mod.rs +++ b/rust/lightwave/src/lwo2/sub_tags/blocks/mod.rs @@ -2,15 +2,14 @@ use crate::binrw_helpers::until_size_limit; use crate::iff::SubChunk; use crate::lwo2::sub_tags::blocks::gradient_texture::GradientTextureSubChunk; use crate::lwo2::sub_tags::blocks::image_texture::SurfaceBlockImageTextureSubChunk; -use crate::lwo2::sub_tags::blocks::shaders::ShaderAlgorithm; +use crate::lwo2::sub_tags::blocks::procedural_texture::ProceduralTextureSubChunk; use crate::lwo2::sub_tags::EnableState; use crate::lwo2::vx; -use binrw::binread; +use binrw::{binread, NullString}; pub mod gradient_texture; pub mod image_texture; pub mod procedural_texture; -pub mod shaders; pub mod texture_mapping; #[binread] @@ -24,7 +23,11 @@ pub enum SurfaceBlocks { attributes: Vec, }, #[br(magic(b"PROC"))] - ProceduralTexture, + ProceduralTexture { + header: SubChunk, + #[br(parse_with = until_size_limit(length as u64 - (header.length as u64 + 2 + 4)))] + attributes: Vec, + }, #[br(magic(b"GRAD"))] GradientTexture { header: SubChunk, @@ -35,10 +38,20 @@ pub enum SurfaceBlocks { ShaderPlugin { header: SubChunk, #[br(magic(b"FUNC"))] - algorithm: SubChunk, + algorithm: SubChunk, }, } +#[binread] +#[br(import(length: u32))] +#[derive(Debug)] +pub struct Algorithm { + #[br(align_after = 2)] + pub algorithm_name: NullString, + #[br(count = length - (algorithm_name.len() as u32 + 1))] + pub data: Vec, +} + #[binread] #[br(import(length: u32))] #[derive(Debug)] diff --git a/rust/lightwave/src/lwo2/sub_tags/blocks/procedural_texture.rs b/rust/lightwave/src/lwo2/sub_tags/blocks/procedural_texture.rs index e69de29..1a88ec1 100644 --- a/rust/lightwave/src/lwo2/sub_tags/blocks/procedural_texture.rs +++ b/rust/lightwave/src/lwo2/sub_tags/blocks/procedural_texture.rs @@ -0,0 +1,32 @@ +use crate::iff::SubChunk; +use crate::lwo2::sub_tags::blocks::Algorithm; +use binrw::binread; + +#[binread] +#[derive(Debug)] +pub enum ProceduralTextureSubChunk { + #[br(magic(b"AXIS"))] + Axis(SubChunk), + #[br(magic(b"VALU"))] + BasicValue(SubChunk), + #[br(magic(b"FUNC"))] + AlgorithmAndParameters(SubChunk), +} + +/// Procedurals are often modulations between the current channel value and another value, given +/// here. This may be a scalar or a vector. +#[binread] +#[br(import(length: u32))] +#[derive(Debug)] +pub struct BasicValue { + #[br(count = length / 4)] + pub value: Vec, +} + +/// If the procedural has an axis, it may be defined with this chunk using a value of 0, 1 or 2. +#[binread] +#[br(import(_length: u32))] +#[derive(Debug)] +pub struct Axis { + pub axis: u16, +} diff --git a/rust/lightwave/src/lwo2/sub_tags/blocks/shaders.rs b/rust/lightwave/src/lwo2/sub_tags/blocks/shaders.rs deleted file mode 100644 index c3d07a0..0000000 --- a/rust/lightwave/src/lwo2/sub_tags/blocks/shaders.rs +++ /dev/null @@ -1,11 +0,0 @@ -use binrw::{binread, NullString}; - -#[binread] -#[br(import(length: u32))] -#[derive(Debug)] -pub struct ShaderAlgorithm { - #[br(align_after = 2)] - pub algorithm_name: NullString, - #[br(count = length - (algorithm_name.len() as u32 + 1))] - pub data: Vec, -}