lightwave_3d/lwo2/sub_tags/blocks/
gradient_texture.rs

1use crate::iff::SubChunk;
2use crate::lwo2::sub_tags::Name;
3use binrw::binread;
4
5#[binread]
6#[derive(Debug)]
7pub enum GradientTextureSubChunk {
8    #[br(magic(b"PNAM"))]
9    ParameterName(SubChunk<Name>),
10    #[br(magic(b"INAM"))]
11    ItemName(SubChunk<Name>),
12    #[br(magic(b"GRST"))]
13    GradientRangeStart(SubChunk<GradientRange>),
14    #[br(magic(b"GREN"))]
15    GradientRangeEnd(SubChunk<GradientRange>),
16    #[br(magic(b"GRPT"))]
17    RepeatMode(SubChunk<RepeatMode>),
18    #[br(magic(b"FKEY"))]
19    KeyValues(SubChunk<KeyValues>),
20    #[br(magic(b"IKEY"))]
21    KeyParameters(SubChunk<KeyParameters>),
22}
23
24/// The repeat mode. This is currently undefined.
25#[binread]
26#[br(import(length: u32))]
27#[derive(Debug)]
28pub struct KeyParameters {
29    #[br(count = length / 2)]
30    pub repeat_mode: Vec<u16>,
31}
32
33/// The transfer function is defined by an array of keys, each with an input value and an RGBA
34/// output vector. Given an input value, the gradient can be evaluated by selecting the keys whose
35/// positions bracket the value and interpolating between their outputs. If the input value is lower
36/// than the first key or higher than the last key, the gradient value is the value of the closest
37/// key.
38#[binread]
39#[br(import(length: u32))]
40#[derive(Debug)]
41pub struct KeyValues {
42    #[br(count = length / 18)]
43    pub key_values: Vec<KeyValue>,
44}
45
46#[binread]
47#[derive(Debug)]
48pub struct KeyValue {
49    pub input: f32,
50    pub output: [f32; 4],
51}
52
53/// The start and end of the input range. These values only affect the display of the gradient
54/// in the user interface. They don't affect rendering.
55#[binread]
56#[br(import(_length: u32))]
57#[derive(Debug)]
58pub struct GradientRange {
59    pub name: f32,
60}
61
62/// The repeat mode. This is currently undefined.
63#[binread]
64#[br(import(_length: u32))]
65#[derive(Debug)]
66pub struct RepeatMode {
67    pub repeat_mode: u16,
68}