pub struct MeshEncoder { /* private fields */ }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
impl MeshEncoder
Sourcepub fn num_encoded_faces(&self) -> usize
pub fn num_encoded_faces(&self) -> usize
Returns the number of faces encoded by the last successful encode.
Sourcepub fn corner_table(&self) -> Option<&CornerTable>
pub fn corner_table(&self) -> Option<&CornerTable>
Returns the corner table built during the last mesh encode, if any.
Sourcepub fn encoded_mesh_info(&self) -> Option<&EncodedMeshInfo>
pub fn encoded_mesh_info(&self) -> Option<&EncodedMeshInfo>
Returns information captured during the last successful mesh encode.
Sourcepub fn encode(
&mut self,
options: &EncoderOptions,
out_buffer: &mut EncoderBuffer,
) -> Status
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.