Skip to main content

ObjDecoder

Struct ObjDecoder 

Source
pub struct ObjDecoder { /* private fields */ }
Expand description

Wavefront OBJ decoder.

Decodes a self-contained OBJ document into a Scene3D. Companion MTL files referenced by mtllib directives are not auto-resolved (the decoder has no file-system context); the material names land in Primitive::extras["obj:usemtl"] and the library file names land in Scene3D::extras["obj:mtllibs"] so the caller can fetch them and merge via crate::mtl::merge_materials_into_scene.

Use obj::parse_obj_with_resolver directly when MTL bytes are already available.

Implementations§

Source§

impl ObjDecoder

Source

pub fn new() -> Self

Construct a fresh decoder. Equivalent to ObjDecoder::default().

Source

pub fn with_curve_tessellation(self, samples: u32) -> Self

Enable tessellation of cstype free-form curves and surf surfaces:

  • cstype bezier / cstype rat bezier — de Casteljau evaluation on the [0, 1] basis domain (1D curv curves and 2D surf surfaces via tensor-product de Casteljau).
  • cstype bspline / cstype rat bspline — Cox-deBoor recursive basis on the knot vector supplied by the most- recent parm u … directive (1D curv and 2D surf surfaces via tensor-product Cox-deBoor).
  • cstype cardinal / cstype rat cardinal — cubic Catmull-Rom (1D curv and 2D surf surfaces via tensor-product Cardinal evaluation).
  • cstype taylor / cstype rat taylor — direct polynomial evaluation (1D curv Horner-rule and 2D surf surfaces via tensor-product bivariate Horner-rule evaluation).
  • cstype bmatrix — 1D curv only.

samples is the number of intervals. A curv curve yields a LineStrip of samples + 1 vertices; a Bezier surf surface yields a Topology::Triangles grid of (samples + 1)² vertices (so samples == 32 produces a 33×33 lattice, smooth enough for diagnostic display without overwhelming the buffer).

Curve primitives land on a synthetic mesh named "obj:curves"; Bezier surface primitives land on "obj:surfaces". Each carries extras["obj:tessellated_curve"] == true (surfaces also carry extras["obj:tessellated_surface"] == true) so downstream consumers that don’t want the derived geometry can filter it out. The free-form directive sequence remains preserved in Scene3D::extras["obj:freeform_directives"] so re-encoding regenerates the original cstype / deg / curv / surf / parm / end section.

samples == 0 (the default) disables tessellation, matching the round 1-6 behaviour. Bezier / B-spline / Cardinal / Taylor surf surfaces are tessellated; basis-matrix surfaces remain captured-only.

Trait Implementations§

Source§

impl Debug for ObjDecoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ObjDecoder

Source§

fn default() -> ObjDecoder

Returns the “default value” for a type. Read more
Source§

impl Mesh3DDecoder for ObjDecoder

Source§

fn decode(&mut self, bytes: &[u8]) -> Result<Scene3D>

Parse bytes into a Scene3D.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.