lightwave_3d/lwo2/sub_tags/blocks/
image_texture.rs

1use crate::iff::SubChunk;
2use crate::lwo2::sub_tags::blocks::texture_mapping::TextureMapping;
3use crate::lwo2::sub_tags::{ValueEnvelope, VxReference};
4use crate::lwo2::vx;
5use binrw::{binread, NullString};
6
7#[binread]
8#[derive(Debug)]
9pub enum SurfaceBlockImageTextureSubChunk {
10    #[br(magic(b"TMAP"))]
11    TextureMapping(SubChunk<TextureMapping>),
12    #[br(magic(b"PROJ"))]
13    ProjectionMode(SubChunk<ProjectionMode>),
14    #[br(magic(b"AXIS"))]
15    MajorAxis(SubChunk<MajorAxis>),
16    #[br(magic(b"IMAG"))]
17    ImageMap(SubChunk<VxReference>),
18    #[br(magic(b"WRAP"))]
19    ImageWrapOptions(SubChunk<ImageWrapOptions>),
20    #[br(magic(b"WRPW"))]
21    ImageWrapAmountWidth(SubChunk<ImageWrapAmount>),
22    #[br(magic(b"WRPH"))]
23    ImageWrapAmountHeight(SubChunk<ImageWrapAmount>),
24    #[br(magic(b"VMAP"))]
25    UvVertexMap(SubChunk<UvMap>),
26    #[br(magic(b"AAST"))]
27    AntialiasingStrength(SubChunk<AntialiasingStrength>),
28    #[br(magic(b"PIXB"))]
29    PixelBlending(SubChunk<PixelBlending>),
30    #[br(magic(b"STICK"))]
31    StickyProjection(SubChunk<ValueEnvelope>),
32    #[br(magic(b"TAMP"))]
33    TextureAmplitude(SubChunk<ValueEnvelope>),
34}
35
36/// The major axis used for planar, cylindrical and spherical projections. The value is 0, 1 or 2
37/// for the X, Y or Z axis.
38#[binread]
39#[br(import(_length: u32))]
40#[derive(Debug)]
41pub struct MajorAxis {
42    pub texture_axis: u16,
43}
44
45/// Pixel blending enlarges the sample filter when it would otherwise be smaller than a single
46/// image map pixel. If the low-order flag bit is set, then pixel blending is enabled.
47#[binread]
48#[br(import(_length: u32))]
49#[derive(Debug)]
50pub struct PixelBlending {
51    pub flags: u16,
52}
53
54/// The low bit of the flags word is an enable flag for texture antialiasing. The antialiasing
55/// strength is proportional to the width of the sample filter, so larger values sample a larger
56/// area of the image.
57#[binread]
58#[br(import(_length: u32))]
59#[derive(Debug)]
60pub struct AntialiasingStrength {
61    pub flags: u16,
62    pub strength: f32,
63}
64
65/// For UV projection, which depends on texture coordinates at each vertex, this selects the name of
66/// the TXUV vertex map that contains those coordinates.
67#[binread]
68#[br(import(_length: u32))]
69#[derive(Debug)]
70pub struct UvMap {
71    #[br(align_after = 2)]
72    pub txuv_map_name: NullString,
73}
74
75/// For cylindrical and spherical projections, these parameters control how many times the image
76/// repeats over each full interval.
77#[binread]
78#[br(import(_length: u32))]
79#[derive(Debug)]
80pub struct ImageWrapAmount {
81    pub cycles: f32,
82    #[br(parse_with = vx)]
83    pub envelope: u32,
84}
85
86/// Specifies how the color of the texture is derived for areas outside the image.
87#[binread]
88#[br(import(_length: u32))]
89#[derive(Debug)]
90pub struct ImageWrapOptions {
91    pub width_wrap: ImageWrapType,
92    pub height_wrap: ImageWrapType,
93}
94
95#[binread]
96#[br(repr = u16)]
97#[derive(Debug)]
98pub enum ImageWrapType {
99    /// Areas outside the image are assumed to be black. The ultimate effect of this depends on
100    /// the opacity settings. For an additive texture layer on the color channel, the final color
101    /// will come from the preceding layers or from the base color of the surface.
102    Reset = 0,
103    /// The image is repeated or tiled.
104    Repeat = 1,
105    /// Like repeat, but alternate tiles are mirror-reversed.
106    Mirror = 2,
107    /// The color is taken from the image's nearest edge pixel.
108    Edge = 3,
109}
110
111#[binread]
112#[br(repr = u16, import(_length: u32))]
113#[derive(Debug)]
114pub enum ProjectionMode {
115    Planar = 0,
116    Cylindrical = 1,
117    Spherical = 2,
118    Cubic = 3,
119    FrontProjection = 4,
120    UV = 5,
121}