9#ifndef AVARA3D_PHYSICS_SHAPE_PHYSICSSHAPE_H
10#define AVARA3D_PHYSICS_SHAPE_PHYSICSSHAPE_H
14#include <unordered_set>
17#include "a3d/physics/PhysicsBody.h"
24 class PhysicsShapeProxy;
43 enum class Type : uint8_t {
52 using Source = std::variant<std::monostate, std::weak_ptr<Mesh>, std::weak_ptr<Node>>;
57 static std::shared_ptr<PhysicsShape>
BoundingBoxShape(
const std::shared_ptr<Mesh>& mesh);
60 static std::shared_ptr<PhysicsShape>
BoundingBoxShape(
const std::shared_ptr<Node>& node);
63 static std::shared_ptr<PhysicsShape>
ConvexHullShape(
const std::shared_ptr<Mesh>& mesh);
66 static std::shared_ptr<PhysicsShape>
ConvexHullShape(
const std::shared_ptr<Node>& node);
128 void checkCreateProxy();
130 const std::unordered_set<PhysicsBody*>& bodies()
const;
132 PhysicsShapeProxy* proxy()
const;
142 std::unique_ptr<PhysicsShapeProxy> _proxy;
148 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.
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.
Simulates rigid bodies and performs physics collision queries for a Scene.