Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/SoftBody/SoftBodyCreationSettings.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2023 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/SoftBody/SoftBodySharedSettings.h>7#include <Jolt/Physics/Collision/ObjectLayer.h>8#include <Jolt/Physics/Collision/CollisionGroup.h>9#include <Jolt/ObjectStream/SerializableObject.h>10#include <Jolt/Core/StreamUtils.h>1112JPH_NAMESPACE_BEGIN1314/// This class contains the information needed to create a soft body object15/// Note: Soft bodies are still in development and come with several caveats. Read the Architecture and API documentation for more information!16class JPH_EXPORT SoftBodyCreationSettings17{18JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, SoftBodyCreationSettings)1920public:21/// Constructor22SoftBodyCreationSettings() = default;23SoftBodyCreationSettings(const SoftBodySharedSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, ObjectLayer inObjectLayer) : mSettings(inSettings), mPosition(inPosition), mRotation(inRotation), mObjectLayer(inObjectLayer) { }2425/// Saves the state of this object in binary form to inStream. Doesn't store the shared settings nor the group filter.26void SaveBinaryState(StreamOut &inStream) const;2728/// Restore the state of this object from inStream. Doesn't restore the shared settings nor the group filter.29void RestoreBinaryState(StreamIn &inStream);3031using GroupFilterToIDMap = StreamUtils::ObjectToIDMap<GroupFilter>;32using IDToGroupFilterMap = StreamUtils::IDToObjectMap<GroupFilter>;33using SharedSettingsToIDMap = SoftBodySharedSettings::SharedSettingsToIDMap;34using IDToSharedSettingsMap = SoftBodySharedSettings::IDToSharedSettingsMap;35using MaterialToIDMap = StreamUtils::ObjectToIDMap<PhysicsMaterial>;36using IDToMaterialMap = StreamUtils::IDToObjectMap<PhysicsMaterial>;3738/// Save this body creation settings, its shared settings and group filter. Pass in an empty map in ioSharedSettingsMap / ioMaterialMap / ioGroupFilterMap or reuse the same map while saving multiple shapes to the same stream in order to avoid writing duplicates.39/// Pass nullptr to ioSharedSettingsMap and ioMaterial map to skip saving shared settings and materials40/// Pass nullptr to ioGroupFilterMap to skip saving group filters41void SaveWithChildren(StreamOut &inStream, SharedSettingsToIDMap *ioSharedSettingsMap, MaterialToIDMap *ioMaterialMap, GroupFilterToIDMap *ioGroupFilterMap) const;4243using SBCSResult = Result<SoftBodyCreationSettings>;4445/// Restore a shape, all its children and materials. Pass in an empty map in ioSharedSettingsMap / ioMaterialMap / ioGroupFilterMap or reuse the same map while reading multiple shapes from the same stream in order to restore duplicates.46static SBCSResult sRestoreWithChildren(StreamIn &inStream, IDToSharedSettingsMap &ioSharedSettingsMap, IDToMaterialMap &ioMaterialMap, IDToGroupFilterMap &ioGroupFilterMap);4748RefConst<SoftBodySharedSettings> mSettings; ///< Defines the configuration of this soft body4950RVec3 mPosition { RVec3::sZero() }; ///< Initial position of the soft body51Quat mRotation { Quat::sIdentity() }; ///< Initial rotation of the soft body5253/// User data value (can be used by application)54uint64 mUserData = 0;5556///@name Collision settings57ObjectLayer mObjectLayer = 0; ///< The collision layer this body belongs to (determines if two objects can collide)58CollisionGroup mCollisionGroup; ///< The collision group this body belongs to (determines if two objects can collide)5960uint32 mNumIterations = 5; ///< Number of solver iterations61float mLinearDamping = 0.1f; ///< Linear damping: dv/dt = -mLinearDamping * v62float mMaxLinearVelocity = 500.0f; ///< Maximum linear velocity that a vertex can reach (m/s)63float mRestitution = 0.0f; ///< Restitution when colliding64float mFriction = 0.2f; ///< Friction coefficient when colliding65float mPressure = 0.0f; ///< n * R * T, amount of substance * ideal gas constant * absolute temperature, see https://en.wikipedia.org/wiki/Pressure66float mGravityFactor = 1.0f; ///< Value to multiply gravity with for this body67bool mUpdatePosition = true; ///< Update the position of the body while simulating (set to false for something that is attached to the static world)68bool mMakeRotationIdentity = true; ///< Bake specified mRotation in the vertices and set the body rotation to identity (simulation is slightly more accurate if the rotation of a soft body is kept to identity)69bool mAllowSleeping = true; ///< If this body can go to sleep or not70};7172JPH_NAMESPACE_END737475