Skip to main content

gltf_json/
image.rs

1use crate::validation::Validate;
2use crate::{buffer, extensions, Extras, Index};
3use gltf_derive::Validate;
4use serde_derive::{Deserialize, Serialize};
5
6/// All valid MIME types.
7pub const VALID_MIME_TYPES: &[&str] = &[
8    "image/jpeg",
9    "image/png",
10    #[cfg(feature = "EXT_texture_webp")]
11    "image/webp",
12];
13
14/// Image data used to create a texture.
15#[derive(Clone, Debug, Deserialize, Serialize, Validate)]
16pub struct Image {
17    /// The index of the buffer view that contains the image. Use this instead of
18    /// the image's uri property.
19    #[serde(rename = "bufferView")]
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub buffer_view: Option<Index<buffer::View>>,
22
23    /// The image's MIME type.
24    #[serde(rename = "mimeType")]
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub mime_type: Option<MimeType>,
27
28    /// Optional user-defined name for this object.
29    #[cfg(feature = "names")]
30    #[cfg_attr(feature = "names", serde(skip_serializing_if = "Option::is_none"))]
31    pub name: Option<String>,
32
33    /// The uri of the image.  Relative paths are relative to the .gltf file.
34    /// Instead of referencing an external file, the uri can also be a data-uri.
35    /// The image format must be jpg or png.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub uri: Option<String>,
38
39    /// Extension specific data.
40    #[serde(default, skip_serializing_if = "Option::is_none")]
41    pub extensions: Option<extensions::image::Image>,
42
43    /// Optional application specific data.
44    #[serde(default)]
45    #[cfg_attr(feature = "extras", serde(skip_serializing_if = "Option::is_none"))]
46    #[cfg_attr(not(feature = "extras"), serde(skip_serializing))]
47    pub extras: Extras,
48}
49
50/// An image MIME type.
51#[derive(Clone, Debug, Deserialize, Serialize)]
52pub struct MimeType(pub String);
53
54impl Validate for MimeType {}