Skip to main content

MeshEncoder

Struct MeshEncoder 

Source
pub struct MeshEncoder { /* private fields */ }
Available on crate feature encoder only.
Expand description

Encoder for Draco triangle mesh bitstreams.

A MeshEncoder takes a Mesh plus EncoderOptions and writes a self-contained .drc bitstream (header, optional metadata, connectivity, and attributes) into an EncoderBuffer. The encoding method (EdgeBreaker or sequential), prediction schemes, and quantization are selected from the options, mirroring the C++ MeshEncoder/ExpertEncoder configuration.

After a successful encode, per-attribute and per-face details are available via encoded_mesh_info.

§Examples

Build a single-triangle mesh, encode it, and decode it back:

use draco_core::{
    DataType, DecoderBuffer, EncoderBuffer, EncoderOptions, FaceIndex,
    GeometryAttributeType, Mesh, MeshDecoder, MeshEncoder, PointAttribute,
};

// One triangle with a float32 position attribute (3 vertices).
let mut mesh = Mesh::new();
let mut position = PointAttribute::new();
position.init(GeometryAttributeType::Position, 3, DataType::Float32, false, 3);
let coords: [f32; 9] = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0];
for (i, value) in coords.iter().enumerate() {
    position.buffer_mut().write(i * 4, &value.to_le_bytes());
}
mesh.add_attribute(position);
mesh.set_num_faces(1);
mesh.set_face(FaceIndex(0), [0u32.into(), 1u32.into(), 2u32.into()]);

// Encode to a Draco bitstream.
let mut encoder = MeshEncoder::new();
encoder.set_mesh(mesh);
let mut buffer = EncoderBuffer::new();
encoder.encode(&EncoderOptions::new(), &mut buffer)?;

// Decode it back.
let mut decoded = Mesh::new();
MeshDecoder::new().decode(&mut DecoderBuffer::new(buffer.data()), &mut decoded)?;
assert_eq!(decoded.num_faces(), 1);

Implementations§

Source§

impl MeshEncoder

Source

pub fn new() -> Self

Creates an encoder without an assigned mesh.

Source

pub fn set_mesh(&mut self, mesh: Mesh)

Assigns the mesh to encode.

Source

pub fn mesh(&self) -> Option<&Mesh>

Returns the assigned mesh, if any.

Source

pub fn num_encoded_faces(&self) -> usize

Returns the number of faces encoded by the last successful encode.

Source

pub fn corner_table(&self) -> Option<&CornerTable>

Returns the corner table built during the last mesh encode, if any.

Source

pub fn encoded_mesh_info(&self) -> Option<&EncodedMeshInfo>

Returns information captured during the last successful mesh encode.

Source

pub fn encode( &mut self, options: &EncoderOptions, out_buffer: &mut EncoderBuffer, ) -> Status

Encodes the assigned mesh into an output buffer.

A mesh must have been provided with set_mesh first. On success the bitstream is appended to out_buffer and encoded_mesh_info is populated.

§Errors

Returns an error if no mesh was set, if the requested encoding method or options are unsupported, or if attribute encoding fails.

Trait Implementations§

Source§

impl Default for MeshEncoder

Source§

fn default() -> Self

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

impl GeometryEncoder for MeshEncoder

Source§

fn point_cloud(&self) -> Option<&PointCloud>

Returns point-cloud geometry when available.
Source§

fn mesh(&self) -> Option<&Mesh>

Returns mesh geometry when available.
Source§

fn corner_table(&self) -> Option<&CornerTable>

Returns mesh corner-table topology when available.
Source§

fn options(&self) -> &EncoderOptions

Returns the active encoder options.
Source§

fn get_geometry_type(&self) -> EncodedGeometryType

Returns the encoded geometry type.
Source§

fn get_encoding_method(&self) -> Option<i32>

Returns the forced encoding method, if one is active.
Source§

fn get_data_to_corner_map(&self) -> Option<&[u32]>

Returns a data-to-corner map for mesh attribute prediction, if present.
Source§

fn get_vertex_to_data_map(&self) -> Option<&[i32]>

Returns a vertex-to-data map for mesh attribute prediction, if present.

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.