Struct Geometry

Source
pub struct Geometry {
    pub base: Shape,
    pub tex_coords: Vec<Point2<f32>>,
    pub faces: Vec<[u32; 3]>,
    pub joints: Joints,
    pub shapes: Vec<Shape>,
}
Expand description

A collection of vertices, their normals, and faces that defines the shape of a polyhedral object.

§Examples

Tetrahedron of unit height and base radius.

use std::f32::consts::PI;

let vertices = vec![
    [0.0, 1.0, 0.0].into(),
    [0.0, 0.0, 1.0].into(),
    [(2.0 * PI / 3.0).sin(), 0.0, (2.0 * PI / 3.0).cos()].into(),
    [(4.0 * PI / 3.0).sin(), 0.0, (4.0 * PI / 3.0).cos()].into(),
];

let faces = vec![
    [0, 1, 2],
    [0, 2, 3],
    [0, 3, 1],
    [1, 3, 2],
];

three::Geometry {
    faces,
    base: three::Shape {
        vertices,
        .. three::Shape::default()
    },
    .. three::Geometry::default()
}

§Notes

  • If any vertex normals, tangents, or texture co-ordinates are provided, the number of entries in each array must match the number of entries in vertices.
  • If joints are provided, the number of entries in joints.indices must match the number of entries in joints.weights.

Fields§

§base: Shape

Idle shape of the geometry.

§tex_coords: Vec<Point2<f32>>

Texture co-ordinates.

§faces: Vec<[u32; 3]>

Face indices.

When omitted, the vertex order [[0, 1, 2], [3, 4, 5], ...] is assumed.

§joints: Joints

Properties for vertex skinning.

§shapes: Vec<Shape>

A list of blend shapes.

Implementations§

Source§

impl Geometry

Source

pub fn with_vertices(vertices: Vec<Point3<f32>>) -> Self

Create Geometry from vector of vertices.

§Examples

Triangle in the XY plane.

let vertices = vec![
    [-0.5, -0.5, 0.0].into(),
    [ 0.5, -0.5, 0.0].into(),
    [ 0.5, -0.5, 0.0].into(),
];
let geometry = three::Geometry::with_vertices(vertices);
Source

pub fn plane(width: f32, height: f32) -> Self

Creates planar geometry in the XY plane.

The width and height parameters specify the total length of the geometry along the X and Y axes respectively.

§Examples

Unit square in the XY plane, centered at the origin.

fn make_square() -> three::Geometry {
    three::Geometry::plane(1.0, 1.0)
}
Source

pub fn cuboid(width: f32, height: f32, depth: f32) -> Self

Creates cuboidal geometry.

The width, height, and depth parameters specify the total length of the geometry along the X, Y, and Z axes respectively.

§Examples

Unit cube, centered at the origin.

fn make_cube() -> three::Geometry {
    three::Geometry::cuboid(1.0, 1.0, 1.0)
}
Source

pub fn cylinder( radius_top: f32, radius_bottom: f32, height: f32, radius_segments: usize, ) -> Self

Creates cylindrial geometry.

§Examples

Cylinder of unit height and radius, using 12 segments at each end.

fn make_cylinder() -> three::Geometry {
    three::Geometry::cylinder(1.0, 1.0, 1.0, 12)
}

Cone of unit height and unit radius at the bottom.

fn make_cone() -> three::Geometry {
    three::Geometry::cylinder(0.0, 1.0, 1.0, 12)
}
Source

pub fn uv_sphere( radius: f32, equatorial_segments: usize, meridional_segments: usize, ) -> Self

Creates geometry for a sphere, using the UV method.

  • equatorial_divisions specifies the number of segments about the sphere equator that lies in the XZ plane.
  • meridional_segments specifies the number of segments around the sphere meridian that lies in the YZ plane.
fn make_sphere() -> three::Geometry {
    three::Geometry::uv_sphere(1.0, 12, 12)
}

Trait Implementations§

Source§

impl Clone for Geometry

Source§

fn clone(&self) -> Geometry

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Geometry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Geometry

Source§

fn default() -> Geometry

Returns the “default value” for a type. 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> 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
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

Source§

impl<T> Erased for T