openconfiguration 1.7.0

OpenConfiguration (OC) is a modular, efficient and flexible approach for the uni-directional exchange of visual e-commerce configurations.
Documentation
use std::collections::HashMap;

use openconfiguration_derive::Visitable;
use serde::{Deserialize, Serialize};
use serde_json::Value;

use crate::{impl_visitable_noop, support::Visitor};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Visitable, Default)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(deny_unknown_fields))]
#[serde(rename_all = "camelCase", rename = "igGeometry")]
/// ig Geometry representation, mesh based.
pub struct Geometry {
    /// The mandatory format of the optional preview mesh.
    pub preview_format: Option<GeometryPreviewFormat>,

    /// An optional mesh to be displayed until the main mesh is loaded.
    #[visitable(visit_with = "crate::support::visit_path")]
    pub preview: Option<String>,

    /// The mandatory format of the optional preview mesh.

    /// Version: OC 1.1	  
    pub collider_format: Option<GeometryColliderFormat>,

    /// An optional mesh to be used for collision detection.
    ///
    /// Version: OC 1.1
    #[visitable(visit_with = "crate::support::visit_path")]
    pub collider: Option<String>,

    /// The mandatory format of the optional main mesh.
    pub mesh_format: Option<GeometryMeshFormat>,

    /// An optional mesh to be displayed as main mesh. Note, in some case a
    /// geometry does not provide it, e.g. for super deformations.
    #[visitable(visit_with = "crate::support::visit_path")]
    pub mesh: Option<String>,

    /// The mandatory format of the optional normal map.
    pub normal_map_format: Option<GeometryNormalMapFormat>,

    /// An optional normal map to be applied to the main mesh.
    #[visitable(visit_with = "crate::support::visit_path")]
    pub normal_map: Option<String>,

    /// Optional Normalmaps to be blended over, if given replaces "normalMap" for glb
    #[serde(
        deserialize_with = "crate::utils::deserialize_optional_map_without_null_values",
        default
    )]
    #[visitable(visit_with = "visit_map_with_paths")]
    pub extra_normal_maps: Option<HashMap<String, String>>,

    /// The mandatory format of the optional deformation.
    /// Allowed formats are "FFD" and "JSON".
    pub deformation_format: Option<GeometryDeformationFormat>,

    /// Deformation description.
    #[visitable(visit_with = "crate::support::visit_path")]
    pub deformation: Option<String>,

    #[serde(rename = "deformationXDataFormat")]
    /// The mandatory format of the optional shape-key file, or other extra deformation data.
    pub deformation_xdata_format: Option<GeometryDeformationXDataFormat>,

    #[serde(rename = "deformationXData")]
    #[visitable(visit_with = "crate::support::visit_path")]
    /// Shape-key file or other extra data, belonging to a deformation.
    pub deformation_xdata: Option<String>,

    /// Optional geometry-related parameters, to be resolved at client-side.
    ///
    /// "Complexity":
    /// Describes the nominal complexity of the geometry. 100 (default) is
    /// a medium-sized, medium-complex object, such as a pillow for instance.
    /// For bigger and/or more complex objects, use complexity 200 or higher.
    /// For smaller and/or more simple objects, use complexity 50 or lower.
    ///
    /// "SuperDeformation":
    /// Marks the geometry as a super deformation. The assigned deformation
    /// will be applied to the local geometry (if any) as well as recursively
    /// to all child geometries.
    /// Target type: Boolean
    ///
    /// "NormalMapTiling":
    /// The Geometry Normal Map should be repeated instead of clamped outside 0..1 UV range
    /// Some 3D libraries call this "wrapping mode" if true set to "repeat", default is "clamp"
    /// Target type: Boolean
    /// Version: OC 1.1
    ///
    /// "NormalMapStrength":
    /// Changes the influence of the Geometry Normal Map in light calculation, default: 1,
    /// by multiplying the strength of the geometry normal map with this factor.
    /// Target type: number
    /// Version: OC 1.1
    ///
    /// "RenderOrder"
    /// Render order for 3D libraries that render transparent objects in a separate, second pass, back to front.
    /// Negative values are rendered earlier in the process, positive values later, 0 is default and keeps library ordering.
    /// Raytracers and renderers with advanced transparency handling must ignore this!
    /// This is NOT intended for effects different from a natural/physical correct scene, i.e. it can not be used for
    /// artistic effects!
    /// Target type: number
    /// Version: OC 1.1
    ///
    /// "NormalMapBlending"
    /// If there is a 0 and a second 100 % GeoNormalMap,
    /// this maps times (0 .. 100 percent to mixfactors 0 .. 100 percent)
    /// Format is t<time>m<mix> in percents, t0 and t100 are mandatory!
    /// Format example is "t0m0t50m50t100m100"
    /// Target type: string
    /// Version: OC 1.6
    #[serde(
        deserialize_with = "crate::utils::deserialize_optional_map_without_null_values",
        default
    )]
    pub parameters: Option<HashMap<String, Value>>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum GeometryPreviewFormat {
    OpenCTM,
    OBJ,
    GLB,
    FBX,
}

impl_visitable_noop!(GeometryPreviewFormat);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum GeometryColliderFormat {
    OpenCTM,
    OBJ,
    GLB,
    FBX,
}

impl_visitable_noop!(GeometryColliderFormat);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum GeometryMeshFormat {
    OpenCTM,
    OBJ,
    GLB,
    FBX,
    DWF,
}

impl_visitable_noop!(GeometryMeshFormat);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum GeometryNormalMapFormat {
    JPEG,
    PNG,
}

impl_visitable_noop!(GeometryNormalMapFormat);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum GeometryDeformationFormat {
    FFD,
    JSON,
}

impl_visitable_noop!(GeometryDeformationFormat);

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum GeometryDeformationXDataFormat {
    #[serde(rename = "glTF")]
    GLTF,
    GLB,
}

impl_visitable_noop!(GeometryDeformationXDataFormat);

fn visit_map_with_paths(value: &mut Option<HashMap<String, String>>, visitor: &mut dyn Visitor) {
    if let Some(map) = value {
        for (_key, value) in map {
            visitor.visit_path(value);
        }
    }
}