pub struct Transaction<'m> { /* private fields */ }Expand description
An open edit on a Mesh. All writes go through it.
Every method validates its whole input before writing, so a returned validation
error leaves the transaction unchanged and usable. If a write itself fails (out of
memory), the transaction is poisoned and commit rolls it back.
Dropping a transaction without committing rolls it back.
Implementations§
Source§impl Transaction<'_>
impl Transaction<'_>
Sourcepub fn keeping_bound_channels<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R
pub fn keeping_bound_channels<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R
Runs f, whose topology writes do not outdate
topology_bound channels: for an
operation that keeps those channels true itself. Writes outside it, in
the same transaction, still do.
Sourcepub fn add_vertices(&mut self, positions: &[[f32; 3]]) -> Result<Vec<VertexId>>
pub fn add_vertices(&mut self, positions: &[[f32; 3]]) -> Result<Vec<VertexId>>
Adds vertices without creation parents; source channels get their default value.
Sourcepub fn add_vertex_with_parents(
&mut self,
position: [f32; 3],
parents: &[(VertexId, f32)],
) -> Result<VertexId>
pub fn add_vertex_with_parents( &mut self, position: [f32; 3], parents: &[(VertexId, f32)], ) -> Result<VertexId>
Adds a vertex created from existing vertices, e.g. an edge split creates a vertex
with parents [(a, 0.5), (b, 0.5)]. Source channels derive its values from the
parents according to their crate::TopologyPolicy.
Sourcepub fn set_positions(
&mut self,
ids: &[VertexId],
positions: &[[f32; 3]],
) -> Result<()>
pub fn set_positions( &mut self, ids: &[VertexId], positions: &[[f32; 3]], ) -> Result<()>
Sets positions of existing vertices.
Sourcepub fn remove_vertices(&mut self, ids: &[VertexId]) -> Result<()>
pub fn remove_vertices(&mut self, ids: &[VertexId]) -> Result<()>
Removes vertices that no triangle uses.
Sourcepub fn add_triangles(
&mut self,
triangles: &[[VertexId; 3]],
) -> Result<Vec<TriangleId>>
pub fn add_triangles( &mut self, triangles: &[[VertexId; 3]], ) -> Result<Vec<TriangleId>>
Adds triangles between existing vertices.
Sourcepub fn remove_triangles(&mut self, ids: &[TriangleId]) -> Result<()>
pub fn remove_triangles(&mut self, ids: &[TriangleId]) -> Result<()>
Removes triangles. Their vertices stay; remove them separately if unused.
Sourcepub fn set_triangles(
&mut self,
ids: &[TriangleId],
triangles: &[[VertexId; 3]],
) -> Result<()>
pub fn set_triangles( &mut self, ids: &[TriangleId], triangles: &[[VertexId; 3]], ) -> Result<()>
Replaces the vertex ids of existing triangles (e.g. an edge flip).
Sourcepub fn write_channel(
&mut self,
name: &str,
ids: &[VertexId],
values: &[f32],
) -> Result<()>
pub fn write_channel( &mut self, name: &str, ids: &[VertexId], values: &[f32], ) -> Result<()>
Writes source channel values: values holds width values per vertex in ids.
Sourcepub fn drop_channel(&mut self, name: &str) -> Result<()>
pub fn drop_channel(&mut self, name: &str) -> Result<()>
Drops a source channel as part of this edit: it reads as absent from
now on, undoing the edit restores it with its values, and redoing drops
it again. For an operation whose new values for the channel are not
well defined, where leaving it would mean stale values. The values stay
in memory, counted in Patch::byte_size, until the patch is released
from its history or the mesh is compacted. A channel added later under
the same name is replaced when the edit is undone.
§Errors
StoreError::UnknownChannel, or StoreError::NotSourceChannel for
a derived channel; the transaction stays usable.