pub struct Mesh { /* private fields */ }Expand description
Triangle mesh geometry decoded from, or prepared for, a Draco bitstream.
A mesh owns triangle topology and dereferences to its underlying
PointCloud, where attributes and metadata are stored.
Implementations§
Source§impl Mesh
impl Mesh
Sourcepub fn into_point_cloud(self) -> PointCloud
pub fn into_point_cloud(self) -> PointCloud
Takes the underlying point cloud, dropping the triangle topology.
A mesh already is a point cloud with faces on top, and Deref lends
that half out for reading. Encoding it as a point cloud needs it owned:
a reader that produced a mesh from a file with no faces — a PLY point
cloud, a file whose payload is per-point attributes — otherwise has no
way to reach PointCloudEncoder without
rebuilding every attribute.
Faces are discarded rather than triangulated into anything; this is for geometry that had none to begin with, and for callers that have decided the connectivity is not what they are encoding.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drops every face and everything the underlying point cloud holds, keeping the allocated capacity of both lists.
What a decode does to the mesh it is given, so that decoding into one that already holds geometry replaces it rather than adding to it.
Sourcepub fn set_face(&mut self, face_id: FaceIndex, face: Face)
pub fn set_face(&mut self, face_id: FaceIndex, face: Face)
Sets a face, growing the face list with zeroed faces when needed.
Sourcepub fn set_faces_from_corner_vertices(
&mut self,
corner_to_vertex_map: &[VertexIndex],
)
pub fn set_faces_from_corner_vertices( &mut self, corner_to_vertex_map: &[VertexIndex], )
Bulk-set all faces from a flat u32 index array (3 indices per face).
Assumes set_num_faces has already been called with the right count.
Fills every face from a corner table’s corner-to-vertex map.
The map lays the three corners of face f at 3f..3f + 3, in the
order a face stores them, so an edgebreaker decode without attribute
seams – where a corner-table vertex index is a point index – is a
straight copy. Reading it back through vertex/vertex_after/
vertex_before instead costs three bounds-checked Option lookups
and two modular corner computations per face for indices already
known to be consecutive: 51 instructions per face against upstream’s
23, on a table whose bounds the caller’s consistency scan has just
proved.
pub fn set_faces_from_flat_indices(&mut self, indices: &[u32])
Sourcepub fn set_faces_from_u8_indices(&mut self, bytes: &[u8])
pub fn set_faces_from_u8_indices(&mut self, bytes: &[u8])
Bulk-set all faces from tightly packed u8 indices.
Assumes set_num_faces has already been called with the right count.
Sourcepub fn set_faces_from_le_u16_indices(&mut self, bytes: &[u8])
pub fn set_faces_from_le_u16_indices(&mut self, bytes: &[u8])
Bulk-set all faces from tightly packed little-endian u16 indices.
Assumes set_num_faces has already been called with the right count.
Sourcepub fn set_faces_from_le_u32_indices(&mut self, bytes: &[u8])
pub fn set_faces_from_le_u32_indices(&mut self, bytes: &[u8])
Bulk-set all faces from tightly packed little-endian u32 indices.
Assumes set_num_faces has already been called with the right count.
Sourcepub fn set_face_from_indices(&mut self, face_id: usize, indices: [u32; 3])
pub fn set_face_from_indices(&mut self, face_id: usize, indices: [u32; 3])
Sets one face from raw u32 point ids.
Sourcepub fn faces(&self) -> &[Face] ⓘ
pub fn faces(&self) -> &[Face] ⓘ
Every face’s point indices, in face order.
For a caller that walks all of them: as_flattened() on the result is
the mesh’s corners in the corner table’s own order, which lets a walk
over both zip two slices instead of deriving a corner index from a face
index and re-proving the bound at each of them.
Sourcepub fn set_num_faces(&mut self, num_faces: usize)
pub fn set_num_faces(&mut self, num_faces: usize)
Resizes the face list, filling new faces with point index zero.
Sourcepub fn try_set_num_faces(&mut self, num_faces: usize) -> Status
pub fn try_set_num_faces(&mut self, num_faces: usize) -> Status
Fallibly resizes the face list.
Sourcepub fn deduplicate_point_ids(&mut self)
pub fn deduplicate_point_ids(&mut self)
Merges points whose attribute values all coincide, and rewrites the faces that named them.
Port of upstream’s Mesh::ApplyPointIdDeduplication path: the point
cloud merges the points, then the faces follow the same map. Pair it
with deduplicate_attribute_values,
which has to run first – two vertices carrying equal bytes hold
distinct value indices until it merges them, so nothing here would see
them as one point.
Sourcepub fn deduplicate_point_ids_returning_map(&mut self) -> Vec<u32>
pub fn deduplicate_point_ids_returning_map(&mut self) -> Vec<u32>
deduplicate_point_ids, additionally
handing back the old-point-to-new-point map – identity when nothing
merged – for a caller that has to carry data addressed by the
original point (an FBX corner’s skin weight or morph delta) onto the
point that now stands in for it.
Sourcepub fn remove_points_unused_by_faces(&mut self)
pub fn remove_points_unused_by_faces(&mut self)
Drops points no face names, and then the attribute values left with no point, keeping everything else in the order it was in.
Nothing downstream keeps such a point: both this encoder and upstream’s
write the geometry the connectivity reaches, so an unreferenced vertex
never reaches a decoder either way. What it does reach is the
quantization range, which is computed over the values an attribute
holds – so a stray vertex far from the mesh spends bits on empty space
and every coordinate that survives comes back less precisely. Measured
on a unit triangle with a fourth vertex at 1000, 1000, 1000: the
encoded size does not move and 1.0 returns as 1.007095.
Upstream keeps them, which is why COMPATIBILITY.md carries this. Its
readers size a position attribute from the vertex list before they know
which entries the faces use, and it has no step that revisits the
question – RemoveUnusedValues exists there but is compiled into the
transcoder alone.
Sourcepub fn finalize(&mut self) -> Status
pub fn finalize(&mut self) -> Status
How a reader finishes a mesh it built from scratch, before anything encodes it: merges bit-identical attribute values, then merges the points those values made identical, then drops what no face names.
The first two steps are upstream’s TriangleSoupMeshBuilder::Finalize,
and their order is load-bearing: two vertices carrying equal bytes hold
distinct value indices until the values merge, so a point merge run
first would find nothing to do.
Doing this is not tidying. Until the points merge, the triangles around two vertices at one position share a vertex rather than an edge, so the encoder sees two connected components where upstream sees one and writes a larger stream that decodes to more points than it was given.
The third step goes past upstream, which stops after the merge. See
remove_points_unused_by_faces
for why an unreferenced point still costs precision, and
COMPATIBILITY.md for the departure it records.
Sourcepub fn finalize_returning_corner_map(&mut self) -> Result<Vec<u32>, DracoError>
pub fn finalize_returning_corner_map(&mut self) -> Result<Vec<u32>, DracoError>
finalize, additionally handing back the point-merge
map – what a caller that built one point per polygon corner needs, and
the readers that build a vertex list do not.
An FBX corner carries its own skin weight and morph delta, so such a caller has to move that data onto whichever point now stands in for the corner. The unused-point drop cannot disturb the map: a mesh built one point per corner has, by construction, no point that starts out unused.
Sourcepub fn renumber_points_in_face_order(&mut self)
pub fn renumber_points_in_face_order(&mut self)
Renumbers points into the order the faces first name them, dropping any point no face names at all.
Not a deduplication, despite what this was once called, and not
upstream’s operation: deduplicate_point_ids
merges points whose values coincide and keeps the order they arrived
in, while this one merges nothing and reorders everything.
What it reproduces is the numbering upstream’s OBJ reader ends up with, because that reader emits one point per face corner and its point order is therefore corner order already. A reader whose points arrive as a vertex list – PLY, glTF – gets a different numbering from this than upstream gets from its own pair, so it is not a substitute for them.
Methods from Deref<Target = PointCloud>§
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drops every attribute, point and the metadata, keeping the allocated capacity of the attribute list and the attributes’ own storage.
What a decode does to the cloud it is given, so that decoding into one
that already holds geometry replaces it rather than adding to it. The
values and the explicit maps of the dropped attributes are kept empty
and handed to the next attributes added, so the caller decoding many
files into one cloud reuses the allocations of the last one; the cloud
therefore holds the memory of the largest geometry it has decoded until
release_spare_storage or drop.
Sourcepub fn release_spare_storage(&mut self)
pub fn release_spare_storage(&mut self)
Frees the storage clear retained from earlier
attributes.
Sourcepub fn set_num_points(&mut self, num_points: usize)
pub fn set_num_points(&mut self, num_points: usize)
Sets the number of logical points.
Sourcepub fn add_attribute(&mut self, attribute: PointAttribute) -> i32
pub fn add_attribute(&mut self, attribute: PointAttribute) -> i32
Adds an attribute and assigns it a unique id matching its attribute id.
Sourcepub fn add_attribute_preserve_unique_id(
&mut self,
attribute: PointAttribute,
) -> i32
pub fn add_attribute_preserve_unique_id( &mut self, attribute: PointAttribute, ) -> i32
Adds an attribute while preserving its existing unique id.
Sourcepub fn set_attribute(&mut self, att_id: i32, attribute: PointAttribute)
pub fn set_attribute(&mut self, att_id: i32, attribute: PointAttribute)
Places an attribute at att_id, growing the attribute list if needed.
Mirrors C++ PointCloud::SetAttribute: the attribute’s unique id is set
to att_id. Any vacancies created when growing the list are filled with
empty attributes.
Sourcepub fn num_attributes(&self) -> i32
pub fn num_attributes(&self) -> i32
Returns the number of attributes.
Sourcepub fn attribute_id_by_unique_id(&self, unique_id: u32) -> i32
pub fn attribute_id_by_unique_id(&self, unique_id: u32) -> i32
Returns the attribute id for the given Draco unique id, or -1.
Mirrors C++ PointCloud::GetAttributeIdByUniqueId.
Sourcepub fn attribute_by_unique_id(&self, unique_id: u32) -> Option<&PointAttribute>
pub fn attribute_by_unique_id(&self, unique_id: u32) -> Option<&PointAttribute>
Returns the attribute with the given Draco unique id.
Mirrors C++ PointCloud::GetAttributeByUniqueId.
Sourcepub fn attribute(&self, att_id: i32) -> &PointAttribute
pub fn attribute(&self, att_id: i32) -> &PointAttribute
Returns an attribute by attribute id.
Sourcepub fn try_attribute(&self, att_id: i32) -> Result<&PointAttribute, DracoError>
pub fn try_attribute(&self, att_id: i32) -> Result<&PointAttribute, DracoError>
Fallibly returns an attribute by attribute id.
Sourcepub fn attribute_mut(&mut self, att_id: i32) -> &mut PointAttribute
pub fn attribute_mut(&mut self, att_id: i32) -> &mut PointAttribute
Returns a mutable attribute by attribute id.
Sourcepub fn try_attribute_mut(
&mut self,
att_id: i32,
) -> Result<&mut PointAttribute, DracoError>
pub fn try_attribute_mut( &mut self, att_id: i32, ) -> Result<&mut PointAttribute, DracoError>
Fallibly returns a mutable attribute by attribute id.
Sourcepub fn named_attribute_id(&self, att_type: GeometryAttributeType) -> i32
pub fn named_attribute_id(&self, att_type: GeometryAttributeType) -> i32
Returns the first attribute id with the requested semantic type, or -1.
Sourcepub fn named_attribute(
&self,
att_type: GeometryAttributeType,
) -> Option<&PointAttribute>
pub fn named_attribute( &self, att_type: GeometryAttributeType, ) -> Option<&PointAttribute>
Returns the first attribute with the requested semantic type.
Sourcepub fn deduplicate_attribute_values(&mut self) -> Status
pub fn deduplicate_attribute_values(&mut self) -> Status
Returns the number of logical points. Merges bit-identical values in every attribute.
Port of upstream’s PointCloud::DeduplicateAttributeValues, which its
OBJ and PLY readers and its TriangleSoupMeshBuilder all run before
the encoder sees the geometry. Fails on an attribute whose type
upstream’s own switch does not cover, which is what upstream does too.
Sourcepub fn deduplicate_point_ids(&mut self)
pub fn deduplicate_point_ids(&mut self)
Merges points whose attribute values all coincide, keeping the order in which they first appear.
Port of upstream’s PointCloud::DeduplicatePointIds. Two points are the
same point when every attribute maps them to the same value, which is
why deduplicate_attribute_values
runs first: without it two vertices carrying equal bytes still hold
distinct value indices and nothing merges.
pub fn num_points(&self) -> usize
Sourcepub fn metadata(&self) -> Option<&GeometryMetadata>
pub fn metadata(&self) -> Option<&GeometryMetadata>
Returns geometry metadata, if present.
Sourcepub fn metadata_mut(&mut self) -> Option<&mut GeometryMetadata>
pub fn metadata_mut(&mut self) -> Option<&mut GeometryMetadata>
Returns mutable geometry metadata, if present.
Sourcepub fn metadata_or_insert(&mut self) -> &mut GeometryMetadata
pub fn metadata_or_insert(&mut self) -> &mut GeometryMetadata
Returns geometry metadata, inserting an empty block when absent.
Sourcepub fn set_metadata(&mut self, metadata: Option<GeometryMetadata>)
pub fn set_metadata(&mut self, metadata: Option<GeometryMetadata>)
Replaces geometry metadata.
Sourcepub fn attribute_metadata_by_unique_id(
&self,
attribute_unique_id: u32,
) -> Option<&AttributeMetadata>
pub fn attribute_metadata_by_unique_id( &self, attribute_unique_id: u32, ) -> Option<&AttributeMetadata>
Finds per-attribute metadata by Draco attribute unique id.
Sourcepub fn attribute_metadata_by_string_entry(
&self,
entry_name: &str,
entry_value: &str,
) -> Option<&AttributeMetadata>
pub fn attribute_metadata_by_string_entry( &self, entry_name: &str, entry_value: &str, ) -> Option<&AttributeMetadata>
Finds per-attribute metadata by a string metadata entry.
Sourcepub fn set_attribute_metadata(
&mut self,
att_id: i32,
metadata: Metadata,
) -> Result<(), DracoError>
pub fn set_attribute_metadata( &mut self, att_id: i32, metadata: Metadata, ) -> Result<(), DracoError>
Sets metadata for an attribute id.