mod3d_gltf/
texture.rs

1//a Imports
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5use crate::Named;
6use crate::{ImageIndex, SamplerIndex, TextureIndex};
7
8//a GltfTextureInfo
9//tp GltfTextureInfo
10/// A type representing a Gltf Texture Info, which is instantiated in
11/// different ways for different aspects of a material, and which
12/// refers to a Texture (and TexCoord number)
13#[derive(Debug, Default)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15#[cfg_attr(feature = "serde", serde(default))]
16pub struct GltfTextureInfo {
17    /// Optional name of the texture
18    pub index: TextureIndex,
19    /// Image index (source)
20    #[cfg_attr(feature = "serde", serde(rename = "texCoord"))]
21    pub tex_coord: usize,
22    /// Scale - for normal textures only
23    pub scale: f32,
24    /// Strength - for occlusion textures only
25    pub strength: f32,
26}
27
28impl GltfTextureInfo {
29    pub fn index(&self) -> TextureIndex {
30        self.index
31    }
32}
33
34//a GltfTexture
35//tp GltfTexture
36/// A type representing a Gltf Texture -
37#[derive(Debug, Default)]
38#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
39#[cfg_attr(feature = "serde", serde(default))]
40pub struct GltfTexture {
41    /// Optional name of the texture
42    pub name: String,
43    /// Image index (source)
44    #[cfg_attr(feature = "serde", serde(rename = "source"))]
45    pub image: ImageIndex,
46    /// Sampler index
47    pub sampler: SamplerIndex,
48}
49
50impl GltfTexture {
51    pub fn image(&self) -> ImageIndex {
52        self.image
53    }
54    pub fn sampler(&self) -> SamplerIndex {
55        self.sampler
56    }
57}
58
59//ip Named for GltfTexture
60impl Named for GltfTexture {
61    type Index = TextureIndex;
62    fn is_name(&self, name: &str) -> bool {
63        self.name == name
64    }
65}