include/PxPhysics.h

File members: include/PxPhysics.h

// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2024 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.

#ifndef PX_PHYSICS_H
#define PX_PHYSICS_H

#include "PxPhysXConfig.h"
#include "PxDeletionListener.h"
#include "foundation/PxTransform.h"
#include "PxShape.h"
#include "PxAggregate.h"
#include "PxParticleSystem.h"
#include "PxDeformableSurface.h"
#include "PxDeformableAttachment.h"
#include "PxDeformableElementFilter.h"
#include "foundation/PxPreprocessor.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

class PxScene;
class PxSceneDesc;
class PxTolerancesScale;
class PxPvd;
class PxOmniPvd;
class PxInsertionCallback;

class PxRigidActor;
class PxConstraintConnector;
struct PxConstraintShaderTable;

class PxGeometry;
class PxFoundation;

class PxPruningStructure;
class PxBVH;

class PxParticleClothBuffer;
class PxParticleRigidBuffer;

class PxDeformableVolumeMesh;

class PxInputStream;

class PxPhysics
{
public:

    //\{

    virtual ~PxPhysics() {}

    virtual void release() = 0;

    virtual PxFoundation& getFoundation() = 0;

    virtual PxOmniPvd* getOmniPvd() = 0;

    virtual PxAggregate* createAggregate(PxU32 maxActor, PxU32 maxShape, PxAggregateFilterHint filterHint) = 0;

    virtual const PxTolerancesScale& getTolerancesScale() const = 0;

    //\}
    //\{

    virtual PxTriangleMesh* createTriangleMesh(PxInputStream& stream) = 0;

    virtual PxU32 getNbTriangleMeshes() const = 0;

