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.
encode produces the bitstream and nothing else.
A caller who also wants per-attribute and per-face details of what the
encode did uses encode_with_info, which
derives them; they are not a byproduct of encoding and are not computed
for callers who do not ask.
§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 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 nothing
else is computed; use
encode_with_info to also get a
description of the encode.
§Errors
Returns an error if no mesh was set, if the requested encoding method or options are unsupported, or if attribute encoding fails.
Sourcepub fn encode_with_info(
&mut self,
options: &EncoderOptions,
out_buffer: &mut EncoderBuffer,
) -> Result<EncodedMeshInfo, DracoError>
pub fn encode_with_info( &mut self, options: &EncoderOptions, out_buffer: &mut EncoderBuffer, ) -> Result<EncodedMeshInfo, DracoError>
Encodes the assigned mesh and describes what the encode did.
The description is derived from the encode rather than produced by it,
and deriving it costs a sweep of every position for its bounds plus a
copy of the encoded point order per attribute. So it is the caller who
decides whether that work happens: encode never
does it, and this does it exactly once, here, where it was asked for.
§Errors
The same errors as encode, plus a failure to
derive the description. The bitstream in out_buffer is complete and
valid in that last case; only the description is missing.
Trait Implementations§
Source§impl Default for MeshEncoder
impl Default for MeshEncoder
Source§impl GeometryEncoder for MeshEncoder
impl GeometryEncoder for MeshEncoder
Source§fn point_cloud(&self) -> Option<&PointCloud>
fn point_cloud(&self) -> Option<&PointCloud>
Source§fn corner_table(&self) -> Option<&CornerTable>
fn corner_table(&self) -> Option<&CornerTable>
Source§fn options(&self) -> &EncoderOptions
fn options(&self) -> &EncoderOptions
Source§fn get_geometry_type(&self) -> EncodedGeometryType
fn get_geometry_type(&self) -> EncodedGeometryType
Source§fn get_encoding_method(&self) -> Option<i32>
fn get_encoding_method(&self) -> Option<i32>
Source§fn get_data_to_corner_map(&self) -> Option<&[u32]>
fn get_data_to_corner_map(&self) -> Option<&[u32]>
Source§fn get_vertex_to_data_map(&self) -> Option<&[i32]>
fn get_vertex_to_data_map(&self) -> Option<&[i32]>
Source§fn get_portable_attribute(&self, att_id: i32) -> Option<&PointAttribute>
fn get_portable_attribute(&self, att_id: i32) -> Option<&PointAttribute>
PointCloudEncoder::GetPortableAttribute.