openusd-schemas 0.7.0

Typed Rust APIs for USD's standard schemas (UsdGeom, UsdShade, UsdSkel, UsdPhysics, and more), built on openusd
Documentation
//! `UsdGeomGprim` — the base for geometric primitives.

use openusd::Result;

use openusd::sdf;
use openusd::usd::Attribute;

use super::Boundable;
use super::tokens as tok;

/// A geometric primitive — the base for the intrinsic shapes, meshes, and
/// curves (C++ `UsdGeomGprim`). Inherits [`Boundable`] and adds the
/// orientation/sidedness attributes shared by all gprims.
pub trait Gprim: Boundable {
    /// Whether the gprim's surfaces should be shaded and rendered from both
    /// sides rather than back-face culled to its [`orientation`](Self::orientation_attr).
    /// C++ `UsdGeomGprim::GetDoubleSidedAttr`.
    ///
    /// Type `bool`. Fetch with `get::<bool>()?`.
    fn double_sided_attr(&self) -> Attribute {
        self.prim().attribute(tok::A_DOUBLE_SIDED)
    }

    /// Author `doubleSided` (`uniform bool`), returning its handle
    /// (C++ `CreateDoubleSidedAttr`).
    fn create_double_sided_attr(&self) -> Result<Attribute> {
        Ok(self
            .prim()
            .create_attribute(tok::A_DOUBLE_SIDED, sdf::ValueTypeName::BOOL)?
            .set_custom(false)?
            .set_variability(sdf::Variability::Uniform)?)
    }

    /// The winding order that decides which side of each face is the front:
    /// `rightHanded` (counter-clockwise) or `leftHanded` (clockwise).
    /// C++ `UsdGeomGprim::GetOrientationAttr`.
    ///
    /// Type `token`. Fetch with `get::<Orientation>()?`.
    fn orientation_attr(&self) -> Attribute {
        self.prim().attribute(tok::A_ORIENTATION)
    }

    /// Author `orientation` (`uniform token`), returning its handle
    /// (C++ `CreateOrientationAttr`).
    fn create_orientation_attr(&self) -> Result<Attribute> {
        Ok(self
            .prim()
            .create_attribute(tok::A_ORIENTATION, sdf::ValueTypeName::TOKEN)?
            .set_custom(false)?
            .set_variability(sdf::Variability::Uniform)?)
    }

    /// The fallback per-vertex/per-element color primvar used to display the
    /// gprim when no bound material provides one (RGB in linear space).
    /// C++ `UsdGeomGprim::GetDisplayColorAttr`.
    ///
    /// Type `color3f[]`. Fetch with `get::<Vec<gf::Vec3f>>()?`.
    fn display_color_attr(&self) -> Attribute {
        self.prim().attribute(tok::A_DISPLAY_COLOR)
    }

    /// Author `primvars:displayColor` (`color3f[]`), returning its handle
    /// (C++ `CreateDisplayColorAttr`). Set its `interpolation` metadata to
    /// describe per-prim vs. per-element values.
    fn create_display_color_attr(&self) -> Result<Attribute> {
        Ok(self
            .prim()
            .create_attribute(tok::A_DISPLAY_COLOR, sdf::ValueTypeName::COLOR3F_ARRAY)?
            .set_custom(false)?)
    }

    /// The fallback display opacity primvar paired with
    /// [`displayColor`](Self::display_color_attr): 1.0 is fully opaque, 0.0
    /// fully transparent. C++ `UsdGeomGprim::GetDisplayOpacityAttr`.
    ///
    /// Type `float[]`. Fetch with `get::<Vec<f32>>()?`.
    fn display_opacity_attr(&self) -> Attribute {
        self.prim().attribute(tok::A_DISPLAY_OPACITY)
    }

    /// Author `primvars:displayOpacity` (`float[]`), returning its handle
    /// (C++ `CreateDisplayOpacityAttr`).
    fn create_display_opacity_attr(&self) -> Result<Attribute> {
        Ok(self
            .prim()
            .create_attribute(tok::A_DISPLAY_OPACITY, sdf::ValueTypeName::FLOAT_ARRAY)?
            .set_custom(false)?)
    }
}