lwo2 parser feature complete

This commit is contained in:
2023-05-10 00:51:28 +02:00
parent cbf4d5df09
commit 5e70d1674d
4 changed files with 57 additions and 21 deletions

View File

@@ -1,5 +1,7 @@
# LightWave 3D Rust Parser # LightWave 3D Rust Parser
Complete LWO2 parser for Rust.
Basic Usage Basic Usage
```rust ```rust
@@ -14,7 +16,7 @@ fn main() {
## LightWave Object (LWO2) ## 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 | | Chunk | Tag | Status |
|--------------------------------------------|--------|--------| |--------------------------------------------|--------|--------|
@@ -107,7 +109,7 @@ Progress: About 90% ([LWO2 Spec](http://static.lightwave3d.com/sdk/2015/html/fil
Ordinal Strings: Ordinal Strings:
* ✅ [Image Texture Map](#image-texture-map) `IMAP` * ✅ [Image Texture Map](#image-texture-map) `IMAP`
* [Procedural Texture](#procedural-texture) `PROC` * [Procedural Texture](#procedural-texture) `PROC`
* ✅ [Gradient Texture](#gradient-texture) `GRAD` * ✅ [Gradient Texture](#gradient-texture) `GRAD`
* ✅ [Shader Plugin](#shaders) `SHDR` * ✅ [Shader Plugin](#shaders) `SHDR`
@@ -150,9 +152,9 @@ Ordinal Strings:
| Chunk | Tag | Status | | Chunk | Tag | Status |
|--------------------------|--------|--------| |--------------------------|--------|--------|
| Axis | `AXIS` | | | Axis | `AXIS` | |
| Basic Value | `VALU` | | | Basic Value | `VALU` | |
| Algorithm and Parameters | `FUNC` | | | Algorithm and Parameters | `FUNC` | |
#### Gradient Texture #### Gradient Texture

View File

@@ -2,15 +2,14 @@ use crate::binrw_helpers::until_size_limit;
use crate::iff::SubChunk; use crate::iff::SubChunk;
use crate::lwo2::sub_tags::blocks::gradient_texture::GradientTextureSubChunk; use crate::lwo2::sub_tags::blocks::gradient_texture::GradientTextureSubChunk;
use crate::lwo2::sub_tags::blocks::image_texture::SurfaceBlockImageTextureSubChunk; 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::sub_tags::EnableState;
use crate::lwo2::vx; use crate::lwo2::vx;
use binrw::binread; use binrw::{binread, NullString};
pub mod gradient_texture; pub mod gradient_texture;
pub mod image_texture; pub mod image_texture;
pub mod procedural_texture; pub mod procedural_texture;
pub mod shaders;
pub mod texture_mapping; pub mod texture_mapping;
#[binread] #[binread]
@@ -24,7 +23,11 @@ pub enum SurfaceBlocks {
attributes: Vec<SurfaceBlockImageTextureSubChunk>, attributes: Vec<SurfaceBlockImageTextureSubChunk>,
}, },
#[br(magic(b"PROC"))] #[br(magic(b"PROC"))]
ProceduralTexture, ProceduralTexture {
header: SubChunk<SurfaceBlockHeader>,
#[br(parse_with = until_size_limit(length as u64 - (header.length as u64 + 2 + 4)))]
attributes: Vec<ProceduralTextureSubChunk>,
},
#[br(magic(b"GRAD"))] #[br(magic(b"GRAD"))]
GradientTexture { GradientTexture {
header: SubChunk<SurfaceBlockHeader>, header: SubChunk<SurfaceBlockHeader>,
@@ -35,10 +38,20 @@ pub enum SurfaceBlocks {
ShaderPlugin { ShaderPlugin {
header: SubChunk<SurfaceBlockHeader>, header: SubChunk<SurfaceBlockHeader>,
#[br(magic(b"FUNC"))] #[br(magic(b"FUNC"))]
algorithm: SubChunk<ShaderAlgorithm>, algorithm: SubChunk<Algorithm>,
}, },
} }
#[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<u8>,
}
#[binread] #[binread]
#[br(import(length: u32))] #[br(import(length: u32))]
#[derive(Debug)] #[derive(Debug)]

View File

@@ -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<Axis>),
#[br(magic(b"VALU"))]
BasicValue(SubChunk<BasicValue>),
#[br(magic(b"FUNC"))]
AlgorithmAndParameters(SubChunk<Algorithm>),
}
/// 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<f32>,
}
/// 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,
}

View File

@@ -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<u8>,
}