9#ifndef AVARA3D_PHYSICS_SHAPE_PHYSICSSHAPE_H
10#define AVARA3D_PHYSICS_SHAPE_PHYSICSSHAPE_H
15#include <unordered_set>
18#include "a3d/physics/PhysicsBody.h"
25class PhysicsShapeProxy;
49 enum class Type : uint8_t {
58 using Source = std::variant<std::monostate, std::weak_ptr<Mesh>, std::weak_ptr<Node>>;
63 static std::shared_ptr<PhysicsShape>
BoundingBoxShape(
const std::shared_ptr<Mesh>& mesh);
66 static std::shared_ptr<PhysicsShape>
BoundingBoxShape(
const std::shared_ptr<Node>& node);
69 static std::shared_ptr<PhysicsShape>
ConvexHullShape(
const std::shared_ptr<Mesh>& mesh);
72 static std::shared_ptr<PhysicsShape>
ConvexHullShape(
const std::shared_ptr<Node>& node);
155 virtual bool supportsMargin()
const;
165 void checkCreateProxy();
167 const std::unordered_set<PhysicsBody*>& bodies()
const;
169 const std::optional<float>& marginOverride()
const;
171 PhysicsShapeProxy* proxy()
const;
181 std::unique_ptr<PhysicsShapeProxy> _proxy;
186 std::optional<float> _margin;
188 std::unordered_set<PhysicsBody*> _bodies;
Rigid-body simulation state attached to a Node.
Type
Determines how a rigid body participates in simulation.
Describes collision geometry used by one or more PhysicsBody objects.
PhysicsShape(Type type, const std::shared_ptr< Mesh > &mesh)
Creates a PhysicsShape of type derived from mesh.
virtual Type type() const
Returns the collision-geometry type.
static std::shared_ptr< PhysicsShape > ConcavePolyhedronShape(const std::shared_ptr< Node > &node)
Creates a concave-polyhedron collision shape from mesh geometry in the node hierarchy.
static std::shared_ptr< PhysicsShape > BoundingBoxShape(const std::shared_ptr< Node > &node)
Creates a bounding-box collision shape from mesh geometry in the node hierarchy.
std::variant< std::monostate, std::weak_ptr< Mesh >, std::weak_ptr< Node > > Source
Weak source object used to derive collision geometry, or no source for primitive shapes.
Source source() const
Returns the weak Mesh or Node source, or std::monostate for a source-less primitive shape.
virtual void type(Type type)
Validates the requested collision-geometry type.
void margin(float margin)
Sets a uniform collision margin for this shape.
static std::shared_ptr< PhysicsShape > ConcavePolyhedronShape(const std::shared_ptr< Mesh > &mesh)
Creates a concave-polyhedron collision shape derived from mesh.
static std::shared_ptr< PhysicsShape > BoundingBoxShape(const std::shared_ptr< Mesh > &mesh)
Creates a bounding-box collision shape derived from mesh.
Type
Collision-geometry representation requested for a PhysicsShape.
static std::shared_ptr< PhysicsShape > ConvexHullShape(const std::shared_ptr< Mesh > &mesh)
Creates a convex-hull collision shape derived from mesh.
static std::shared_ptr< PhysicsShape > ConvexHullShape(const std::shared_ptr< Node > &node)
Creates a convex-hull collision shape from mesh geometry in the node hierarchy.
PhysicsShape(Type type, const std::shared_ptr< Node > &node)
Creates a PhysicsShape of type from mesh geometry in the node hierarchy.
float margin() const
Returns the collision margin used by this shape.
Simulates rigid bodies and performs physics collision queries for a Scene.