Skip to main content

EditableMesh

Struct EditableMesh 

Source
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: u64

Version of geometry; update increments refresh the shared GPU mesh.

Implementations§

Source§

impl EditableMesh

Source

pub fn vertex_count(&self) -> usize

Number of vertices.

Source

pub fn position(&self, i: usize) -> Option<Vec3>

Local position of vertex i.

Source

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.

Source

pub fn bounds(&self) -> (Vec3, Vec3)

Axis-aligned local bounds (min, max); both zero for an empty mesh.

Source

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.

Source

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.

Source

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.

Source

pub fn translate_vertices(&mut self, indices: &[usize], delta: Vec3)

Adds delta to the listed vertices.

Source

pub fn translate(&mut self, delta: Vec3)

Moves the whole mesh.

Source

pub fn scale_about(&mut self, center: Vec3, scale: Vec3)

Scales around center per axis.

Source

pub fn transform(&mut self, m: Mat4)

Applies an arbitrary matrix to positions and (rotation part only) normals.

Source

pub fn inflate(&mut self, amount: f32)

Pushes every vertex along its normal (amount metres; negative shrinks).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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

Source

pub fn from_mesh(mesh: &MeshData) -> Result<Self, String>

Copies the geometry of a validated source. Material images remain on MeshRenderer.

Source

pub fn mesh(&self) -> MeshData

CPU mesh snapshot, with no imported material runs.

Source

pub fn changed(&mut self)

Marks vertex/index modifications for upload.

Source

pub fn recalculate_normals(&mut self) -> Result<(), String>

Rebuilds area-weighted normals after deformation.

Source

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

pub fn sculpt(&mut self, center: Vec3, radius: f32, amount: f32) -> bool

Pushes nearby vertices along their normals with a smooth local-space brush falloff. Coincident split vertices share a direction to keep hard-edged meshes closed.

Source

pub fn to_obj(&self) -> Result<String, String>

OBJ with indexed positions, UVs and normals. Does not export glTF material bindings.

Source§

impl EditableMesh

Source

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.

Source

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.

Source

pub fn project_spherical(&mut self)

Spherical projection around the origin: U is longitude, V latitude (both 0..1). Good for planets and balls.

Source

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).

Source

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).

Source

pub fn flat_normals(&mut self)

Flat shading: every triangle gets its own face normal (vertices are split per triangle).

Source

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

Source§

fn clone(&self) -> EditableMesh

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for EditableMesh

Source§

const NAME: &'static str = "EditableMesh"

Stable, globally unique name; keep it identical in the host and script library.
§

const KEY: u64 = _

Storage key derived from [Self::NAME]. Normally should not be overridden.
Source§

impl Component for EditableMesh

Source§

const REMOVABLE: bool = true

Whether the user may remove it in the inspector.
Source§

fn fields(&mut self) -> Vec<Field<'_>>

Mutable field descriptors used by the Inspector and script property serialization.
Source§

impl Default for EditableMesh

Source§

fn default() -> EditableMesh

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for EditableMesh

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for EditableMesh

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.