    virtual PxU32 getTriangleMeshes(PxTriangleMesh** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    //\}
    //\{

    virtual PxTetrahedronMesh* createTetrahedronMesh(PxInputStream& stream) = 0;

    virtual PxDeformableVolumeMesh* createDeformableVolumeMesh(PxInputStream& stream) = 0;

    PX_DEPRECATED PX_FORCE_INLINE PxDeformableVolumeMesh* createSoftBodyMesh(PxInputStream& stream)
    {
        return createDeformableVolumeMesh(stream);
    }

    virtual PxU32 getNbTetrahedronMeshes() const = 0;

    virtual PxU32 getTetrahedronMeshes(PxTetrahedronMesh** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    virtual PxHeightField* createHeightField(PxInputStream& stream) = 0;

    virtual PxU32 getNbHeightFields() const = 0;

    virtual PxU32 getHeightFields(PxHeightField** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    virtual PxConvexMesh* createConvexMesh(PxInputStream& stream) = 0;

    virtual PxU32 getNbConvexMeshes() const = 0;

    virtual PxU32 getConvexMeshes(PxConvexMesh** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    virtual PxBVH* createBVH(PxInputStream& stream) = 0;

    virtual PxU32 getNbBVHs() const = 0;

    virtual PxU32 getBVHs(PxBVH** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    //\}
    //\{

    virtual PxScene* createScene(const PxSceneDesc& sceneDesc) = 0;

    virtual PxU32 getNbScenes() const = 0;

    virtual PxU32 getScenes(PxScene** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    //\}
    //\{

    virtual PxRigidStatic* createRigidStatic(const PxTransform& pose) = 0;

    virtual PxRigidDynamic* createRigidDynamic(const PxTransform& pose) = 0;

    virtual PxPruningStructure* createPruningStructure(PxRigidActor*const* actors, PxU32 nbActors) = 0;

    //\}
    //\{

    PX_FORCE_INLINE PxShape* createShape(   const PxGeometry& geometry,
                                            const PxMaterial& material,
                                            bool isExclusive = false,
                                            PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE)
    {
        PxMaterial* materialPtr = const_cast<PxMaterial*>(&material);
        return createShape(geometry, &materialPtr, 1, isExclusive, shapeFlags);
    }

    PX_FORCE_INLINE PxShape* createShape(   const PxGeometry& geometry,
                                            const PxDeformableVolumeMaterial& material,
                                            bool isExclusive = false,
                                            PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE)
    {
        PxDeformableVolumeMaterial* materialPtr = const_cast<PxDeformableVolumeMaterial*>(&material);
        return createShape(geometry, &materialPtr, 1, isExclusive, shapeFlags);
    }

    PX_FORCE_INLINE PxShape* createShape(   const PxGeometry& geometry,
                                            const PxDeformableSurfaceMaterial& material,
                                            bool isExclusive = false,
                                            PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE)
    {
        PxDeformableSurfaceMaterial* materialPtr = const_cast<PxDeformableSurfaceMaterial*>(&material);
        return createShape(geometry, &materialPtr, 1, isExclusive, shapeFlags);
    }

    virtual PxShape* createShape(   const PxGeometry& geometry,
                                    PxMaterial*const * materials,
                                    PxU16 materialCount,
                                    bool isExclusive = false,
                                    PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE) = 0;

    virtual PxShape* createShape(   const PxGeometry& geometry,
                                    PxDeformableSurfaceMaterial*const * materials,
                                    PxU16 materialCount,
                                    bool isExclusive = false,
                                    PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE) = 0;

    virtual PxShape* createShape(   const PxGeometry& geometry,
                                    PxDeformableVolumeMaterial*const * materials,
                                    PxU16 materialCount,
                                    bool isExclusive = false,
                                    PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE) = 0;

    virtual PxU32 getNbShapes() const = 0;

    virtual PxU32 getShapes(PxShape** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    //\}
    //\{

    virtual PxConstraint* createConstraint(PxRigidActor* actor0, PxRigidActor* actor1, PxConstraintConnector& connector, const PxConstraintShaderTable& shaders, PxU32 dataSize) = 0;

    virtual PxArticulationReducedCoordinate* createArticulationReducedCoordinate() = 0;

    virtual PxDeformableAttachment* createDeformableAttachment(const PxDeformableAttachmentData& data) = 0;

    virtual PxDeformableElementFilter* createDeformableElementFilter(const PxDeformableElementFilterData& data) = 0;

    virtual PxDeformableSurface* createDeformableSurface(PxCudaContextManager& cudaContextManager) = 0;

    virtual PxDeformableVolume* createDeformableVolume(PxCudaContextManager& cudaContextManager) = 0;

    PX_DEPRECATED PX_FORCE_INLINE PxDeformableVolume* createSoftBody(PxCudaContextManager& cudaContextManager)
    {
        return createDeformableVolume(cudaContextManager);
    }

    virtual PxPBDParticleSystem* createPBDParticleSystem(PxCudaContextManager& cudaContextManager, PxU32 maxNeighborhood = 96, PxReal neighborhoodScale = 1.01f) = 0;

    virtual PxParticleBuffer* createParticleBuffer(PxU32 maxParticles, PxU32 maxVolumes, PxCudaContextManager* cudaContextManager) = 0;

    virtual PxParticleAndDiffuseBuffer* createParticleAndDiffuseBuffer(PxU32 maxParticles, PxU32 maxVolumes, PxU32 maxDiffuseParticles, PxCudaContextManager* cudaContextManager) = 0;

    virtual PxParticleClothBuffer* createParticleClothBuffer(PxU32 maxParticles, PxU32 maxNumVolumes, PxU32 maxNumCloths, PxU32 maxNumTriangles, PxU32 maxNumSprings, PxCudaContextManager* cudaContextManager) = 0;

    virtual PxParticleRigidBuffer* createParticleRigidBuffer(PxU32 maxParticles, PxU32 maxNumVolumes, PxU32 maxNumRigids, PxCudaContextManager* cudaContextManager) = 0;

    //\}
    //\{

    virtual PxMaterial* createMaterial(PxReal staticFriction, PxReal dynamicFriction, PxReal restitution) = 0;

    virtual PxU32 getNbMaterials() const = 0;

    virtual PxU32 getMaterials(PxMaterial** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    virtual PxDeformableSurfaceMaterial* createDeformableSurfaceMaterial(PxReal youngs, PxReal poissons, PxReal dynamicFriction,
        PxReal thickness = 0.001f, PxReal bendingStiffness = 0.0f, PxReal damping = 0.0f, PxReal bendingDamping = 0.0f) = 0;

    virtual PxU32 getNbDeformableSurfaceMaterials() const = 0;

    virtual PxU32 getDeformableSurfaceMaterials(PxDeformableSurfaceMaterial** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    virtual PxDeformableVolumeMaterial* createDeformableVolumeMaterial(PxReal youngs, PxReal poissons, PxReal dynamicFriction) = 0;

    PX_DEPRECATED PX_FORCE_INLINE PxDeformableVolumeMaterial* createFEMSoftBodyMaterial(PxReal youngs, PxReal poissons, PxReal dynamicFriction)
    {
        return createDeformableVolumeMaterial(youngs, poissons, dynamicFriction);
    }

    virtual PxU32 getNbDeformableVolumeMaterials() const = 0;

    PX_DEPRECATED PX_FORCE_INLINE PxU32 getNbFEMSoftBodyMaterials() const
    {
        return getNbDeformableVolumeMaterials();
    }

    virtual PxU32 getDeformableVolumeMaterials(PxDeformableVolumeMaterial** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    PX_DEPRECATED PX_FORCE_INLINE PxU32 getFEMSoftBodyMaterials(PxDeformableVolumeMaterial** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const
    {
        return getDeformableVolumeMaterials(userBuffer, bufferSize, startIndex);
    }

    virtual PxPBDMaterial* createPBDMaterial(PxReal friction, PxReal damping, PxReal adhesion, PxReal viscosity, PxReal vorticityConfinement, PxReal surfaceTension, PxReal cohesion, PxReal lift, PxReal drag, PxReal cflCoefficient = 1.f, PxReal gravityScale = 1.f) = 0;

    virtual PxU32 getNbPBDMaterials() const = 0;

    virtual PxU32 getPBDMaterials(PxPBDMaterial** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const = 0;

    //\}
    //\{

    virtual void registerDeletionListener(PxDeletionListener& observer, const PxDeletionEventFlags& deletionEvents, bool restrictedObjectSet = false) = 0;

    virtual void unregisterDeletionListener(PxDeletionListener& observer) = 0;

    virtual void registerDeletionListenerObjects(PxDeletionListener& observer, const PxBase* const* observables, PxU32 observableCount) = 0;

    virtual void unregisterDeletionListenerObjects(PxDeletionListener& observer, const PxBase* const* observables, PxU32 observableCount) = 0;

    virtual PxInsertionCallback& getPhysicsInsertionCallback() = 0;

    //\}
};

#if !PX_DOXYGEN
} // namespace physx
#endif

PX_C_EXPORT PX_PHYSX_CORE_API  physx::PxPhysics* PxCreatePhysics(physx::PxU32 version,
                                                                physx::PxFoundation& foundation,
                                                                const physx::PxTolerancesScale& scale,
                                                                bool trackOutstandingAllocations = false,
                                                                physx::PxPvd* pvd = NULL,
                                                                physx::PxOmniPvd* omniPvd = NULL);

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreturn-type-c-linkage"
#endif

PX_C_EXPORT PX_PHYSX_CORE_API physx::PxPhysics& PX_CALL_CONV PxGetPhysics();

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif