pub const ALL: &str = ".all";
pub const ROOT: &str = ".root";
pub const GLOBAL: &str = ".global";
pub const SET: &str = "set";
pub const SHADER: &str = "shader";
pub const ATTRIBUTES: &str = "attributes";
pub const TRANSFORM: &str = "transform";
pub const INSTANCES: &str = "instances";
pub const PLANE: &str = "plane";
pub const MESH: &str = "mesh";
pub const FACE_SET: &str = "faceset";
pub const CURVES: &str = "curves";
pub const PARTICLES: &str = "particles";
pub const NURBS: &str = "nurbs";
pub const PROCEDURAL: &str = "procedural";
pub const VOLUME: &str = "volume";
pub const ENVIRONMENT: &str = "environment";
pub const ORTHOGRAPHIC_CAMERA: &str = "orthographiccamera";
pub const PERSPECTIVE_CAMERA: &str = "perspectivecamera";
pub const FISHEYE_CAMERA: &str = "fisheyecamera";
pub const CYLINDRICAL_CAMERA: &str = "cylindricalcamera";
pub const SPHERICAL_CAMERA: &str = "sphericalcamera";
pub const OUTPUT_DRIVER: &str = "outputdriver";
pub const OUTPUT_LAYER: &str = "outputlayer";
pub const SCREEN: &str = "screen";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum NodeType {
All,
Root,
Global,
Set,
Shader,
Attributes,
Transform,
Instances,
Plane,
Mesh,
FaceSet,
Curves,
Particles,
Nurbs,
Procedural,
Volume,
Environment,
OrthographicCamera,
PerspectiveCamera,
FisheyeCamera,
CylindricalCamera,
SphericalCamera,
OutputDriver,
OutputLayer,
Screen,
}
impl NodeType {
#[inline]
pub const fn as_str(&self) -> &'static str {
match self {
Self::All => ALL,
Self::Root => ROOT,
Self::Global => GLOBAL,
Self::Set => SET,
Self::Shader => SHADER,
Self::Attributes => ATTRIBUTES,
Self::Transform => TRANSFORM,
Self::Instances => INSTANCES,
Self::Plane => PLANE,
Self::Mesh => MESH,
Self::FaceSet => FACE_SET,
Self::Curves => CURVES,
Self::Particles => PARTICLES,
Self::Nurbs => NURBS,
Self::Procedural => PROCEDURAL,
Self::Volume => VOLUME,
Self::Environment => ENVIRONMENT,
Self::OrthographicCamera => ORTHOGRAPHIC_CAMERA,
Self::PerspectiveCamera => PERSPECTIVE_CAMERA,
Self::FisheyeCamera => FISHEYE_CAMERA,
Self::CylindricalCamera => CYLINDRICAL_CAMERA,
Self::SphericalCamera => SPHERICAL_CAMERA,
Self::OutputDriver => OUTPUT_DRIVER,
Self::OutputLayer => OUTPUT_LAYER,
Self::Screen => SCREEN,
}
}
pub fn from_name(s: &str) -> Option<Self> {
Some(match s {
ALL => Self::All,
ROOT => Self::Root,
GLOBAL => Self::Global,
SET => Self::Set,
SHADER => Self::Shader,
ATTRIBUTES => Self::Attributes,
TRANSFORM => Self::Transform,
INSTANCES => Self::Instances,
PLANE => Self::Plane,
MESH => Self::Mesh,
FACE_SET => Self::FaceSet,
CURVES => Self::Curves,
PARTICLES => Self::Particles,
NURBS => Self::Nurbs,
PROCEDURAL => Self::Procedural,
VOLUME => Self::Volume,
ENVIRONMENT => Self::Environment,
ORTHOGRAPHIC_CAMERA => Self::OrthographicCamera,
PERSPECTIVE_CAMERA => Self::PerspectiveCamera,
FISHEYE_CAMERA => Self::FisheyeCamera,
CYLINDRICAL_CAMERA => Self::CylindricalCamera,
SPHERICAL_CAMERA => Self::SphericalCamera,
OUTPUT_DRIVER => Self::OutputDriver,
OUTPUT_LAYER => Self::OutputLayer,
SCREEN => Self::Screen,
_ => return None,
})
}
}
impl std::fmt::Display for NodeType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn node_type_round_trip() {
let types = [
NodeType::All,
NodeType::Root,
NodeType::Global,
NodeType::Set,
NodeType::Shader,
NodeType::Attributes,
NodeType::Transform,
NodeType::Instances,
NodeType::Plane,
NodeType::Mesh,
NodeType::FaceSet,
NodeType::Curves,
NodeType::Particles,
NodeType::Nurbs,
NodeType::Procedural,
NodeType::Volume,
NodeType::Environment,
NodeType::OrthographicCamera,
NodeType::PerspectiveCamera,
NodeType::FisheyeCamera,
NodeType::CylindricalCamera,
NodeType::SphericalCamera,
NodeType::OutputDriver,
NodeType::OutputLayer,
NodeType::Screen,
];
for ty in types {
let s = ty.as_str();
let parsed = NodeType::from_name(s).expect("should parse");
assert_eq!(ty, parsed);
}
}
}