Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/PhysicsScene.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Core/Reference.h>7#include <Jolt/Physics/Body/BodyCreationSettings.h>8#include <Jolt/Physics/SoftBody/SoftBodyCreationSettings.h>9#include <Jolt/Physics/Constraints/TwoBodyConstraint.h>1011JPH_NAMESPACE_BEGIN1213class PhysicsSystem;1415/// Contains the creation settings of a set of bodies16class JPH_EXPORT PhysicsScene : public RefTarget<PhysicsScene>17{18JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, PhysicsScene)1920public:21/// Add a body to the scene22void AddBody(const BodyCreationSettings &inBody);2324/// Body constant to use to indicate that the constraint is attached to the fixed world25static constexpr uint32 cFixedToWorld = 0xffffffff;2627/// Add a constraint to the scene28/// @param inConstraint Constraint settings29/// @param inBody1 Index in the bodies list of first body to attach constraint to30/// @param inBody2 Index in the bodies list of the second body to attach constraint to31void AddConstraint(const TwoBodyConstraintSettings *inConstraint, uint32 inBody1, uint32 inBody2);3233/// Add a soft body to the scene34void AddSoftBody(const SoftBodyCreationSettings &inSoftBody);3536/// Get number of bodies in this scene37size_t GetNumBodies() const { return mBodies.size(); }3839/// Access to the body settings for this scene40const Array<BodyCreationSettings> & GetBodies() const { return mBodies; }41Array<BodyCreationSettings> & GetBodies() { return mBodies; }4243/// A constraint and how it is connected to the bodies in the scene44class ConnectedConstraint45{46JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, ConnectedConstraint)4748public:49ConnectedConstraint() = default;50ConnectedConstraint(const TwoBodyConstraintSettings *inSettings, uint inBody1, uint inBody2) : mSettings(inSettings), mBody1(inBody1), mBody2(inBody2) { }5152RefConst<TwoBodyConstraintSettings> mSettings; ///< Constraint settings53uint32 mBody1; ///< Index of first body (in mBodies)54uint32 mBody2; ///< Index of second body (in mBodies)55};5657/// Get number of constraints in this scene58size_t GetNumConstraints() const { return mConstraints.size(); }5960/// Access to the constraints for this scene61const Array<ConnectedConstraint> & GetConstraints() const { return mConstraints; }62Array<ConnectedConstraint> & GetConstraints() { return mConstraints; }6364/// Get number of bodies in this scene65size_t GetNumSoftBodies() const { return mSoftBodies.size(); }6667/// Access to the soft body settings for this scene68const Array<SoftBodyCreationSettings> & GetSoftBodies() const { return mSoftBodies; }69Array<SoftBodyCreationSettings> & GetSoftBodies() { return mSoftBodies; }7071/// Instantiate all bodies, returns false if not all bodies could be created72bool CreateBodies(PhysicsSystem *inSystem) const;7374/// Go through all body creation settings and fix shapes that are scaled incorrectly (note this will change the scene a bit).75/// @return False when not all scales could be fixed.76bool FixInvalidScales();7778/// Saves the state of this object in binary form to inStream.79/// @param inStream The stream to save the state to80/// @param inSaveShapes If the shapes should be saved as well (these could be shared between physics scenes, in which case the calling application may want to write custom code to restore them)81/// @param inSaveGroupFilter If the group filter should be saved as well (these could be shared)82void SaveBinaryState(StreamOut &inStream, bool inSaveShapes, bool inSaveGroupFilter) const;8384using PhysicsSceneResult = Result<Ref<PhysicsScene>>;8586/// Restore a saved scene from inStream87static PhysicsSceneResult sRestoreFromBinaryState(StreamIn &inStream);8889/// For debugging purposes: Construct a scene from the current state of the physics system90void FromPhysicsSystem(const PhysicsSystem *inSystem);9192private:93/// The bodies that are part of this scene94Array<BodyCreationSettings> mBodies;9596/// Constraints that are part of this scene97Array<ConnectedConstraint> mConstraints;9899/// Soft bodies that are part of this scene100Array<SoftBodyCreationSettings> mSoftBodies;101};102103JPH_NAMESPACE_END104105106