9#ifndef AVARA3D_SCENE_SCENE_H
10#define AVARA3D_SCENE_SCENE_H
20#include "a3d/input/InputContext.h"
21#include "a3d/util/Bitmask.h"
52 ImportMeshes = 1 << 0,
53 ImportMaterials = 1 << 1,
54 ImportLights = 1 << 2,
55 ImportCameras = 1 << 3,
56 ImportAll = UINT16_MAX
64 ShowStatsOverlay = 1 << 0,
66 ShowMeshBounds = 1 << 1,
67 ShowMeshFrames = 1 << 2,
68 ShowMeshWireframes = 1 << 3,
72 ShowLightExtents = 1 << 6,
74 ShowPhysicsBounds = 1 << 7,
75 ShowPhysicsFrames = 1 << 8,
76 ShowPhysicsWireframes = 1 << 9,
77 ShowPhysicsContactPoints = 1 << 10,
78 ShowPhysicsNormals = 1 << 11,
80 ShowPhysicsConstraints = 1 << 12,
82 ShowPhysicsConstraintLimits =
117 static std::unique_ptr<Scene>
FromFile(
const std::filesystem::path& path,
158 const std::optional<std::string>&
name()
const;
229 void pollEvents(Profiler& profiler);
231 void stepSimulation(
const StepInfo& info, Profiler& profiler);
236 std::optional<std::string> _name;
237 std::shared_ptr<Node> _rootNode;
238 std::unique_ptr<VisualWorld> _visualWorld;
239 std::unique_ptr<PhysicsWorld> _physicsWorld;
240 std::unique_ptr<InputContext> _inputContext;
246 namespace util::bitmask {
249 struct enable_ops<
Scene::ImportOptions> : std::true_type {};
252 struct enable_ops<Scene::DebugOptions> : std::true_type {};
Base interface for Scene input state updated once per Runner host update.
Simulates rigid bodies and performs physics collision queries for a Scene.
Owns a scene graph and the worlds used to simulate and render it.
InputContext * inputContext() const
Returns the owned InputContext, or nullptr if none is installed.
PhysicsWorld * physicsWorld() const
Returns the owned PhysicsWorld, or nullptr if none is installed.
void willStepCallback(WillStepCallback callback)
Replaces the callback invoked before each simulation step; an empty callback disables it.
VisualWorld * visualWorld() const
Returns the owned VisualWorld, or nullptr if none is installed.
Scene(const std::string &name, std::unique_ptr< VisualWorld > visualWorld, std::unique_ptr< PhysicsWorld > physicsWorld, std::unique_ptr< InputContext > inputContext)
Creates a named Scene and takes ownership of its optional worlds and input context.
std::function< void(Scene &scene, const StepInfo &info)> DidStepCallback
Callback invoked immediately after a Scene simulation step.
DebugOptions debugOptions() const
Returns the enabled Scene debug visualization options.
std::function< void(Scene &scene, const StepInfo &info)> WillStepCallback
Callback invoked immediately before a Scene simulation step.
Scene(std::unique_ptr< VisualWorld > visualWorld, std::unique_ptr< PhysicsWorld > physicsWorld, std::unique_ptr< InputContext > inputContext)
Creates a Scene and takes ownership of its optional worlds and input context.
void physicsWorld(std::unique_ptr< PhysicsWorld > world)
Replaces the owned PhysicsWorld; nullptr removes the current world.
const std::optional< std::string > & name() const
Returns the optional Scene name.
void didStepCallback(DidStepCallback callback)
Replaces the callback invoked after each simulation step; an empty callback disables it.
static std::unique_ptr< Scene > FromFile(const std::filesystem::path &path, ImportOptions options=ImportOptions::ImportAll)
Imports a Scene from path.
AABB aabb(bool vertfit=false) const
Returns the world-space axis-aligned bounding box enclosing the Scene hierarchy.
Scene(const std::string &name)
Creates a named Scene with an empty root node and no worlds or input context.
math::vec3 extent(bool vertfit=false) const
Returns the dimensions of the Scene world-space axis-aligned bounding box.
void inputContext(std::unique_ptr< InputContext > context)
Replaces the owned InputContext; nullptr removes the current context.
DidStepCallback didStepCallback() const
Returns the callback invoked after each simulation step.
void visualWorld(std::unique_ptr< VisualWorld > world)
Replaces the owned VisualWorld; nullptr removes the current world.
WillStepCallback willStepCallback() const
Returns the callback invoked before each simulation step.
Scene()
Creates a Scene with an empty root node and no worlds or input context.
ImportOptions
Selects which resource categories are imported by FromFile().
@ ImportAll
Import all supported resource categories.
void name(const std::string &name)
Sets the Scene name.
void rootNode(const std::shared_ptr< Node > &node)
Replaces the root node of the Scene hierarchy.
DebugOptions
Scene-wide debug visualization options.
const std::shared_ptr< Node > & rootNode() const
Returns the root node of the Scene hierarchy.
void debugOptions(DebugOptions options)
Sets the enabled Scene debug visualization options.
Manages the visual presentation, camera, and visual queries for a Scene.
Axis-aligned bounding box defined by minimum and maximum corners.
Timing information for one input update.
Timing information for one simulation step.
std::uint64_t stepIndex
Zero-based simulation-step index.
double endTime
Simulation time in seconds after this step completes.
double startTime
Simulation time in seconds before this step.
double deltaTime
Amount of simulation time in seconds advanced by this step.