Expand description
§rust-3d
3D/2D library written in Rust. Offering useful containers, structures and algorithms for 2D and 3D space. Meant as basis for numeric algorithms, viewers, game engines, …
§Migration 0.29.0 -> 0.30.0
Note that the module structure changed. There’s now only submodules for io
and impls
.
Also prelude
was removed.
If you were using the prelude via rust_3d::prelude::*;
you should now be able to just switch to
rust_3d::*;
.
If you were using explicit paths such as rust_3d::filters::combinators::FilterAll
you should now use rust_3d::FilterAll
.
Note that io
and impls
are still part of the module path.
This should make future usage easier, but might be painful for existing users.
§Tour
Here’s a little overview of some of rust-3d
’s features.
The snippets / names might not be up-to-date, so please check tests/
for compiling examples.
§Proper error handling
No .unwrap()
where it’s not 100% safe.
§Strong / Smart Types
There’s strong types for everything that might get mixed up easily.
This way e.g. ids of faces can’t be mistaken for ids of vertices.
fn edges_of_face(&self, faceid: FId) -> Result<(EId, EId, EId)>;
There’s also smart types which restrict the values they can hold.
This way distances can never be < 0.0
, sizes can be enfored to be > 0.0
etc.
Positive
NonNegative
§Generic Code Base
I try and keep all algorithms and types as generic as possible.
- Even rather basic types like
Is2D
are split into several versions:IsEditable2D
,IsBuildable2D
IsMesh
is defined for any vertex type and any number of vertices / face- There’s traits for collections (no need to use
Vec
)
This makes it possible to require as little implementation work as possible if you want to use your own types.
§Combinators / Transformers
- Any
IsFilter<T>
can be combined viaFilterAND
,FilterOR
,FilterAny
,FilterNegate
… - Any
IsFilter<T>
can be transformed to work for any collection ofT
s (IsFilterRandomAccessible
). IsDirectionField2D
might be transformed to anIsFilter<Is2D>
, which can then be transformed to anIsFilterRandomAccessible<Is2D>
.
§IO
Any IO
method is defined on traits, so if you implement these, you’ll get read/write of different file formats for free.
§Documentation
You can find the documentation here.
§Examples
Please take a look at the tests in tests/
. These will be up-to-date and compiling.
I might add extensive tutorials / examples / demo projects in the future.
§Links
§Contribute
Feel free to open an issue in case you’re missing something or found a bug. Please avoid directly contributing since I might be working on breaking changes or the feature you want to implement. Open an issue or email me beforehand.
§License
MIT (see LICENSE)
Modules§
- boxx
- rust-3d trait implementations for the standard Box
- io
- Containing IO functions / traits / types
- linked_
list - rust-3d trait implementations for the standard LinkedList
- subdivide
- Subdivision algorithms to e.g. refine meshes
- test_
helper - helper functions for testing (these functions unwrap and panic, only use for tests)
- vec
- rust-3d trait implementations for the standard Vec
- vec_
deque - rust-3d trait implementations for the standard VecDeque
Macros§
Structs§
- Bounding
Box2D - BoundingBox2D, an axis aligned bounding box within 2D space
- Bounding
Box3D - BoundingBox3D, an axis aligned bounding box within 3D space
- Box2D
- Box2D, a box in 2D space
- Box3D
- Box3D, a box in 3D space
- BoxUnaligned3D
- Not axis aligned Box in 3D space
- Circle
- Circle, a circle in 2D space
- Cluster
- Spatial clustering of data on the x/y plane
- Compressed
Point3D - CompressedPoint3D
- Compressed
Point Cloud3D - CompressedPointCloud3D
- Deg
- Dynamic
Precision Index Vec - DynamicPrecisionIndexVec is a memory efficient container with a usize interface. It uses u8 -> u16 -> u32 -> usize for storage depending on the largest index’s size
- EId
- FId
- Face3
- Face3, a face defined by 3 indices (e.g. used for Mesh)
- FilterAND
- FilterAND, a filter which combines two filters and is true if both of its filters are true
- Filter
All - FilterAll, a filter to chain multiple filters with the and condition => must pass all filters to pass this filter
- Filter
AllRandom Accessible - FilterAllRandomAccessible, a filter to chain multiple IsFilterRandomAccessible with the and condition => must pass all filters to pass this filter
- Filter
Allow - FilterAllow, a filter which always returns true
- Filter
Any - FilterAny, a filter to chain multiple filters with the or condition => must pass any filter to pass this filter
- Filter
AnyRandom Accessible - FilterAnyRandomAccessible, a filter to chain multiple IsFilterRandomAccessible with the or condition => must pass any filter to pass this filter
- Filter
Box2D - FilterBox2D, a box filter within 2D space
- Filter
Box3D - FilterBox3D, a box filter within 3D space
- Filter
Circle - FilterCircle, a circle filter within 2D space
- Filter
Deny - FilterDeny, a filter which always returns false
- Filter
Direction Field2D - FilterDirectionField2D, a filter which can transform any IsDirectionField2D into a filter for (Is2D, IsNormalized2D)
- Filter
Direction Field3D - FilterDirectionField3D, a filter which can transform any IsDirectionField3D into a filter for (Is3D, IsNormalized3D)
- Filter
Negate - FilterNegate, a filter which negates another filter
- FilterOR
- FilterOR, a filter which combines two filters and is true if one of its filters is true
- Filter
Outer Inner - FilterOuterInner, a filter which combines an inner and an outer filter. Where the inner is negated while the outer is allowed. This is useful to create hollow filter shapes
- Filter
Outlier3D - FilterOutlier3D, a filter which removes outliers by counting their neighbours in a search radius This can be used to compare two sets of points by removing those in A which aren’t close enough to B Or to remove outliers within a single set For this use the same input to build this filter as to filter against Points will find themselves, so increase the required count by 1
- Filter
Random Accessible - FilterRandomAccessible, a filter which can transform any IsFilter into an IsFilterRandomAccessible
- Filter
Sphere - FilterSphere, a sphere filter within 3D space
- FilterXOR
- FilterXOR, a filter which combines two filters and is true iff one of its filters is true
- Half
Edge - HalfEdge, the half edge data structure
- HasBounding
Box2D Converted - Wrapper helper to convert the Maybe type to the non-Maybe type
- HasBounding
Box3D Converted - Wrapper helper to convert the Maybe type to the non-Maybe type
- IsIndex
Container Iterator - Iterator for IsIndexContainer
- KdTree
- KdTree https://en.wikipedia.org/wiki/K-d_tree
- Line2D
- Line2D, a line within 2D space
- Line3D
- Line3D, a line within 3D space
- Line
Segment2D - LineSegment2D, a line segment within 2D space
- Line
Segment3D - LineSegment3D, a line segment within 3D space
- Matrix3
- Matrix3, a matrix with 3 rows and columns
- Matrix4
- Matrix4, a matrix with 4 rows and columns
- Matrix3
Pipe - Matrix3Pipe, which makes it easier to pipe different matrices in a defined order
- Matrix4
Pipe - Matrix4Pipe, which makes it easier to pipe different matrices in a defined order
- Mesh3D
- Mesh3D, a mesh with tri-faces within 3D space
- NonNegative
- NonNegative, a wrapper for a f64 value, ensuring it is always >= 0
- Norm2D
- Norm2D, a normalized vector within 2D space
- Norm3D
- Norm3D, a normalized vector within 3D space
- OcTree
- OcTree https://en.wikipedia.org/wiki/Octree
- Plane3D
- Plane3D, a plane within 3D space
- Point2D
- Point2D, a point / position within 2D space
- Point3D
- Point3D, a point / position within 3D space
- Point
Cloud2D - PointCloud2D, a collection of positions within 2D space
- Point
Cloud3D - PointCloud3D, a collection of positions within 3D space
- Point
Cloud3 Df32 - PointCloud3Df32, a collection of positions within 3D space stored lossy as f32 vector for easier usage during rendering
- Polygon2D
- Polygon2D, a polygon within 2D space
- Polygon3D
- Polygon3D, a polygon within 3D space
- Positive
- Positive, a wrapper for a f64 value, ensuring it is always > 0
- Rad
- Ray2D
- Ray2D, a ray within 2D space
- Ray3D
- Ray3D, a ray within 3D space
- Rgb
- Rgb, a struct holding color information
- SATCollider
- Helper to check for collisions between IsSATObject
- SId
- Searchable
Mesh - SearchableMesh, transforms IsMesh to IsSearchableMesh
- Skip
Empty - Iterator that skips empty elements
- Skip
Empty String - Iterator that skips empty strings
- Sphere
- Sphere, a sphere in 3D space
- TriFace3D
- Face with 3 corners in 3D space
- U32Index
Vec - U32IndexVec is a u32 container with a usize interface (make sure your use case doesn’t go out of bounds)
- VId
Enums§
- AABB
Tree2D - AABBTree2D, an axis aligned bounding box tree in 2D for fast collision detection
- AABB
Tree3D - AABBTree3D, an axis aligned bounding box tree in 3D for fast collision detection
- Collider3D
- Collider enumeration for 3D space
- Error
Kind - The Error Enum used by rust-3d
- Precision
- Used to flag precision e.g. for IO operations (32 or 64 bit)
- View
- View, which defines a restricted / full view onto any T. E.g. used when filtering collections of points.
Traits§
- HasBounding
Box2D - HasBoundingBox2D is a trait for types which have a bounding box
- HasBounding
Box2D Maybe - HasBoundingBox2DMaybe is a trait for types which might have a bounding box
- HasBounding
Box3D - HasBoundingBox3D is a trait for types which have a bounding box
- HasBounding
Box3D Maybe - HasBoundingBox3DMaybe is a trait for types which might have a bounding box
- HasCenter
OfGravity2D - HasCenterOfGravity2D is a trait for types which might have a center of gravity
- HasCenter
OfGravity3D - HasCenterOfGravity3D is a trait for types which might have a center of gravity
- HasColliders3D
- Trait for types that have 3D colliders
- HasDistance
To - HasDistanceTo trait used for types which have a defined distance towards another T.
Implementing HasDistanceTo
for U also implements HasDistanceTo for T - HasLength
- HasLength is a trait used for types which have a physical length
- Is2D
- Is2D is a trait used for types which are positioned within the 2D space
- Is3D
- Is3D is a trait used for types which are positioned within the 3D space
- IsBox3D
Searchable - IsBox3DSearchable trait used for search structures which can be queried for elements within a 3D box You should only implement this, if your solution is rather efficient
- IsBuildable2D
- IsBuildable2D is a trait used for types which are positioned in 2D space and can be constructed
- IsBuildable3D
- IsBuildable3D is a trait used for types which are positioned in 3D space and can be constructed
- IsBuildableND
- IsBuildableND is a trait used for types which are positioned in n-dimensional space and can be constructed
- IsCollider
Container3D - Trait for containers with 3D colliders
- IsData
Container - IsDataContainer trait used for data containers allowing for different storage types than using the abstracted type
- IsDirection
Field2D - IsDirectionField2D is a trait used for fields of directions within 2D space
- IsDirection
Field3D - IsDirectionField3D is a trait used for fields of directions within 3D space
- IsEditable2D
- IsEditable2D is a trait used for types which are positioned in 2D space and their position can be changed
- IsEditable3D
- IsEditable3D is a trait used for types which are positioned in 3D space and their position can be changed
- IsEditableND
- IsEditableND is a trait used for types which are positioned in n-dimensional space and their position can be changed
- IsEditable
Polygon - IsEditablePolygon trait used for polygons which can be edited
- IsFace
Editable Mesh - IsFaceEditableMesh trait used for meshes with editable face data
- IsFilter
- IsFilter trait used for filters
- IsFilter
Random Accessible - IsFilterRandomAccessible is a trait used for filters for random accessible collections
- IsIndex
Container - IsIndexContainer trait for containers holding indices
- IsKNearest
Searchable - IsKNearestSearchable trait used for search structures which can be queried for nearest neighbours. You should only implement this, if your solution is rather efficient
- IsMatrix3
Transformable - IsMatrix3Transformable trait used for types that can be transformed by a 3x3 Matrix
- IsMatrix4
Transformable - IsMatrix4Transformable trait used for types that can be transformed by a 4x4 Matrix
- IsMergeable
- IsMergeable trait used for types which can be merged with their own type
- IsMesh
- IsMesh is trait used for meshes
- IsMesh3D
- IsMesh3D is trait used for meshes in 3D space
- IsMovable2D
- IsMovable2D is a trait used for types within 2D space which can be moved
- IsMovable3D
- IsMovable3D is a trait used for types within 3D space which can be moved
- IsND
- IsND is a trait used for types which are positioned within the n-dimensional space
- IsNormalized2D
- IsNormalized2D is a trait used for types which are positioned within the 2D space and normalized
- IsNormalized3D
- IsNormalized3D is a trait used for types which are positioned within the 3D space and normalized
- IsOc
Tree - IsOcTree is a trait used for OcTrees
- IsPlane3D
- IsPlane3D is a trait used for planes within 3D space
- IsPolygon
- IsPolygon is a trait used for closed polygons
- IsPushable
- IsPushable trait used for collections of elements which can be pushed / appended to
- IsRandom
Accessible - IsRandomAccessible is a trait used for collections of elements which are random accessible
- IsRandom
Insertible - IsRandomInsertible is a trait used for collections of elements which are random insertible
- IsSAT
Object - IsSATObject is a trait used for objects that can be used for SAT collision checks
- IsScalable
- IsScalable trait used for types that can have their size scaled by a factor
- IsSearchable
Mesh - IsSearchableMesh trait used for meshes which have extended search methods
- IsSkip
Empty Producer - Utility trait to easily spawn the SkipEmpty iterator
- IsSkip
Empty String Producer - Utility trait to easily spawn the SkipEmptyString iterator
- IsSortable2D
- IsSortable2D trait used for collections which can be sorted by x or y
- IsSortable3D
- IsSortable3D trait used for collections which can be sorted by x,y or z
- IsSortableND
- IsSortableND trait used for collections which can be sorted by certain dimensions. E.g. x,y,z
- IsSphere
Searchable - IsSphereSearchable trait used for search structures which can be queried for elements within a sphere You should only implement this, if your solution is rather efficient
- IsTopology
Unit - IsTopologyUnit trait used for single units of a topology. E.g. size 1 for paths, size 3 for tri meshes, size 4 for quad meshes
- IsTrans
Formable To2D - IsTransFormableTo2D is a trait used for any type which can be transformed 2D space
- IsTrans
Formable To3D - IsTransFormableTo3D is a trait used for any type which can be transformed 3D space
- IsTree3D
- IsTree3D is a trait used for types which are any type of tree within 3D space
- IsVertex
Editable Mesh - IsVertexEditableMesh trait used for meshes with editable vertex data
- IsView
Buildable - IsViewBuildable trait used for types which can be constructed from a view / have a view applied to them
- IsVoxel
Image - IsVoxelImage is a trait used for any type of voxel image
Functions§
- add
- Adds two Is3D values
- arc
- Creates an arc with the given center, diameter, resolution and start and end angles in radians
- center
- Positions the object in such a way that its center is at origin
- center_
2d - Returns the center of two IsBuildable2D
- center_
3d - Returns the center of two IsBuildable3D
- closest_
intersecting - Returns the closest intersection with the ray
- closest_
intersecting_ mut - Returns the closest intersection with the ray
- cluster_
vertices - Algorithm to cluster nearby vertices within a mesh
- collect_
intersections_ ray_ mesh - Collects all intersections between a ray and mesh
- conn
- Calculates the vector between two positions
- contains
- Checks whether haystack contains needle
- convex_
hull_ 2d - Convex hull algorithm returning a Vec of the hull where the points are ordered according to the hull Using Andrew’s monotone chain convex hull algorithm https://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain
- cross
- Returns the cross product between a Is3D and a IsBuildable3D
- dimension_
compare - Compares two IsBuildable3D at a given dimensions
- dimension_
dist - Calculates the distance within a given dimension between two IsBuildable3D
- dist_2d
- Returns the distance between two Is2D
- dist_3d
- Returns the distance between two Is3D
- dist_nd
- Returns the distance between two IsND in case their number of dimensions match
- douglas_
peucker_ 2d - Douglas Peucker algorithm for 2D https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm
- ellipse
- Creates an ellipse with the given center, a, b and resolution
- estimate_
delimiter - Estimates the used delimiter within a string
- extrude
- Extrudes a 2D point cloud into 3D space with a given center and direction
- for_
each_ intersecting - Applies the function to each intersection candidate
- hash_
f64 - Generates the hash of an f64
- heal_
mesh - Algorithm to remove duplicate and degenerate faces from a mesh
- index_
closest_ intersecting - Returns the index of the closest intersection with the ray
- interpolate_
bezier - Returns the Bezier interpolation of the given base points
- interpolate_
cosine - Returns the Cosine interpolation of the given base points
- interpolation_
linear - Returns the linear interpolation of the given base points
- intersection
- The intersection between a line and BoundingBox if there is any
- intersection_
ray_ triangle - Finds the intersection between a ray and triangle
- involut_
circle - Creates a involut circle with the given center, diameter, resolution and start and end angles in radians
- max64
- Maximum of two f64 values
- max_f64
- Max of two f64 values
- max_
f64_ 3 - Max of three f64 values
- min64
- Minimum of two f64 values
- normal_
of_ face - Calculates the normal of a face given by three vertices
- normals_
of_ mesh - Calculates the normals of a mesh
- pack_
dupes_ indexed - Returns a container with duplicates removed and indices representing the original order
- project_
point_ on_ plane - Projects a point onto a plane
- rectangle
- Creates a 2D rectangle from given center width and height
- set_
size - Scales the object to the required size
- sort_
vec_ 2d_ x - Helper function to sort a Vec of Is2D by x
- sort_
vec_ 2d_ y - Helper function to sort a Vec of Is2D by y
- sort_
vec_ 3d_ x - Helper function to sort a Vec of Is3D by x
- sort_
vec_ 3d_ y - Helper function to sort a Vec of Is3D by y
- sort_
vec_ 3d_ z - Helper function to sort a Vec of Is3D by z
- sqr_
dist_ 2d - Returns the squared distance between two Is2D
- sqr_
dist_ 3d - Returns the squared distance between two Is3D
- sqr_
dist_ nd - Returns the squared distance between two IsND in case their number of dimensions match
- to_
words_ skip_ empty - Splits an ASCII line into its words, skipping empty elements
- unify_
faces - Algorithm to unifiy the face orientation within a mesh
- until
- Returns all until delimiter
- until_
bytes - Returns all until delimiter
Type Aliases§
- Result
- Result type used by rust-3d