pub struct EditableMesh {
pub vertices: Vec<Vertex>,
pub indices: Vec<u32>,
pub revision: u64,
}Expand description
Scene-persistent geometry. Increment revision after manual vertex/index changes.
Fields§
§vertices: Vec<Vertex>Position, normal and UV attributes, indexed by triangle data.
indices: Vec<u32>Triangle-list topology.
revision: u64Version of geometry; update increments refresh the shared GPU mesh.
Implementations§
Source§impl EditableMesh
impl EditableMesh
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
Number of vertices.
Sourcepub fn set_position(&mut self, i: usize, p: Vec3) -> bool
pub fn set_position(&mut self, i: usize, p: Vec3) -> bool
Moves one vertex. Returns false for a bad index or a non-finite position.
Sourcepub fn bounds(&self) -> (Vec3, Vec3)
pub fn bounds(&self) -> (Vec3, Vec3)
Axis-aligned local bounds (min, max); both zero for an empty mesh.
Sourcepub fn map_positions(&mut self, f: impl FnMut(usize, Vec3, Vec3) -> Vec3)
pub fn map_positions(&mut self, f: impl FnMut(usize, Vec3, Vec3) -> Vec3)
Replaces every position with f(index, position, normal). Non-finite results are ignored.
Sourcepub fn select_sphere(&self, center: Vec3, radius: f32) -> Vec<usize>
pub fn select_sphere(&self, center: Vec3, radius: f32) -> Vec<usize>
Indices of the vertices inside a sphere (local space): the selection for brush-like edits.
Sourcepub fn select_half_space(&self, point: Vec3, normal: Vec3) -> Vec<usize>
pub fn select_half_space(&self, point: Vec3, normal: Vec3) -> Vec<usize>
Indices of the vertices on the positive side of a plane through point with normal.
Sourcepub fn translate_vertices(&mut self, indices: &[usize], delta: Vec3)
pub fn translate_vertices(&mut self, indices: &[usize], delta: Vec3)
Adds delta to the listed vertices.
Sourcepub fn scale_about(&mut self, center: Vec3, scale: Vec3)
pub fn scale_about(&mut self, center: Vec3, scale: Vec3)
Scales around center per axis.
Sourcepub fn transform(&mut self, m: Mat4)
pub fn transform(&mut self, m: Mat4)
Applies an arbitrary matrix to positions and (rotation part only) normals.
Sourcepub fn inflate(&mut self, amount: f32)
pub fn inflate(&mut self, amount: f32)
Pushes every vertex along its normal (amount metres; negative shrinks).
Sourcepub fn twist(&mut self, axis: Vec3, degrees_per_metre: f32)
pub fn twist(&mut self, axis: Vec3, degrees_per_metre: f32)
Twists the mesh around axis through the origin: degrees_per_metre of rotation per metre along the axis.
Sourcepub fn taper(&mut self, axis: Vec3, start: f32, end: f32)
pub fn taper(&mut self, axis: Vec3, start: f32, end: f32)
Scales the cross-section along axis: start at the lowest point of the mesh, end at the highest.
Sourcepub fn bend(&mut self, along: Vec3, bend_axis: Vec3, degrees_per_metre: f32)
pub fn bend(&mut self, along: Vec3, bend_axis: Vec3, degrees_per_metre: f32)
Bends the mesh around the bend_axis direction: points are rotated around it by
degrees_per_metre times their distance along along.
Sourcepub fn wave(
&mut self,
direction: Vec3,
displace: Vec3,
amplitude: f32,
wavelength: f32,
phase: f32,
)
pub fn wave( &mut self, direction: Vec3, displace: Vec3, amplitude: f32, wavelength: f32, phase: f32, )
A travelling sine wave: vertices move along displace by amplitude * sin(2pi * (d / wavelength + phase)),
where d is the position along direction.
Sourcepub fn noise_displace(&mut self, noise: &Noise, amplitude: f32, time: f32)
pub fn noise_displace(&mut self, noise: &Noise, amplitude: f32, time: f32)
Displaces vertices along their normals by 3D noise (rocks, terrain, hand-made wobble).
time slides the noise so repeated calls animate.
Sourcepub fn smooth(&mut self, iterations: u32, factor: f32)
pub fn smooth(&mut self, iterations: u32, factor: f32)
Laplacian smoothing: moves each vertex towards the average of its neighbours. Vertices that share a position stay together (hard-edged meshes do not tear).
Sourcepub fn default_noise(frequency: f32, seed: u32) -> Noise
pub fn default_noise(frequency: f32, seed: u32) -> Noise
A ready noise for Self::noise_displace: smooth Perlin at the given frequency.
Source§impl EditableMesh
impl EditableMesh
Sourcepub fn from_mesh(mesh: &MeshData) -> Result<Self, String>
pub fn from_mesh(mesh: &MeshData) -> Result<Self, String>
Copies the geometry of a validated source. Material images remain on MeshRenderer.
Sourcepub fn recalculate_normals(&mut self) -> Result<(), String>
pub fn recalculate_normals(&mut self) -> Result<(), String>
Rebuilds area-weighted normals after deformation.
Sourcepub fn box_uv(&mut self, scale: f32) -> Result<(), String>
pub fn box_uv(&mut self, scale: f32) -> Result<(), String>
Simple dominant-normal box projection. This is a UV inspection tool, not an island packer.
Source§impl EditableMesh
impl EditableMesh
Sourcepub fn project_planar(&mut self, axis: Vec3, scale: f32)
pub fn project_planar(&mut self, axis: Vec3, scale: f32)
Planar projection: UVs are the position on the plane perpendicular to axis, divided by scale
(metres per UV unit). Best for floors, walls and decals. Does nothing for a zero axis or scale <= 0.
Sourcepub fn project_cylindrical(&mut self, scale: f32)
pub fn project_cylindrical(&mut self, scale: f32)
Cylindrical projection around the Y axis: U is the angle (0..1 around), V the height divided by scale.
Good for trunks, bottles and columns. The seam sits at +X.
Sourcepub fn project_spherical(&mut self)
pub fn project_spherical(&mut self)
Spherical projection around the origin: U is longitude, V latitude (both 0..1). Good for planets and balls.
Sourcepub fn normalize_uv(&mut self, margin: f32)
pub fn normalize_uv(&mut self, margin: f32)
Fits the UVs into the 0..1 square keeping their proportions, with a margin border (0..0.45).
Sourcepub fn transform_uv(
&mut self,
scale: [f32; 2],
rotation_degrees: f32,
offset: [f32; 2],
)
pub fn transform_uv( &mut self, scale: [f32; 2], rotation_degrees: f32, offset: [f32; 2], )
Scales, rotates (degrees) and offsets every UV around (0.5, 0.5).
Sourcepub fn flat_normals(&mut self)
pub fn flat_normals(&mut self)
Flat shading: every triangle gets its own face normal (vertices are split per triangle).
Sourcepub fn smooth_normals(&mut self, angle_degrees: f32)
pub fn smooth_normals(&mut self, angle_degrees: f32)
Smooth shading with a crease angle: neighbouring faces closer than angle_degrees share a smooth
normal, sharper edges stay hard. Vertices are split along creases.
Trait Implementations§
Source§impl Clone for EditableMesh
impl Clone for EditableMesh
Source§fn clone(&self) -> EditableMesh
fn clone(&self) -> EditableMesh
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Component for EditableMesh
impl Component for EditableMesh
Source§impl Component for EditableMesh
impl Component for EditableMesh
Source§impl Default for EditableMesh
impl Default for EditableMesh
Source§fn default() -> EditableMesh
fn default() -> EditableMesh
Source§impl<'de> Deserialize<'de> for EditableMesh
impl<'de> Deserialize<'de> for EditableMesh
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for EditableMesh
impl RefUnwindSafe for EditableMesh
impl Send for EditableMesh
impl Sync for EditableMesh
impl Unpin for EditableMesh
impl UnsafeUnpin for EditableMesh
impl UnwindSafe for EditableMesh
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSync for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.