Init
This commit is contained in:
1236
physx/samples/samplelargeworld/ChunkLoader.cpp
Normal file
1236
physx/samples/samplelargeworld/ChunkLoader.cpp
Normal file
File diff suppressed because it is too large
Load Diff
242
physx/samples/samplelargeworld/ChunkLoader.h
Normal file
242
physx/samples/samplelargeworld/ChunkLoader.h
Normal file
@ -0,0 +1,242 @@
|
||||
//
|
||||
// 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-2021 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 CHUNKLOADER_H
|
||||
#define CHUNKLOADER_H
|
||||
|
||||
#include "PsMutex.h"
|
||||
#include "PsThread.h"
|
||||
#include "PhysXSample.h"
|
||||
|
||||
#include "PsTime.h"
|
||||
|
||||
#define ENABLE_PROGRESS_BAR 1
|
||||
|
||||
typedef PxU16 CoordType;
|
||||
typedef PxU32 IDType;
|
||||
|
||||
#define N1 7
|
||||
//The terrain has 16*16 grids
|
||||
#define N2 256
|
||||
|
||||
//The width of each terrain chunk, this is the hardcoded number accroding to Terrain.bin
|
||||
#define CHUNK_WIDTH 256.0f
|
||||
|
||||
#define MATERIAL_ROAD_GRASS 1003
|
||||
#define MATERIAL_BRICKS 1004
|
||||
#define MATERIAL_BUILDING 1005
|
||||
#define MATERIAL_FARM 1006
|
||||
#define MATERIAL_TREE 1007
|
||||
|
||||
PX_FORCE_INLINE PxShape* getShape(const PxRigidActor& actor)
|
||||
{
|
||||
PX_ASSERT(actor.getNbShapes() >= 1);
|
||||
PxShape* shape = NULL;
|
||||
actor.getShapes(&shape, 1);
|
||||
return shape;
|
||||
}
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct{
|
||||
CoordType x, y;
|
||||
} coord;
|
||||
IDType id;
|
||||
|
||||
}ChunkID;
|
||||
|
||||
static PX_INLINE bool operator < (const ChunkID& _Left, const ChunkID& _Right)
|
||||
{
|
||||
return _Left.id < _Right.id;
|
||||
}
|
||||
static PX_INLINE bool operator == (const ChunkID& _Left, PxU32 _Right)
|
||||
{
|
||||
return _Left.id == _Right;
|
||||
}
|
||||
|
||||
static PX_INLINE bool operator == (const ChunkID& _Left, ChunkID _Right)
|
||||
{
|
||||
return _Left.id == _Right.id;
|
||||
}
|
||||
|
||||
struct ChunkCommandType
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eAdd,
|
||||
eRemove
|
||||
};
|
||||
};
|
||||
|
||||
struct ChunkCommand
|
||||
{
|
||||
ChunkCommand(ChunkCommandType::Enum _type, const ChunkID& _id)
|
||||
{
|
||||
type = _type;
|
||||
id = _id;
|
||||
}
|
||||
|
||||
ChunkCommandType::Enum type;
|
||||
ChunkID id;
|
||||
};
|
||||
|
||||
struct DynamicObjects
|
||||
{
|
||||
DynamicObjects(PxRigidDynamic* _actor, bool _isImportant)
|
||||
{
|
||||
actor = _actor;
|
||||
isImportant = _isImportant;
|
||||
id.id = 0;
|
||||
}
|
||||
|
||||
PxRigidDynamic* actor;
|
||||
bool isImportant;
|
||||
ChunkID id;
|
||||
};
|
||||
|
||||
class SampleLargeWorld;
|
||||
class BackgroundLoader : public SampleAllocateable
|
||||
{
|
||||
public:
|
||||
struct DeferredLoadedRenderData : public RAWMesh
|
||||
{
|
||||
DeferredLoadedRenderData():shape(NULL){}
|
||||
//the shape to link with
|
||||
PxShape* shape;
|
||||
};
|
||||
public:
|
||||
|
||||
BackgroundLoader(SampleLargeWorld& sample, CoordType halfRange, CoordType terrainRange, PxF32 chunkWidth);
|
||||
~BackgroundLoader();
|
||||
|
||||
void addDynamicObject(PxRigidDynamic* inActor, bool inIsImportant)
|
||||
{
|
||||
mDyncActors.push_back(new DynamicObjects(inActor, inIsImportant));
|
||||
updateDynamicChunkId();
|
||||
}
|
||||
|
||||
void onTick();
|
||||
void updateChunk(const PxVec3& cameraPos);
|
||||
|
||||
//The lock for accessing streaming progress and timing status
|
||||
Ps::ReadWriteLock mLoaderStatusLock;
|
||||
|
||||
|
||||
#ifdef ENABLE_PROGRESS_BAR
|
||||
volatile PxU32 mQueryLength;
|
||||
volatile PxF32 mQueryProgress;
|
||||
#endif
|
||||
|
||||
volatile Ps::Time::Second mDiskIOTime;
|
||||
volatile Ps::Time::Second mPhyXStreamTime;
|
||||
volatile Ps::Time::Second mGraphicStreamTime;
|
||||
|
||||
private:
|
||||
const char* getPathname( ChunkID id );
|
||||
|
||||
void serialize(PxCollection* collection, ChunkID id);
|
||||
|
||||
void addReadyChunkToScene(ChunkID id);
|
||||
void destroyChunk(ChunkID id);
|
||||
|
||||
void updateDynamicChunkId();
|
||||
|
||||
//Return NULL means already loaded or cannot load
|
||||
PxCollection* loadChunk(ChunkID id);
|
||||
|
||||
void createRenderObjectsFromCollection(PxCollection* collection);
|
||||
void deleteLoadedRenderQueue();
|
||||
void deleteCollections();
|
||||
|
||||
void* loaderThread();
|
||||
static void* loaderThread(void* loader);
|
||||
|
||||
DeferredLoadedRenderData* createRawMeshFromObjMesh(const char* name, const PxTransform& pos, DeferredLoadedRenderData& rawMesh);
|
||||
|
||||
private:
|
||||
|
||||
struct CollectionMemory
|
||||
{
|
||||
CollectionMemory()
|
||||
: collection(NULL)
|
||||
, memory(NULL)
|
||||
, addToScene(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PxCollection* collection;
|
||||
void* memory;
|
||||
bool addToScene;
|
||||
};
|
||||
|
||||
typedef std::map<ChunkID, CollectionMemory> CollectionIdMap;
|
||||
CollectionIdMap mCollectionIdMap;
|
||||
|
||||
std::vector<ChunkID> mRequestQueue;
|
||||
std::vector<DynamicObjects*> mDyncActors;
|
||||
std::vector<PxActor*> mRemovingActors;
|
||||
|
||||
//We calculate terrain's normals and store here
|
||||
std::vector<DeferredLoadedRenderData> mLoadedRenderDataQueue;
|
||||
|
||||
physx::shdfnd::Thread* mLoaderThread;
|
||||
|
||||
//The lock to access ChunkQueue arrays
|
||||
physx::shdfnd::Mutex mQueueLock;
|
||||
|
||||
//The lock to access mCollectionIdMap
|
||||
physx::shdfnd::Mutex mCollectionLock;
|
||||
|
||||
//A signal to inform background thread new jobs
|
||||
shdfnd::Sync mRequestReady;
|
||||
|
||||
SampleLargeWorld* mSampleLargeWorld;
|
||||
PxPhysics& mPhysics;
|
||||
PxScene& mScene;
|
||||
PxMaterial& mMaterial;
|
||||
|
||||
ChunkID mCurChunkId;
|
||||
CoordType mHalfRange;
|
||||
CoordType mTerrainRange;
|
||||
PxF32 mChunkWidth;
|
||||
|
||||
//Internal Timing varialbe
|
||||
Ps::Time::Second mDiskIOTimeCounter;
|
||||
Ps::Time::Second mPhyXStreamTimeCounter;
|
||||
Ps::Time::Second mGraphicStreamTimeCounter;
|
||||
PxBounds3 mLocalBounds;
|
||||
|
||||
PxSerializationRegistry* mSr;
|
||||
std::vector<ChunkCommand> mChunkCmds;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
181
physx/samples/samplelargeworld/MeshBuilder.cpp
Normal file
181
physx/samples/samplelargeworld/MeshBuilder.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
//
|
||||
// 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-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#include "SampleDirManager.h"
|
||||
#include "SampleLargeWorld.h"
|
||||
#include "MeshBuilder.h"
|
||||
#include "wavefront.h"
|
||||
|
||||
using namespace PxToolkit;
|
||||
using namespace physx;
|
||||
using namespace shdfnd;
|
||||
|
||||
#define MATERIAL_ID 1
|
||||
|
||||
|
||||
MeshBuilder::MeshBuilder(SampleLargeWorld& sample, const char* filename)
|
||||
: mSampleLargeWorld(&sample)
|
||||
, mPhysics(sample.getPhysics())
|
||||
, mScene(sample.getActiveScene())
|
||||
, mCooking(sample.getCooking())
|
||||
, mMaterial(sample.getDefaultMaterial())
|
||||
, mStringTable(sample.mStringTable)
|
||||
{
|
||||
PxDefaultFileInputData inputStream(filename);
|
||||
PxSerializationRegistry* sr = PxSerialization::createSerializationRegistry(mPhysics);
|
||||
|
||||
PxCollection* c = PxSerialization::createCollectionFromXml(inputStream, mCooking, *sr, NULL, mStringTable);
|
||||
PX_ASSERT( c );
|
||||
|
||||
c->add( mMaterial, MATERIAL_ID );
|
||||
PxSerialization::complete(*c, *sr);
|
||||
|
||||
PxU32 count = c->getNbObjects();
|
||||
for(PxU32 i = 0; i < count; i++)
|
||||
{
|
||||
PxBase* object = &c->getObject(i);
|
||||
switch ( object->getConcreteType() )
|
||||
{
|
||||
case PxConcreteType::eCONVEX_MESH:
|
||||
{
|
||||
PxConvexMesh* j = static_cast<PxConvexMesh*>(object);
|
||||
mConvexMeshes.push_back( j );
|
||||
break;
|
||||
}
|
||||
case PxConcreteType::eTRIANGLE_MESH_BVH33:
|
||||
case PxConcreteType::eTRIANGLE_MESH_BVH34:
|
||||
{
|
||||
PxTriangleMesh* j = static_cast<PxTriangleMesh*>(object);
|
||||
mTriMeshes.push_back(j);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
c->release();
|
||||
sr->release();
|
||||
}
|
||||
|
||||
void MeshBuilder::addObjMeshToPxCollection(
|
||||
PxPhysics& physics,
|
||||
PxCooking& cooking,
|
||||
PxMaterial& material,
|
||||
const char* filename,
|
||||
const char* filenameCooked,
|
||||
const PxTransform& pose,
|
||||
const PxVec3& scale,
|
||||
PxCollection& collection,
|
||||
const char* name)
|
||||
{
|
||||
PxTriangleMesh* mesh = NULL;
|
||||
|
||||
PxDefaultFileInputData cooked(filenameCooked);
|
||||
if (cooked.isValid())
|
||||
{
|
||||
//load from disc
|
||||
mesh = physics.createTriangleMesh(cooked); //if this load fails, maybe old format. try to recook below.
|
||||
}
|
||||
if(!mesh)
|
||||
{
|
||||
WavefrontObj wfo;
|
||||
if (!wfo.loadObj(filename, false))
|
||||
{
|
||||
shdfnd::printFormatted("Error loading file: %s\n", filename);
|
||||
}
|
||||
|
||||
PxTriangleMeshDesc meshDesc;
|
||||
meshDesc.points.count = wfo.mVertexCount;
|
||||
meshDesc.triangles.count = wfo.mTriCount;
|
||||
meshDesc.points.stride = sizeof(float) * 3;
|
||||
meshDesc.triangles.stride = sizeof(int) * 3;
|
||||
meshDesc.points.data = wfo.mVertices;
|
||||
meshDesc.triangles.data = wfo.mIndices;
|
||||
|
||||
bool ok;
|
||||
{
|
||||
PxDefaultFileOutputStream stream(filenameCooked);
|
||||
ok = cooking.cookTriangleMesh(meshDesc, stream);
|
||||
}
|
||||
if ( ok )
|
||||
{
|
||||
PxDefaultFileInputData stream(filenameCooked);
|
||||
mesh = physics.createTriangleMesh(stream);
|
||||
}
|
||||
}
|
||||
PX_ASSERT( mesh );
|
||||
|
||||
PxRigidStatic* actor = physics.createRigidStatic(pose);
|
||||
PX_ASSERT( actor );
|
||||
PxMeshScale meshScale = PxMeshScale(scale, PxQuat(PxIdentity));
|
||||
PxShape* shape = PxRigidActorExt::createExclusiveShape(*actor, PxTriangleMeshGeometry(mesh, meshScale), material);
|
||||
PX_ASSERT( shape );
|
||||
shape->setFlag(PxShapeFlag::eVISUALIZATION, false);
|
||||
if( name )
|
||||
{
|
||||
actor->setName(name);
|
||||
}
|
||||
|
||||
collection.add(*actor);
|
||||
}
|
||||
|
||||
void MeshBuilder::addRepXToPxCollection(
|
||||
const PxTransform& pose,
|
||||
const PxVec3& scale,
|
||||
PxCollection& collection,
|
||||
const char* name)
|
||||
{
|
||||
|
||||
PxRigidStatic* actor = mPhysics.createRigidStatic(pose);
|
||||
PX_ASSERT( actor );
|
||||
|
||||
size_t size = mConvexMeshes.size();
|
||||
PxMeshScale meshScale = PxMeshScale(scale, PxQuat(PxIdentity));
|
||||
for(PxU32 i = 0; i < size; ++i)
|
||||
{
|
||||
PxConvexMesh* mesh = mConvexMeshes[i];
|
||||
PxShape* shape = PxRigidActorExt::createExclusiveShape(*actor, PxConvexMeshGeometry(mesh, meshScale), mMaterial);
|
||||
PX_ASSERT( shape );
|
||||
shape->setFlag(PxShapeFlag::eVISUALIZATION, false);
|
||||
}
|
||||
|
||||
size = mTriMeshes.size();
|
||||
for(PxU32 i = 0; i < size; ++i)
|
||||
{
|
||||
PxTriangleMesh* mesh = mTriMeshes[i];
|
||||
PxShape* shape = PxRigidActorExt::createExclusiveShape(*actor, PxTriangleMeshGeometry(mesh, meshScale), mMaterial);
|
||||
PX_ASSERT( shape );
|
||||
shape->setFlag(PxShapeFlag::eVISUALIZATION, false);
|
||||
}
|
||||
|
||||
if( name )
|
||||
actor->setName(name);
|
||||
|
||||
collection.add(*actor);
|
||||
}
|
||||
75
physx/samples/samplelargeworld/MeshBuilder.h
Normal file
75
physx/samples/samplelargeworld/MeshBuilder.h
Normal file
@ -0,0 +1,75 @@
|
||||
//
|
||||
// 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-2021 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 MESHBUILDER_H
|
||||
#define MESHBUILDER_H
|
||||
|
||||
#include "PhysXSample.h"
|
||||
|
||||
class SampleLargeWorld;
|
||||
class MeshBuilder : public SampleAllocateable
|
||||
{
|
||||
public:
|
||||
MeshBuilder(SampleLargeWorld& sample, const char* filename);
|
||||
~MeshBuilder() {}
|
||||
|
||||
void addRepXToPxCollection(
|
||||
const PxTransform& pose,
|
||||
const PxVec3& scale,
|
||||
PxCollection& collection,
|
||||
const char* name = NULL);
|
||||
|
||||
static void addObjMeshToPxCollection(
|
||||
PxPhysics& physics,
|
||||
PxCooking& cooking,
|
||||
PxMaterial& material,
|
||||
const char* filename,
|
||||
const char* filenameCooked,
|
||||
const PxTransform& pose,
|
||||
const PxVec3& scale,
|
||||
PxCollection& collection,
|
||||
const char* name = NULL);
|
||||
|
||||
private:
|
||||
MeshBuilder& operator=(const MeshBuilder&);
|
||||
SampleLargeWorld* mSampleLargeWorld;
|
||||
|
||||
PxPhysics& mPhysics;
|
||||
PxScene& mScene;
|
||||
PxCooking& mCooking;
|
||||
PxMaterial& mMaterial;
|
||||
PxRigidStatic* mStaticActor;
|
||||
PxStringTable* mStringTable;
|
||||
|
||||
std::vector<PxConvexMesh*> mConvexMeshes;
|
||||
std::vector<PxTriangleMesh*> mTriMeshes;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
1038
physx/samples/samplelargeworld/SampleLargeWorld.cpp
Normal file
1038
physx/samples/samplelargeworld/SampleLargeWorld.cpp
Normal file
File diff suppressed because it is too large
Load Diff
203
physx/samples/samplelargeworld/SampleLargeWorld.h
Normal file
203
physx/samples/samplelargeworld/SampleLargeWorld.h
Normal file
@ -0,0 +1,203 @@
|
||||
//
|
||||
// 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-2021 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 SAMPLE_LARGE_WORLD_H
|
||||
#define SAMPLE_LARGE_WORLD_H
|
||||
|
||||
#include "PhysXSample.h"
|
||||
#include "ChunkLoader.h"
|
||||
#include "characterkinematic/PxController.h"
|
||||
#include "characterkinematic/PxControllerBehavior.h"
|
||||
#include "PxTkRandom.h"
|
||||
|
||||
|
||||
namespace physx
|
||||
{
|
||||
class PxControllerManager;
|
||||
}
|
||||
|
||||
class SampleCCTCameraController;
|
||||
class ControlledActor;
|
||||
class RenderBaseActor;
|
||||
class BackgroundLoader;
|
||||
|
||||
typedef Ps::HashMap<const char*, RAWMesh, Ps::Hash<const char*>, Ps::RawAllocator> ObjMeshMap;
|
||||
|
||||
class SampleLargeWorld : public PhysXSample
|
||||
, public PxUserControllerHitReport, public PxControllerBehaviorCallback, public PxQueryFilterCallback
|
||||
{
|
||||
friend class BackgroundLoader;
|
||||
public:
|
||||
SampleLargeWorld(PhysXSampleApplication& app);
|
||||
virtual ~SampleLargeWorld();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Implements SampleApplication
|
||||
virtual void onInit();
|
||||
virtual void onInit(bool restart) { onInit(); }
|
||||
virtual void onShutdown();
|
||||
virtual void onTickPreRender(PxF32 dtime);
|
||||
virtual void onDigitalInputEvent(const SampleFramework::InputEvent& , bool val);
|
||||
|
||||
//virtual void onRelease(const PxBase* , void* , PxDeletionEventFlag::Enum ) {}
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Implements PhysXSampleApplication
|
||||
virtual void customizeSceneDesc(PxSceneDesc&);
|
||||
virtual void customizeSample(SampleSetup&);
|
||||
virtual void onSubstep(PxF32 dtime);
|
||||
virtual void collectInputEvents(std::vector<const SampleFramework::InputEvent*>& inputEvents);
|
||||
virtual void helpRender(PxU32 x, PxU32 y, PxU8 textAlpha);
|
||||
virtual void descriptionRender(PxU32 x, PxU32 y, PxU8 textAlpha);
|
||||
virtual void customizeRender();
|
||||
virtual void newMesh(const RAWMesh&);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Implements PxUserControllerHitReport
|
||||
virtual void onShapeHit(const PxControllerShapeHit& hit);
|
||||
virtual void onControllerHit(const PxControllersHit& hit) {}
|
||||
virtual void onObstacleHit(const PxControllerObstacleHit& hit) {}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Implements PxControllerBehaviorCallback
|
||||
virtual PxControllerBehaviorFlags getBehaviorFlags(const PxShape& shape, const PxActor& actor);
|
||||
virtual PxControllerBehaviorFlags getBehaviorFlags(const PxController& controller);
|
||||
virtual PxControllerBehaviorFlags getBehaviorFlags(const PxObstacle& obstacle);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Implements PxQueryFilterCallback
|
||||
virtual PxQueryHitType::Enum preFilter(const PxFilterData& filterData, const PxShape* shape, const PxRigidActor* actor, PxHitFlags& queryFlags);
|
||||
virtual PxQueryHitType::Enum postFilter(const PxFilterData& filterData, const PxQueryHit& hit);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Implements PxSimulationFilterShader
|
||||
enum
|
||||
{
|
||||
CCD_FLAG = 1<<29,
|
||||
};
|
||||
|
||||
static PxFilterFlags filter(PxFilterObjectAttributes attributes0,
|
||||
PxFilterData filterData0,
|
||||
PxFilterObjectAttributes attributes1,
|
||||
PxFilterData filterData1,
|
||||
PxPairFlags& pairFlags,
|
||||
const void* constantBlock,
|
||||
PxU32 constantBlockSize);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Create chunk_i_j file
|
||||
void createChunk(CoordType coordX, CoordType coordY, PxCollection& outCollection);
|
||||
|
||||
|
||||
private:
|
||||
RAWMesh* createRawMeshFromMeshGeom(const PxTriangleMeshGeometry& mesh, RAWMesh &rawMesh);
|
||||
RAWMesh* createRAWMeshFromObjMesh(const char* inObjFileName, const PxTransform& inPos, PxU32 inMaterialID, RAWMesh &outRawMesh);
|
||||
|
||||
//Deep cope
|
||||
void cloneMesh(const RAWMesh& inSrc, RAWMesh& outDst);
|
||||
|
||||
void renderProgressBar(PxF32 ratio, bool needFlush = false);
|
||||
void releaseJoints();
|
||||
bool readyToSyncCCT();
|
||||
void attachNearestObjectsToCCT();
|
||||
|
||||
PxRigidDynamic* createBox(const PxVec3& pos, const PxVec3& dims, const PxVec3* linVel,
|
||||
RenderMaterial* material, PxReal density);
|
||||
void addWindMills(const PxTriangleMeshGeometry& meshGeom, PxToolkit::BasicRandom& random,
|
||||
const PxBounds3& bound, PxCollection& outCollection);
|
||||
void addTrees(const PxTriangleMeshGeometry& meshGeom, const PxBounds3& bound, PxCollection& outCollection);
|
||||
void addCity(SampleArray<PxVec3>& terrainVertices, const PxBounds3& bound, PxCollection& outCollection);
|
||||
void addFarm(SampleArray<PxVec3>& terrainVertices, const PxBounds3& bound, PxCollection& outCollection);
|
||||
void addFortress(SampleArray<PxVec3>& terrainVertices, const PxBounds3& bound, PxCollection& outCollection);
|
||||
|
||||
static void setCCDActive(PxShape& shape);
|
||||
static bool isCCDActive(PxFilterData& filterData);
|
||||
|
||||
PxTriangleMesh* generateTriMesh(const SampleArray<PxVec3>* vertices, const SampleArray<PxU32>* indices);
|
||||
|
||||
void setCollisionGroup(PxRigidActor* actor, PxU32 group);
|
||||
|
||||
//Terrain template data from Terrain.bin
|
||||
struct BinData
|
||||
{
|
||||
SampleArray<SampleArray<PxVec3> > mTerrainVertices;
|
||||
SampleArray<SampleArray<PxU32> > mTerrainIndices;
|
||||
|
||||
CoordType mDim;
|
||||
|
||||
//Need parent to render progress bar
|
||||
void serialize(SampleLargeWorld* parent, const char* terrainFile);
|
||||
|
||||
}binData;
|
||||
|
||||
ObjMeshMap mRenderMeshCache;
|
||||
|
||||
BackgroundLoader* mBGLoader;
|
||||
SampleCCTCameraController* mCCTCamera;
|
||||
ControlledActor* mActor;
|
||||
PxControllerManager* mControllerManager;
|
||||
PxExtendedVec3 mControllerInitialPosition;
|
||||
PxExtendedVec3 mLastCCTPosition;
|
||||
std::vector<PxFixedJoint*> mFixedJoints;
|
||||
|
||||
//Sky box
|
||||
RenderBaseActor* mSkybox[5];
|
||||
|
||||
//For progress bar renderering
|
||||
PxReal mProgressBarRatio;
|
||||
Ps::Time::Second mDiskIOTime;
|
||||
Ps::Time::Second mPhysxStreaming;
|
||||
Ps::Time::Second mGraphicStreaming;
|
||||
|
||||
//Bound of the whole world
|
||||
PxBounds3 mWorldBound;
|
||||
|
||||
bool mReadyToSyncCCT;
|
||||
bool mAddRenderActor;
|
||||
bool mPick;
|
||||
bool mKeyShiftDown;
|
||||
|
||||
PxReal mDefaultCameraSpeed;
|
||||
|
||||
public:
|
||||
static const PxU32 DEFAULT_COLLISION_GROUP = 0;
|
||||
static const PxU32 FAN_COLLISION_GROUP = 1;
|
||||
static const PxU32 PICKING_COLLISION_GROUP = 2;
|
||||
|
||||
PxStringTable* mStringTable;
|
||||
};
|
||||
|
||||
#endif
|
||||
70
physx/samples/samplelargeworld/SampleLargeWorldCCT.cpp
Normal file
70
physx/samples/samplelargeworld/SampleLargeWorldCCT.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// 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-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#include "SampleLargeWorld.h"
|
||||
|
||||
#include "KinematicPlatform.h"
|
||||
#include "SampleCCTActor.h"
|
||||
#include "SampleCCTCameraController.h"
|
||||
extern const char* gDynamic;
|
||||
|
||||
void SampleLargeWorld::onShapeHit(const PxControllerShapeHit& hit)
|
||||
{
|
||||
defaultCCTInteraction(hit);
|
||||
}
|
||||
|
||||
PxControllerBehaviorFlags SampleLargeWorld::getBehaviorFlags(const PxShape& shape, const PxActor& actor)
|
||||
{
|
||||
return PxControllerBehaviorFlags(0);
|
||||
}
|
||||
|
||||
PxControllerBehaviorFlags SampleLargeWorld::getBehaviorFlags(const PxController&)
|
||||
{
|
||||
return PxControllerBehaviorFlags(0);
|
||||
}
|
||||
|
||||
PxControllerBehaviorFlags SampleLargeWorld::getBehaviorFlags(const PxObstacle&)
|
||||
{
|
||||
return PxControllerBehaviorFlag::eCCT_CAN_RIDE_ON_OBJECT|PxControllerBehaviorFlag::eCCT_SLIDE;
|
||||
}
|
||||
|
||||
PxQueryHitType::Enum SampleLargeWorld::preFilter(const PxFilterData& filterData, const PxShape* shape, const PxRigidActor* actor, PxHitFlags& queryFlags)
|
||||
{
|
||||
PX_UNUSED(actor);
|
||||
const char* actorName = shape->getActor()->getName();
|
||||
if(actorName==gDynamic)
|
||||
return PxQueryHitType::eNONE;
|
||||
|
||||
return PxQueryHitType::eBLOCK;
|
||||
}
|
||||
|
||||
PxQueryHitType::Enum SampleLargeWorld::postFilter(const PxFilterData& filterData, const PxQueryHit& hit)
|
||||
{
|
||||
return PxQueryHitType::eBLOCK;
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
//
|
||||
// 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-2021 NVIDIA Corporation. All rights reserved.
|
||||
#ifndef _SAMPLE_LARGE_WORLD_INPUT_EVENT_IDS_H
|
||||
#define _SAMPLE_LARGE_WORLD_INPUT_EVENT_IDS_H
|
||||
|
||||
#include <SampleBaseInputEventIds.h>
|
||||
|
||||
// InputEvents used by SampleCharacterController
|
||||
enum SampleLargeWorldInputEventIds
|
||||
{
|
||||
SAMPLE_LARGE_WORLD_FIRST = NUM_SAMPLE_BASE_INPUT_EVENT_IDS,
|
||||
|
||||
RETRY,
|
||||
THROW_IMPORTANTOBJECT,
|
||||
THROW_UNIMPORTANCTOBJECT,
|
||||
PICK_NEARSETOBJECT,
|
||||
FLY_CAMERA,
|
||||
NUM_SAMPLE_LARGE_WORLD_INPUT_EVENT_IDS,
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user