hexasphere

Struct Subdivided

Source
pub struct Subdivided<T, S: BaseShape> { /* private fields */ }
Expand description

A subdivided shape generated from some BaseShape and a subdivision level.

The subdivided shape is defined, as is conventional in most 3D graphics systems, as a list of vertices, and a list of indices into the vertex list which connect the vertices into primitive shapes. Subdivided can provide triangle-list indices indices for solid surface rendering, and line-strip indices for wireframe rendering.

All main triangles specified by S in BaseShape are expected to be in counter clockwise winding.

Points are preferably stored with coordinates less than or equal to 1.0. This is why all default shapes lie on the unit sphere.

Implementations§

Source§

impl<T> Subdivided<T, IcoSphereBase>

Source

pub fn radius_shapes(&self) -> f32

Calculate distance from the center of a shape (pentagon or hexagon) to one of the vertices of the shape.

In other words, the radius of the circumscribed circle.

Source§

impl<T, S: BaseShape> Subdivided<T, S>

Source

pub fn new(subdivisions: usize, generator: impl FnMut(Vec3A) -> T) -> Self
where S: Default,

Creates the base shape from S and subdivides it.

This is equivalent to Subdivided::new_custom_shape(subdivisions, generator, S::default()) and is convenient when S implements Default.

Source

pub fn new_custom_shape( subdivisions: usize, generator: impl FnMut(Vec3A) -> T, shape: S, ) -> Self

Creates the base shape from S and subdivides it.

  • subdivisions specifies the number of auxiliary points that will be created along the edges the vertices of the base shape. For example, if subdivisions is 0, then the base shape is unaltered; if subdivisions is 3, then each edge of the base shape will have 3 added points, forming 4 triangle edges.

  • generator is a function run for each vertex once all the subdivisions are applied, and its values are stored in an internal Vec, accessible from Self::raw_data().

Source

pub fn subdivide(&mut self, amount: usize)

Increases the current subdivision count by amount.

After calling this, you must call Self::calculate_values() to compute new vertex data.

Source

pub fn calculate_values(&mut self, generator: impl FnMut(Vec3A) -> T)

Recalculate data after Self::subdivide().

Source

pub fn raw_points(&self) -> &[Vec3A]

The vertex positions created by the subdivision process.

Source

pub fn get_indices(&self, triangle: usize, buffer: &mut Vec<u32>)

Appends the indices for the subdivided form of the specified main triangle into buffer.

The specified triangle is a main triangle on the base shape. The range of this should be limited to the number of triangles in the base shape.

Alternatively, use Self::get_all_indices to get all the indices.

Each element put into buffer is an index into Self::raw_data or Self::raw_points specifying the position of a triangle vertex. The first three elements specify the three vertices of a triangle to be drawn, and the next three elements specify another triangle, and so on.

Source

pub fn get_all_indices(&self) -> Vec<u32>

Gets the indices for the triangles making up the subdivided shape.

Each element of the returned Vec is an index into Self::raw_data or Self::raw_points specifying the position of a triangle vertex. The first three elements specify the three vertices of a triangle to be drawn, and the next three elements specify another triangle, and so on.

Together, these triangles cover the entire surface of the shape.

Source

pub fn get_line_indices( &self, buffer: &mut Vec<u32>, triangle: usize, delta: usize, breaks: impl FnMut(&mut Vec<u32>), )

Appends indices for the wireframe of the subdivided form of the specified main triangle to buffer.

This is equivalent to Self::get_all_line_indices except that it selects a single main triangle from the base shape. See its documentation for the format of the result, and how to use delta and breaks.

Source

pub fn get_major_edge_line_indices( &self, edge: usize, buffer: &mut Vec<u32>, delta: usize, )

👎Deprecated: Flawed. Use get_major_edges_line_indices() instead.

Appends indices for the wireframe of the subdivided form of the specified main triangle edge to buffer.

The valid range of edge is 0..(S::EDGES). See Self::get_line_indices for more on delta.

Source

pub fn get_major_edges_line_indices( &self, buffer: &mut Vec<u32>, delta: u32, breaks: impl FnMut(&mut Vec<u32>), )

Appends indices for the wireframe of the subdivided form of the base shape’s main triangles’ edges to buffer.

Compared to Self::get_all_line_indices, this does not return edges of any of the triangles which were created by subdivision — only edges of the original triangles. See that method’s documentation for how to use delta and breaks.

Source

pub fn get_all_line_indices( &self, delta: usize, breaks: impl FnMut(&mut Vec<u32>), ) -> Vec<u32>

Returns a vector of indices for the wireframe of the subdivided mesh.

Each element in the returned Vec is an index into Self::raw_data or Self::raw_points specifying the position of a triangle vertex. The indices are formatted as “line strips”; that is, each vertex should be connected to the previous by a line, except where a break is specified.

The breaks function is run every time there is a necessary break in the line strip. Use this to, for example, swap out the buffer using std::mem::take, or push a special break-marking index into the buffer.

delta is added to all of the indices pushed into the buffer, and is generally intended to be used together with breaks to allow a marker index at zero. This marker index might be used to refer to a vertex with position set to NaN, or parsed in some other way by the graphics API the indices are fed to.

Source

pub fn subdivisions(&self) -> usize

Returns the number of subdivisions applied when this shape was created.

Source

pub fn raw_data(&self) -> &[T]

Returns the custom data for each vertex created by the generator function.

The length of this slice is equal to the number of vertices in the subdivided shape.

Source

pub fn raw_data_mut(&mut self) -> &mut [T]

Returns mutable access to the custom data created by the generator function.

The length of this slice is equal to the number of vertices in the subdivided shape.

Source

pub fn indices_per_main_triangle(&self) -> usize

Calculate the number of indices which each main triangle will add to the vertex buffer.

§Equation
(subdivisions + 1)²
Source

pub fn vertices_per_main_triangle_shared(&self) -> usize

Calculate the number of vertices contained within each main triangle including the vertices which are shared with another main triangle.

§Equation
(subdivisions + 1) * (subdivisions + 2) / 2
Source

pub fn vertices_per_main_triangle_unique(&self) -> usize

Calculate the number of vertices contained within each main triangle excluding the ones that are shared with other main triangles.

§Equation
{
{ subdivisions < 2  : 0
{
{ subdivisions >= 2 : (subdivisions - 1) * subdivisions / 2
{
Source

pub fn shared_vertices(&self) -> usize

Calculate the number of vertices along the edges of the main triangles and the vertices of the main triangles.

§Equation
subdivisions * EDGES + INITIAL_POINTS
Source

pub fn linear_distance(&self, p1: u32, p2: u32, radius: f32) -> f32

Linear distance between two points on this shape.

Trait Implementations§

Source§

impl<T: Clone, S: Clone + BaseShape> Clone for Subdivided<T, S>

Source§

fn clone(&self) -> Subdivided<T, S>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T, S> Freeze for Subdivided<T, S>
where S: Freeze,

§

impl<T, S> RefUnwindSafe for Subdivided<T, S>

§

impl<T, S> Send for Subdivided<T, S>
where S: Send, T: Send,

§

impl<T, S> Sync for Subdivided<T, S>
where S: Sync, T: Sync,

§

impl<T, S> Unpin for Subdivided<T, S>
where S: Unpin, T: Unpin,

§

impl<T, S> UnwindSafe for Subdivided<T, S>
where S: UnwindSafe, T: UnwindSafe,

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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> 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V