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