Documentation
¶
Index ¶
- Constants
- func CheckBoxMeshIntersection(box Box, mesh Mesh, yield IntersectionYieldFunc)
- func CheckSegmentBoxIntersection(segment Segment, box Box, yield IntersectionYieldFunc)
- func CheckSegmentCircleIntersection(segment Segment, circle Circle, yield IntersectionYieldFunc)
- func CheckSegmentMeshIntersection(segment Segment, mesh Mesh, yield IntersectionYieldFunc)
- func CheckSegmentSphereIntersection(segment Segment, sphere Sphere, yield IntersectionYieldFunc)
- func CheckSegmentSurfaceIntersection(segment Segment, surface Surface, yield IntersectionYieldFunc)
- func CheckSegmentTriangleIntersection(segment Segment, triangle Triangle, yield IntersectionYieldFunc)
- func CheckSphereBoxIntersection(sphere Sphere, box Box, yield IntersectionYieldFunc)
- func CheckSphereMeshIntersection(sphere Sphere, mesh Mesh, yield IntersectionYieldFunc)
- func CheckSphereSphereIntersection(source, target Sphere, yield IntersectionYieldFunc)
- func CheckSphereTriangleIntersection(sphere Sphere, triangle Triangle, yield IntersectionYieldFunc)
- func IsSegmentCircleIntersection(segment Segment, circle Circle) bool
- func IsSegmentSphereIntersection(segment Segment, sphere Sphere) bool
- func IsSegmentSphereOverlap(segment Segment, sphere Sphere) bool
- func IsSegmentSurfaceIntersection(segment Segment, surface Surface) bool
- func IsSphereSphereIntersection(source, target Sphere) bool
- type Box
- type BoxInfo
- type Circle
- type CompactCube
- type CompactQueryAABB
- type CompactQuerySegment
- type CompactTree
- func (t *CompactTree[T]) GC()
- func (t *CompactTree[T]) Insert(cube CompactCube, value T) CompactTreeItemID
- func (t *CompactTree[T]) QueryAABB(queryBox CompactQueryAABB, yield VisitorFunc[T])
- func (t *CompactTree[T]) QuerySegment(querySegment CompactQuerySegment, yield VisitorFunc[T])
- func (t *CompactTree[T]) Remove(id CompactTreeItemID)
- func (t *CompactTree[T]) Stats() CompactTreeStats
- func (t *CompactTree[T]) Update(id CompactTreeItemID, cube CompactCube)
- func (t *CompactTree[T]) VisitStats() CompactTreeVisitStats
- type CompactTreeItemID
- type CompactTreeSettings
- type CompactTreeStats
- type CompactTreeVisitStats
- type Filter
- type Intersection
- type IntersectionCollection
- type IntersectionYieldFunc
- type LargestIntersection
- type LargestObjectIntersection
- type LastIntersection
- type Mesh
- type MeshInfo
- type ObjectID
- type ObjectInfo
- type ObjectIntersection
- type ObjectIntersectionBucket
- type ObjectIntersectionCollection
- type Scene
- func (s *Scene[O, S]) AttachBox(objID ObjectID, info BoxInfo[S]) ShapeID
- func (s *Scene[O, S]) AttachMesh(objID ObjectID, info MeshInfo[S]) ShapeID
- func (s *Scene[O, S]) AttachSphere(objID ObjectID, info SphereInfo[S]) ShapeID
- func (s *Scene[O, S]) BoxIter(filter Filter) iter.Seq[Box]
- func (s *Scene[O, S]) CheckBoxIntersection(box Box, filter Filter) (ObjectIntersection, bool)
- func (s *Scene[O, S]) CheckMeshIntersection(mesh Mesh, filter Filter) (ObjectIntersection, bool)
- func (s *Scene[O, S]) CheckSegmentIntersection(segment Segment, filter Filter) (ObjectIntersection, bool)
- func (s *Scene[O, S]) CheckSphereIntersection(sphere Sphere, filter Filter) (ObjectIntersection, bool)
- func (s *Scene[O, S]) CollectBoxIntersections(box Box, filter Filter, collection ObjectIntersectionCollection)
- func (s *Scene[O, S]) CollectIntersections(collection ObjectIntersectionCollection)
- func (s *Scene[O, S]) CollectMeshIntersections(mesh Mesh, filter Filter, collection ObjectIntersectionCollection)
- func (s *Scene[O, S]) CollectSegmentIntersections(segment Segment, filter Filter, collection ObjectIntersectionCollection)
- func (s *Scene[O, S]) CollectSphereIntersections(sphere Sphere, filter Filter, collection ObjectIntersectionCollection)
- func (s *Scene[O, S]) CreateObject(info ObjectInfo[O]) ObjectID
- func (s *Scene[O, S]) DeleteObject(objID ObjectID)
- func (s *Scene[O, S]) DeleteShape(shapeID ShapeID)
- func (s *Scene[O, S]) EachBox(filter Filter, yield func(Box) bool)
- func (s *Scene[O, S]) EachMesh(filter Filter, yield func(Mesh) bool)
- func (s *Scene[O, S]) EachSphere(filter Filter, yield func(Sphere) bool)
- func (s *Scene[O, S]) GC()
- func (s *Scene[O, S]) GetObjectTransform(objID ObjectID) Transform
- func (s *Scene[O, S]) GetObjectUserData(objID ObjectID) O
- func (s *Scene[O, S]) GetShapeUserData(shapeID ShapeID) S
- func (s *Scene[O, S]) MeshIter(filter Filter) iter.Seq[Mesh]
- func (s *Scene[O, S]) SetObjectTransform(objID ObjectID, transform Transform)
- func (s *Scene[O, S]) SetObjectUserData(objID ObjectID, userData O)
- func (s *Scene[O, S]) SetShapeUserData(shapeID ShapeID, userData S)
- func (s *Scene[O, S]) SphereIter(filter Filter) iter.Seq[Sphere]
- type SceneSettings
- type Segment
- type ShapeID
- type ShapeInfo
- type SmallestIntersection
- type SmallestObjectIntersection
- type Sphere
- type SphereInfo
- type Surface
- type Transform
- type Triangle
- type VisitorBucket
- type VisitorFunc
Constants ¶
const InvalidCompactTreeItemID = CompactTreeItemID(0xFFFFFFFF)
InvalidCompactTreeItemID is an identifier that can be used by user code to mark an identifier as invalid. However, such an identifier will never be returned by the library and must also never be passed to the library.
const InvalidObjectID = ObjectID(invalidObjectIndex)
InvalidObjectID indicates an object that can never be part of the scene.
const InvalidShapeID = ShapeID(invalidShapeRef)
InvalidShapeID indicates a shape that can never be part of the scene.
Variables ¶
This section is empty.
Functions ¶
func CheckBoxMeshIntersection ¶
func CheckBoxMeshIntersection(box Box, mesh Mesh, yield IntersectionYieldFunc)
CheckBoxMeshIntersection checks if a Box shape intersects with a Mesh shape.
func CheckSegmentBoxIntersection ¶
func CheckSegmentBoxIntersection(segment Segment, box Box, yield IntersectionYieldFunc)
CheckSegmentBoxIntersection checks if the specified segment intersects the specified box and returns the intersection information.
This implementation uses the slab method adapted for oriented boxes. It returns the closest intersection point along the segment.
func CheckSegmentCircleIntersection ¶
func CheckSegmentCircleIntersection(segment Segment, circle Circle, yield IntersectionYieldFunc)
CheckSegmentCircleIntersection returns whether the specified segment intersects the specified circle and returns the intersection point.
This implementation assumes that the circle has backface culling. Hence, a segment starting on the "negative" side of the circle and ending on the "positive" side will not produce an intersection.
A standard Intersection result is not meaningful here.
func CheckSegmentMeshIntersection ¶
func CheckSegmentMeshIntersection(segment Segment, mesh Mesh, yield IntersectionYieldFunc)
CheckSegmentMeshIntersection checks if a segment intersects a mesh.
TODO: Rework this. Just like with sphere an Intersection is not meaningful here and instead an intersection point (one closest to segment start) should be returned.
func CheckSegmentSphereIntersection ¶
func CheckSegmentSphereIntersection(segment Segment, sphere Sphere, yield IntersectionYieldFunc)
CheckSegmentSphereIntersection checks if the specified segment intersects the specified sphere and returns the intersection point.
This implementation assumes that the sphere has backface culling. Hence, a segment starting from inside the sphere will not produce an intersection. For such cases you can flip the segment to get the intersection going out.
func CheckSegmentSurfaceIntersection ¶
func CheckSegmentSurfaceIntersection(segment Segment, surface Surface, yield IntersectionYieldFunc)
CheckSegmentSurfaceIntersection checks whether the specified segment intersects the specified surface and returns the intersection point.
This implementation assumes that the surface has backface culling. Hence, a segment starting on the "negative" side of the surface and ending on the "positive" side will not produce an intersection.
func CheckSegmentTriangleIntersection ¶
func CheckSegmentTriangleIntersection(segment Segment, triangle Triangle, yield IntersectionYieldFunc)
CheckSegmentTriangleIntersection checks if a line segment shape intersects with a triangle shape.
This function assumes that the triangle has backface culling.
func CheckSphereBoxIntersection ¶
func CheckSphereBoxIntersection(sphere Sphere, box Box, yield IntersectionYieldFunc)
CheckSphereBoxIntersection checks if the specified sphere intersects with the specified box.
func CheckSphereMeshIntersection ¶
func CheckSphereMeshIntersection(sphere Sphere, mesh Mesh, yield IntersectionYieldFunc)
func CheckSphereSphereIntersection ¶
func CheckSphereSphereIntersection(source, target Sphere, yield IntersectionYieldFunc)
CheckSphereSphereIntersection checks if a Sphere shape intersects with another Sphere shape.
func CheckSphereTriangleIntersection ¶
func CheckSphereTriangleIntersection(sphere Sphere, triangle Triangle, yield IntersectionYieldFunc)
TODO: Revisit this!
func IsSegmentCircleIntersection ¶
IsSegmentCircleIntersection returns whether the specified segment intersects the specified circle.
This implementation assumes that the circle has backface culling. Hence, a segment starting on the "negative" side of the circle and ending on the "positive" side will not produce an intersection.
func IsSegmentSphereIntersection ¶
IsSegmentSphereIntersection checks if the specified segment intersects the specified sphere.
This implementation assumes that the sphere has backface culling. Hence, a segment starting from inside the sphere will not produce an intersection. For such cases you can flip the segment to get the intersection going out.
func IsSegmentSphereOverlap ¶
IsSegmentSphereOverlap checks if the specified segment overlaps in any way the specified sphere, including being contained by the sphere.
func IsSegmentSurfaceIntersection ¶
IsSegmentSurfaceIntersection checks whether the specified segment intersects the specified surface.
This implementation assumes that the surface has backface culling. Hence, a segment starting on the "negative" side of the surface and ending on the "positive" side will not produce an intersection.
func IsSphereSphereIntersection ¶
IsSphereSphereIntersection checks if the source sphere intersects with the target sphere.
Only a bool result is returned and no collision points or separation normals are evaluated.
Types ¶
type Box ¶
type Box struct {
// Position holds the position of the box.
Position dprec.Vec3
// Rotation holds the rotation of the box.
Rotation dprec.Quat
// HalfWidth holds the half-width of the bx.
HalfWidth float64
// HalfHeight holds the half-height of the box.
HalfHeight float64
// HalfLength holds the half-length of the box.
HalfLength float64
}
Box represents a cuboid shape.
func NewBox ¶
NewBox creates a new box with the specified position, rotation and size.
The size is the full size of the box. Internally it will be converted to half sizes.
func TransformedBox ¶
TransformedBox creates a new box from the specified source box by applying the specified transformation.
func (*Box) BoundingSphere ¶
BoundingSphere returns the bounding sphere of the box.
type BoxInfo ¶
type BoxInfo[S any] struct { // ShapeInfo contains general shape information. ShapeInfo[S] // Box contains the box information. Box Box }
BoxInfo contains the information needed to create a box shape.
type Circle ¶
type Circle struct {
// Position specifies the position of the circle.
Position dprec.Vec3
// Normal specifies the orientation of the circle using a normal vector.
Normal dprec.Vec3
// Radius specifies the radius of the circle.
Radius float64
}
Circle represents a 2D circle in 3D space.
type CompactCube ¶
type CompactCube struct {
// contains filtered or unexported fields
}
CompactCube represents a cube area used for inserting items into the tree.
func NewCompactCube ¶
func NewCompactCube(x, y, z, size float64) CompactCube
NewCompactCube creates a new CompactCube instance from the specified position and size.
func NewCompactCubeFromSphere ¶
func NewCompactCubeFromSphere(sphere Sphere) CompactCube
NewCompactCubeFromSphere creates a new CompactCube that wraps a sphere.
type CompactQueryAABB ¶
type CompactQueryAABB struct {
// contains filtered or unexported fields
}
CompactQueryAABB represents an axis-aligned bounding box used for querying the tree.
func NewCompactQueryAABB ¶
func NewCompactQueryAABB(minX, maxX, minY, maxY, minZ, maxZ float64) CompactQueryAABB
NewCompactQueryAABB creates a new CompactQueryAABB instance from the specified bounds.
func NewCompactQueryAABBFromSphere ¶
func NewCompactQueryAABBFromSphere(sphere Sphere) CompactQueryAABB
NewCompactQueryAABBFromSphere creates a new CompactQueryAABB that wraps a sphere.
type CompactQuerySegment ¶
type CompactQuerySegment struct {
// contains filtered or unexported fields
}
CompactQuerySegment represents a line segment used for querying the tree.
func NewCompactQuerySegment ¶
func NewCompactQuerySegment(a, b dprec.Vec3) CompactQuerySegment
NewCompactQuerySegment creates a new CompactQuerySegment instance from the specified endpoints.
type CompactTree ¶
type CompactTree[T any] struct { // contains filtered or unexported fields }
CompactTree is a spatial structure that uses a loose octree implementation with shrinking bounding box to enable the fast searching of items.
func NewCompactTree ¶
func NewCompactTree[T any](settings CompactTreeSettings) *CompactTree[T]
NewCompactTree creates a new CompactTree using the provided settings.
func (*CompactTree[T]) GC ¶
func (t *CompactTree[T]) GC()
GC runs cleanup and optimization logic. You should call this at least once per frame.
func (*CompactTree[T]) Insert ¶
func (t *CompactTree[T]) Insert(cube CompactCube, value T) CompactTreeItemID
Insert adds an item, which occupies the specified cube area, to this tree.
func (*CompactTree[T]) QueryAABB ¶
func (t *CompactTree[T]) QueryAABB(queryBox CompactQueryAABB, yield VisitorFunc[T])
QueryAABB finds all items that are inside or intersect the specified axis-aligned bounding box. Each found item is passed to the specified yield function. The order in which items are passed is undefined and might change between invocations.
func (*CompactTree[T]) QuerySegment ¶
func (t *CompactTree[T]) QuerySegment(querySegment CompactQuerySegment, yield VisitorFunc[T])
QuerySegment finds all items that intersect the specified segment. Each found item is passed to the specified yield function. The order in which items are passed is undefined and might change between invocations.
func (*CompactTree[T]) Remove ¶
func (t *CompactTree[T]) Remove(id CompactTreeItemID)
Remove removes the item with the specified id from this tree.
func (*CompactTree[T]) Stats ¶
func (t *CompactTree[T]) Stats() CompactTreeStats
Stats returns statistics on the current state of this tree.
func (*CompactTree[T]) Update ¶
func (t *CompactTree[T]) Update(id CompactTreeItemID, cube CompactCube)
Update repositions the item with the specified id to the new area.
func (*CompactTree[T]) VisitStats ¶
func (t *CompactTree[T]) VisitStats() CompactTreeVisitStats
VisitStats returns statistics information on the last executed search in this tree.
type CompactTreeItemID ¶
type CompactTreeItemID uint32
CompactTreeItemID is an identifier used to control the placement of an item into a compact tree.
type CompactTreeSettings ¶
type CompactTreeSettings struct {
// Size specifies the dimension (side to side) of the tree node.
//
// If not specified, a default size of 4096 is used.
//
// Inserting an item outside these bounds has undefined behavior.
Size opt.T[float64]
// MaxDepth controls the maximum depth that the tree can reach.
//
// If not specified, a default max depth of 8 is used.
MaxDepth opt.T[uint32]
// InitialNodeCapacity is a hint as to the number of nodes that will be
// needed to place all items. Usually one would find that number empirically.
// This allows the tree to preallocate memory and avoid dynamic allocations.
//
// By default the initial capacity is 4096.
InitialNodeCapacity opt.T[uint32]
// InitialItemCapacity is a hint as to the likely upper bound of items that
// will be inserted into the tree. This allows the tree to preallocate
// memory and avoid dynamic allocations during insertion.
//
// By default the initial capacity is 1024.
InitialItemCapacity opt.T[uint32]
}
CompactTreeSettings contains the settings for a CompactTree.
type CompactTreeStats ¶
type CompactTreeStats struct {
// NodeCount is the total number of nodes in the tree.
NodeCount uint32
// ItemCount is the total number of items in the tree.
ItemCount uint32
// ItemCountPerDepth contains the number of items at each depth level.
ItemCountPerDepth []uint32
}
CompactTreeStats represents the current state of a CompactTree.
type CompactTreeVisitStats ¶
type CompactTreeVisitStats struct {
// NodeCountVisited is the number of nodes that were visited during the last
// visit operation.
NodeCountVisited uint32
// NodeCountAccepted is the number of nodes that were determined relevant
// during the last visit operation.
NodeCountAccepted uint32
// NodeCountRejected is the number of nodes that were determined irrelevant
// during the last visit operation.
NodeCountRejected uint32
// ItemCountVisited is the number of items that were visited during the last
// visit operation.
ItemCountVisited uint32
// ItemCountAccepted is the number of items that were determined relevant
// during the last visit operation.
ItemCountAccepted uint32
// ItemCountRejected is the number of items that were determined irrelevant
// during the last visit operation.
ItemCountRejected uint32
}
CompactTreeVisitStats represents statistics on the last visit operation performed on a CompactTree.
type Filter ¶
type Filter struct {
// Mask is a bitmask used to filter shapes based on their assigned layers.
Mask opt.T[uint32]
// SkipDynamic indicates whether dynamic shapes should be excluded from the
// results.
SkipDynamic bool
// SkipStatic indicates whether static shapes should be excluded from the
// results.
SkipStatic bool
}
Filter represents a set of criteria to filter 3D shapes in a scene.
type Intersection ¶
type Intersection struct {
// TargetContact contains the point on the target shape where the
// intersection first occurred.
TargetContact dprec.Vec3
// TargetNormal contains the best direction in which the source shape
// must be translated to avoid the intersection.
TargetNormal dprec.Vec3
// Depth returns the amount of penetration between the two shapes.
Depth float64
}
Intersection represents the intersection of two shapes.
func (*Intersection) EvalSourceContact ¶
func (i *Intersection) EvalSourceContact() dprec.Vec3
EvalSourceContact calculates the contact point on the source shape.
func (*Intersection) EvalSourceNormal ¶
func (i *Intersection) EvalSourceNormal() dprec.Vec3
EvalSourceNormal calculates the normal on the source shape along which the target shape needs to be repositioned to resolve the intersection.
func (*Intersection) Flipped ¶
func (i *Intersection) Flipped() Intersection
Flipped returns a flipped (source and target swapped) version of this intersection.
type IntersectionCollection ¶
type IntersectionCollection interface {
// AddIntersection adds an intersection to the collection.
AddIntersection(intersection Intersection)
}
IntersectionCollection represents a data structure that can hold one or more intersections.
type IntersectionYieldFunc ¶
type IntersectionYieldFunc func(intersection Intersection)
IntersectionYieldFunc is a function type that can be used to yield intersections as they are found.
type LargestIntersection ¶
type LargestIntersection struct {
// contains filtered or unexported fields
}
LargestIntersection is an implementation of IntersectionCollection that keeps track of the closest (largest depth) observed intersection.
func (*LargestIntersection) AddIntersection ¶
func (i *LargestIntersection) AddIntersection(intersection Intersection)
AddIntersection tracks the specified intersection.
func (*LargestIntersection) Intersection ¶
func (i *LargestIntersection) Intersection() (Intersection, bool)
Intersection returns the worst observed intersection and a flag whether there was actually any intersection observed.
func (*LargestIntersection) Reset ¶
func (i *LargestIntersection) Reset()
Reset clears any observed intersection.
type LargestObjectIntersection ¶
type LargestObjectIntersection struct {
// contains filtered or unexported fields
}
LargestObjectIntersection is an implementation of ObjectIntersectionCollection that keeps track of the closest (largest depth) observed intersection.
func (*LargestObjectIntersection) AddIntersection ¶
func (i *LargestObjectIntersection) AddIntersection(intersection ObjectIntersection)
AddIntersection tracks the specified intersection.
func (*LargestObjectIntersection) Intersection ¶
func (i *LargestObjectIntersection) Intersection() (ObjectIntersection, bool)
Intersection returns the worst observed intersection and a flag whether there was actually any intersection observed.
func (*LargestObjectIntersection) Reset ¶
func (i *LargestObjectIntersection) Reset()
Reset clears any observed intersection.
type LastIntersection ¶
type LastIntersection struct {
// contains filtered or unexported fields
}
LastIntersection is an implementation of IntersectionCollection that keeps track of the last observed intersection.
func (*LastIntersection) AddIntersection ¶
func (i *LastIntersection) AddIntersection(intersection Intersection)
AddIntersection tracks the specified intersection.
func (*LastIntersection) Intersection ¶
func (i *LastIntersection) Intersection() (Intersection, bool)
Intersection returns the last observed intersection and a flag whether there was actually any intersection observed.
func (*LastIntersection) Reset ¶
func (i *LastIntersection) Reset()
Reset clears any observed intersection.
type Mesh ¶
type Mesh struct {
// Triangles contains all the triangles that make up the mesh.
Triangles []Triangle
}
Mesh represents a mesh shape that is comprised of triangles.
func NewMesh ¶
NewMesh creates a mesh from the specified triangles.
NOTE: The mesh becomes the owner of the triangle slice.
func TransformedMesh ¶
TransformedMesh creates a new mesh from the specified source mesh by applying the specified transformation.
func (*Mesh) BoundingSphere ¶
BoundingSphere returns a Sphere that encompases this mesh.
type MeshInfo ¶
type MeshInfo[S any] struct { // ShapeInfo contains general shape information. ShapeInfo[S] // Mesh contains the mesh information. Mesh Mesh }
MeshInfo contains the information needed to create a mesh shape.
type ObjectInfo ¶
type ObjectInfo[O any] struct { // Position optionally specifies a position where the object should be // placed. // // Defaults to the origin. Position opt.T[dprec.Vec3] // Rotation optionally specifies a rotation of the object. // // Defaults to the identity rotation. Rotation opt.T[dprec.Quat] // Static marks the object as static. Static objects are not checked for // intersections with other static objects. Static bool // UserData allows one to attach custom user data to an object. UserData O }
ObjectInfo contains the information needed to create an object in a scene.
type ObjectIntersection ¶
type ObjectIntersection struct {
// SourceObjectID contains the ID of the first involved object.
//
// This ID is equal to InvalidObjectID if the check was not performed with
// a scene object.
SourceObjectID ObjectID
// SourceShapeID contains the ID of the shape from the first involved object.
//
// This ID is equal to InvalidShapeID if the check was not performed with
// a scene object.
SourceShapeID ShapeID
// TargetObjectID contains the ID of the second involved object.
//
// This ID is equal to InvalidObjectID if the check was not performed with
// a scene object.
TargetObjectID ObjectID
// TargetShapeID contains the ID of the shape from the second involved object.
//
// This ID is equal to InvalidShapeID if the check was not performed with
// a scene object.
TargetShapeID ShapeID
// Intersection holds the underlying raw shape intersection.
Intersection
}
ObjectIntersection represents the intersectio of two objects.
func (*ObjectIntersection) Flipped ¶
func (i *ObjectIntersection) Flipped() ObjectIntersection
Flipped returns a flipped (source and target swapped) version of this intersection.
type ObjectIntersectionBucket ¶
type ObjectIntersectionBucket struct {
// contains filtered or unexported fields
}
ObjectIntersectionBucket is a container for object intersections.
func NewIntersectionBucket ¶
func NewIntersectionBucket(initialCapacity int) *ObjectIntersectionBucket
NewIntersectionBucket creates a new IntersectionBucket instance with the specified initial capacity.
func (*ObjectIntersectionBucket) AddIntersection ¶
func (b *ObjectIntersectionBucket) AddIntersection(intersection ObjectIntersection)
Add adds a new Intersection to this set.
func (*ObjectIntersectionBucket) Intersections ¶
func (s *ObjectIntersectionBucket) Intersections() []ObjectIntersection
Intersections returns a slice of all intersections that have been observed.
NOTE: The slice must not be modified or cached as it will be reused.
func (*ObjectIntersectionBucket) IsEmpty ¶
func (b *ObjectIntersectionBucket) IsEmpty() bool
IsEmpty returns whether no intersections were found.
func (*ObjectIntersectionBucket) Reset ¶
func (b *ObjectIntersectionBucket) Reset()
Reset clears the buffer of this result set so that it can be reused.
type ObjectIntersectionCollection ¶
type ObjectIntersectionCollection interface {
// AddIntersection adds an intersection to the collection.
AddIntersection(intersection ObjectIntersection)
}
ObjectIntersectionCollection represents a data structure that can hold one or more object intersections.
type Scene ¶
type Scene[T, S any] struct { // contains filtered or unexported fields }
Scene represents a 3D scene where objects made of shapes can be added.
func NewScene ¶
func NewScene[O, S any](settings SceneSettings) *Scene[O, S]
NewScene creates a new scene.
func (*Scene[O, S]) AttachBox ¶
AttachBox creates a box shape and attaches it to the object to be used for intersection tests.
func (*Scene[O, S]) AttachMesh ¶
AttachMesh creates a mesh shape and attaches it to the object to be used for intersection tests.
func (*Scene[O, S]) AttachSphere ¶
func (s *Scene[O, S]) AttachSphere(objID ObjectID, info SphereInfo[S]) ShapeID
AttachSphere creates a sphere shape and attaches it to the object to be used for intersection tests.
func (*Scene[O, S]) BoxIter ¶
BoxIter returns an iterator over all box shapes in the scene that match the filter.
func (*Scene[O, S]) CheckBoxIntersection ¶
func (s *Scene[O, S]) CheckBoxIntersection(box Box, filter Filter) (ObjectIntersection, bool)
CheckBoxIntersection returns the first intersection of the box with the scene.
func (*Scene[O, S]) CheckMeshIntersection ¶
func (s *Scene[O, S]) CheckMeshIntersection(mesh Mesh, filter Filter) (ObjectIntersection, bool)
CheckMeshIntersection returns the first intersection of the mesh with the scene.
func (*Scene[O, S]) CheckSegmentIntersection ¶
func (s *Scene[O, S]) CheckSegmentIntersection(segment Segment, filter Filter) (ObjectIntersection, bool)
CheckSegmentIntersection returns the first intersection of the segment with the scene.
func (*Scene[O, S]) CheckSphereIntersection ¶
func (s *Scene[O, S]) CheckSphereIntersection(sphere Sphere, filter Filter) (ObjectIntersection, bool)
CheckSphereIntersection returns the first intersection of the sphere with the scene.
func (*Scene[O, S]) CollectBoxIntersections ¶
func (s *Scene[O, S]) CollectBoxIntersections(box Box, filter Filter, collection ObjectIntersectionCollection)
CollectBoxIntersections collects all intersections of the box with objects in the scene.
func (*Scene[O, S]) CollectIntersections ¶
func (s *Scene[O, S]) CollectIntersections(collection ObjectIntersectionCollection)
CollectIntersections yields intersections found in this scene.
func (*Scene[O, S]) CollectMeshIntersections ¶
func (s *Scene[O, S]) CollectMeshIntersections(mesh Mesh, filter Filter, collection ObjectIntersectionCollection)
CollectMeshIntersections collects all intersections of the mesh with objects in the scene.
func (*Scene[O, S]) CollectSegmentIntersections ¶
func (s *Scene[O, S]) CollectSegmentIntersections(segment Segment, filter Filter, collection ObjectIntersectionCollection)
CollectSegmentIntersections collects all intersections of the segment with objects in the scene.
func (*Scene[O, S]) CollectSphereIntersections ¶
func (s *Scene[O, S]) CollectSphereIntersections(sphere Sphere, filter Filter, collection ObjectIntersectionCollection)
CheckSphereIntersection returns the first intersection of the sphere with the scene.
func (*Scene[O, S]) CreateObject ¶
func (s *Scene[O, S]) CreateObject(info ObjectInfo[O]) ObjectID
CreateObject creates a new object.
func (*Scene[O, S]) DeleteObject ¶
DeleteObject deletes an object.
func (*Scene[O, S]) DeleteShape ¶
DeleteShape deletes a shape from an object. The object is not deleted and continues to exist in the scene.
func (*Scene[O, S]) EachBox ¶
EachBox iterates over all box shapes in the scene that match the filter and yields them to the provided callback.
func (*Scene[O, S]) EachMesh ¶
EachMesh iterates over all mesh shapes in the scene that match the filter and yields them to the provided callback.
func (*Scene[O, S]) EachSphere ¶
EachSphere iterates over all sphere shapes in the scene that match the filter and yields them to the provided callback.
func (*Scene[O, S]) GC ¶
func (s *Scene[O, S]) GC()
GC cleans up internal data and allows for memory reuse. This should be called once per frame.
func (*Scene[O, S]) GetObjectTransform ¶
GetObjectTransform returns the given object's transform.
func (*Scene[O, S]) GetObjectUserData ¶
GetObjectUserData returns the user data associated with the given object.
func (*Scene[O, S]) GetShapeUserData ¶
GetShapeUserData returns the user data associated with the given shape.
func (*Scene[O, S]) MeshIter ¶
MeshIter returns an iterator over all mesh shapes in the scene that match the filter.
func (*Scene[O, S]) SetObjectTransform ¶
SetObjectTransform relocates the given object.
func (*Scene[O, S]) SetObjectUserData ¶
SetObjectUserData assigns the specified user data to the object.
func (*Scene[O, S]) SetShapeUserData ¶
SetShapeUserData assigns the specified user data to the shape.
type SceneSettings ¶
type SceneSettings struct {
// Size specifies the dimension (from side to side) of the scene.
// Inserting an item outside these bounds has undefined behavior.
Size opt.T[float64]
// MaxDepth controls the maximum depth that the underlying octree can reach.
MaxDepth opt.T[uint32]
// InitialNodeCapacity is a hint as to the number of nodes that will be
// needed to place all items. Usually one would find that number empirically.
// This allows the octree to preallocate memory and avoid dynamic allocations.
InitialNodeCapacity opt.T[uint32]
// InitialItemCapacity is a hint as to the likely upper bound of items that
// will be inserted into the octree. This allows the octree to preallocate
// memory and avoid dynamic allocations during insertion.
InitialItemCapacity opt.T[uint32]
}
SceneSettings contains information needed to create an optimal scene.
type Segment ¶
type Segment struct {
// A is the start of the segment.
A dprec.Vec3
// B is the end of the segment.
B dprec.Vec3
}
Segment represents a line segment with fixed start and end points.
func NewSegment ¶
NewSegment creates a new segment with the specified start and end points.
type ShapeInfo ¶
type ShapeInfo[S any] struct { // RejectGroup becomes active if a value larger than zero is specified. // Shapes that share the same reject group are not checked for intersection. RejectGroup uint32 // SourceMask specifies the layers in which this shape is positioned. SourceMask opt.T[uint32] // TargetMask specifies the layers with which this shape can intersect. TargetMask opt.T[uint32] // UserData allows one to attach custom user data to a shape. UserData S }
ShapeInfo contains information needed to create a new shape in the scene.
type SmallestIntersection ¶
type SmallestIntersection struct {
// contains filtered or unexported fields
}
SmallestIntersection is an implementation of IntersectionCollection that keeps track of the farthest (smallest depth) observed intersection.
func (*SmallestIntersection) AddIntersection ¶
func (i *SmallestIntersection) AddIntersection(intersection Intersection)
AddIntersection tracks the specified intersection.
func (*SmallestIntersection) Intersection ¶
func (i *SmallestIntersection) Intersection() (Intersection, bool)
Intersection returns the best observed intersection and a flag whether there was actually any intersection observed.
func (*SmallestIntersection) Reset ¶
func (i *SmallestIntersection) Reset()
Reset clears any observed intersection.
type SmallestObjectIntersection ¶
type SmallestObjectIntersection struct {
// contains filtered or unexported fields
}
SmallestObjectIntersection is an implementation of ObjectIntersectionCollection that keeps track of the farthest (smallest depth) observed intersection.
func (*SmallestObjectIntersection) AddIntersection ¶
func (i *SmallestObjectIntersection) AddIntersection(intersection ObjectIntersection)
AddIntersection tracks the specified intersection.
func (*SmallestObjectIntersection) Intersection ¶
func (i *SmallestObjectIntersection) Intersection() (ObjectIntersection, bool)
Intersection returns the worst observed intersection and a flag whether there was actually any intersection observed.
func (*SmallestObjectIntersection) Reset ¶
func (i *SmallestObjectIntersection) Reset()
Reset clears any observed intersection.
type Sphere ¶
type Sphere struct {
// Position is the position of the sphere.
Position dprec.Vec3
// Radius is the radius of the sphere.
Radius float64
}
Sphere represents a sphere shape.
func TransformedSphere ¶
TransformedSphere creates a new sphere based off of an existing one by applying the specified transformation.
type SphereInfo ¶
type SphereInfo[S any] struct { // ShapeInfo contains general shape information. ShapeInfo[S] // Sphere contains the sphere information. Sphere Sphere }
SphereInfo contains the information needed to create a sphere shape.
type Surface ¶
type Surface struct {
// Normal is a unit vector that represents the orientation of the plane.
Normal dprec.Vec3
// Distance is the distance of the plane from the origin along the normal.
Distance float64
}
Surface represents a plane in 3D space.
It uses a normal + distance representation which both compact and also easier to use that the official A, B, C, D, since the normal is expected to be normalized.
func BasisXSurface ¶
func BasisXSurface() Surface
BasisXSurface surface returns a surface that is oriented along the X axis.
func BasisYSurface ¶
func BasisYSurface() Surface
BasisYSurface surface returns a surface that is oriented along the Y axis.
func BasisZSurface ¶
func BasisZSurface() Surface
BasisZSurface surface returns a surface that is oriented along the Z axis.
func NewSurface ¶
NewSurface returns a new surface from the specified point and normal.
type Transform ¶
type Transform struct {
// Translation specifies the translation that the transformation applies.
Translation dprec.Vec3
// Rotation specifies the rotation that the transformation applies.
Rotation dprec.Quat
}
Transform represents a shape transformation.
func ChainedTransform ¶
ChainedTransform returns the Transform that is the result of combining two Transforms together.
func IdentityTransform ¶
func IdentityTransform() Transform
IdentityTransform returns a new Transform that represents the origin.
func RotationTransform ¶
RotationTransform returns a new Transform that represents a rotation.
func TRTransform ¶
TRTransform returns a new Transform that represents both a translation and a rotation.
func TranslationTransform ¶
TranslationTransform returns a new Transform that represents a translation.
type Triangle ¶
type Triangle struct {
// A is the first vertex of the triangle.
A dprec.Vec3
// B is the second vertex of the triangle.
B dprec.Vec3
// C is the third vertex of the triangle.
C dprec.Vec3
}
Triangle represents a tringle in 3D space.
func NewTriangle ¶
NewTriangle creates a new Triangle shape.
func TransformedTriangle ¶
TransformedTriangle creates a new triangle from the specified source triangle by applying the specified transformation.
func (*Triangle) BoundingSphere ¶
BoundingSphere returns a Sphere shape that encompases this triangle.
func (*Triangle) ContainsPoint ¶
ContainsPoint checks whether the specified Point is inside the triangle.
Beware, currently this method assumes that the point lies somewhere on the surface plane of the triangle.
func (*Triangle) IsLookingTowards ¶
IsLookingTowards checks whether the orientation of the triangle looks towards the same hemisphere as the provided direction.
type VisitorBucket ¶
type VisitorBucket[T any] struct { // contains filtered or unexported fields }
VisitorBucket can be used to store items returned from a query.
func NewVisitorBucket ¶
func NewVisitorBucket[T any](initCapacity int) *VisitorBucket[T]
NewVisitorBucket creates a new VisitorBucket instance with the specified initial capacity, which is only used to preallocate memory (it is allowed to exceed the initial capacity).
func (*VisitorBucket[T]) Add ¶
func (r *VisitorBucket[T]) Add(item T) bool
Add records the passed item into the bucket.
func (*VisitorBucket[T]) Each ¶
func (r *VisitorBucket[T]) Each(yield func(item T) bool)
Each calls the provided closure function for each stored item.
func (*VisitorBucket[T]) Items ¶
func (r *VisitorBucket[T]) Items() []T
Items returns the underlying slice of stored items. The returned slice is valid only until the Reset function is called.
func (*VisitorBucket[T]) VisitorFunc ¶
func (r *VisitorBucket[T]) VisitorFunc() VisitorFunc[T]
VisitorFunc returns a VisitorFunc that can be passed to query functions.
Make sure to call Reset before reusing the bucket, unless you want to append to the existing items.
type VisitorFunc ¶
VisitorFunc is a mechanism to receive items from a query.
Source Files
¶
- box.go
- circle.go
- common.go
- doc.go
- filter.go
- intersection.go
- intersection_box_mesh.go
- intersection_object.go
- intersection_segment_box.go
- intersection_segment_circle.go
- intersection_segment_mesh.go
- intersection_segment_sphere.go
- intersection_segment_surface.go
- intersection_segment_triangle.go
- intersection_sphere_box.go
- intersection_sphere_mesh.go
- intersection_sphere_sphere.go
- intersection_sphere_triangle.go
- logger.go
- mesh.go
- object.go
- object_box.go
- object_mesh.go
- object_shape.go
- object_sphere.go
- scene.go
- segment.go
- sphere.go
- surface.go
- transform.go
- tree_compact.go
- triangle.go
- visitor.go