ModuleDestructible.h
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2018 NVIDIA Corporation. All rights reserved.
00027 
00028 
00029 
00030 #ifndef MODULE_DESTRUCTIBLE_H
00031 #define MODULE_DESTRUCTIBLE_H
00032 
00033 #include "foundation/Px.h"
00034 #include "foundation/PxBounds3.h"
00035 #include "Module.h"
00036 
00037 #ifndef APEX_RUNTIME_FRACTURE
00038 #define APEX_RUNTIME_FRACTURE 1
00039 #else
00040 #undef APEX_RUNTIME_FRACTURE
00041 #define APEX_RUNTIME_FRACTURE 0
00042 #endif
00043 
00044 #if PX_ANDROID
00045 #undef APEX_RUNTIME_FRACTURE
00046 #define APEX_RUNTIME_FRACTURE 0
00047 #endif
00048 
00049 namespace physx
00050 {
00051 class PxRigidActor;
00052 class PxRigidDynamic;
00053 class PxScene;
00054 }
00055 
00056 namespace nvidia
00057 {
00058 namespace apex
00059 {
00060 
00061 PX_PUSH_PACK_DEFAULT
00062 
00063 class DestructibleAsset;
00064 class DestructibleAssetAuthoring;
00065 class DestructibleActor;
00066 class DestructibleActorJoint;
00067 class DestructibleChunkDesc;
00068 class DestructibleActorDesc;
00069 class DestructibleActorJointDesc;
00070 
00074 struct ApexChunkFlag
00075 {
00079     enum Enum
00080     {
00082         DYNAMIC                         =   1 << 0,
00083 
00085         EXTERNALLY_SUPPORTED            =   1 << 1,
00086 
00088         WORLD_SUPPORTED                 =   1 << 2,
00089 
00091         FRACTURED                       =   1 << 3,
00092 
00094         DESTROYED_FIFO_FULL             =   1 << 4,
00095 
00097         DESTROYED_TIMED_OUT             =   1 << 5,
00098 
00100         DESTROYED_EXCEEDED_MAX_DISTANCE =   1 << 6,
00101 
00103         DESTROYED_CRUMBLED              =   1 << 7,
00104 
00106         DESTROYED_LEFT_VALID_BOUNDS     =   1 << 8,
00107 
00109         DESTROYED_LEFT_USER_BOUNDS      =   1 << 9,
00110 
00112         DESTROYED_ENTERED_USER_BOUNDS   =   1 << 10
00113     };
00114 };
00115 
00119 struct ChunkData
00120 {
00122     uint32_t            index;
00123 
00125     uint32_t            depth;
00126 
00130     PxBounds3           worldBounds;
00131 
00135     float               damage;
00136 
00141     uint32_t            flags;
00142 };
00143 
00147 struct DamageEventReportData
00148 {
00152     DestructibleActor*  destructible;
00153 
00157     PxVec3              hitDirection;
00158 
00163     PxBounds3           worldBounds;
00164 
00169     uint32_t            totalNumberOfFractureEvents;
00170 
00175     uint16_t            minDepth;
00176     
00181     uint16_t            maxDepth;
00182 
00191     const ChunkData*    fractureEventList;
00192 
00198     uint32_t            fractureEventListSize;
00199 
00203     physx::PxActor const*   impactDamageActor;
00204 
00205 
00209     PxVec3              hitPosition;
00210 
00214     void*               appliedDamageUserData;
00215 };
00216 
00217 
00223 struct DestructibleChunkEvent
00224 {
00228     enum EventMask
00229     {
00230         VisibilityChanged   =   (1 << 0),
00231         ChunkVisible    =       (1 << 1)
00232     };
00233 
00234     uint16_t    chunkIndex; 
00235     uint16_t    event; 
00236 };
00237 
00238 
00242 struct ChunkStateEventData
00243 {
00247     DestructibleActor*          destructible;
00248 
00252     const DestructibleChunkEvent* stateEventList;
00253 
00257     uint32_t                    stateEventListSize;
00258 };
00259 
00260 
00264 class UserChunkReport
00265 {
00266 public:
00273     virtual void    onDamageNotify(const DamageEventReportData& damageEvent) = 0;
00274 
00285     virtual void    onStateChangeNotify(const ChunkStateEventData& visibilityEvent) = 0;
00286 
00297     virtual bool    releaseOnNoChunksVisible(const DestructibleActor* destructible) { PX_UNUSED(destructible);  return false; }
00298 
00302     virtual void    onDestructibleWake(DestructibleActor** destructibles, uint32_t count) = 0;
00303 
00307     virtual void    onDestructibleSleep(DestructibleActor** destructibles, uint32_t count) = 0;
00308 
00309 protected:
00310     virtual         ~UserChunkReport() {}
00311 };
00312 
00313 
00317 struct ChunkParticleReportData
00318 {
00320     const PxVec3* positions;
00321 
00323     uint32_t positionCount;
00324 
00333     const PxVec3* velocities;
00334 
00336     uint32_t velocityCount;
00337 };
00338 
00343 class UserChunkParticleReport
00344 {
00345 public:
00355     virtual void    onParticleEmission(const ChunkParticleReportData& particleData) = 0;
00356 
00357 protected:
00358     virtual         ~UserChunkParticleReport() {}
00359 };
00360 
00361 
00366 class UserDestructiblePhysXActorReport
00367 {
00368 public:
00370     virtual void    onPhysXActorCreate(const physx::PxActor& actor) = 0;
00371 
00373     virtual void    onPhysXActorRelease(const physx::PxActor& actor) = 0;
00374 protected:
00375     virtual     ~UserDestructiblePhysXActorReport() {}
00376 };
00377 
00378 
00382 struct ModuleDestructibleConst
00383 {
00387     enum Enum
00388     {
00393         INVALID_CHUNK_INDEX = -1
00394     };
00395 };
00396 
00400 struct DestructibleActorMeshType
00401 {
00405     enum Enum
00406     {
00407         Skinned,
00408         Static,
00409         Count
00410     };
00411 };
00412 
00416 struct DamageEventCoreData
00417 {
00418     int32_t chunkIndexInAsset;  
00419     PxVec3  position;           
00420     float   damage;             
00421     float   radius;             
00422 };
00423 
00427 struct ImpactDamageEventData : public DamageEventCoreData
00428 {
00429     nvidia::DestructibleActor*  destructible;       
00430     PxVec3                      direction;          
00431     physx::PxActor const*       impactDamageActor;  
00432 };
00433 
00437 class UserImpactDamageReport
00438 {
00439 public:
00446     virtual void    onImpactDamageNotify(const ImpactDamageEventData* buffer, uint32_t bufferSize) = 0;
00447 };
00448 
00452 template<typename DestructibleSyncHeader>
00453 class UserDestructibleSyncHandler
00454 {
00455 public:
00459     virtual void    onWriteBegin(DestructibleSyncHeader *& bufferStart, uint32_t bufferSize) = 0;
00460     
00464     virtual void    onWriteDone(uint32_t headerCount) = 0;
00465     
00469     virtual void    onPreProcessReadBegin(DestructibleSyncHeader *& bufferStart, uint32_t & bufferSize, bool & continuePointerSwizzling) = 0;
00470     
00474     virtual void    onPreProcessReadDone(uint32_t headerCount) = 0;
00475     
00479     virtual void    onReadBegin(const DestructibleSyncHeader *& bufferStart) = 0;
00480     
00484     virtual void    onReadDone(const char * debugMessage) = 0;
00485 protected:
00486     virtual ~UserDestructibleSyncHandler() {}
00487 };
00488 
00489 /*** Sync-able Damage Data ***/
00490 
00491 struct DamageEventUnit;
00495 struct DamageEventHeader
00496 {
00497     uint32_t                    userActorID;            
00498     uint32_t                    damageEventCount;       
00499     DamageEventUnit *           damageEventBufferStart; 
00500     DamageEventHeader *         next;                   
00501 };
00502 
00506 struct DamageEventUnit
00507 {
00508     uint32_t    chunkIndex;         
00509     uint32_t    damageEventFlags;   
00510     float       damage;             
00511     float       momentum;           
00512     float       radius;             
00513     PxVec3      position;           
00514     PxVec3      direction;          
00515 };
00516 
00517 /*** Sync-able Fracture Data ***/
00518 
00519 struct FractureEventUnit;
00520 
00524 struct FractureEventHeader
00525 {
00526     uint32_t                    userActorID;                
00527     uint32_t                    fractureEventCount;         
00528     FractureEventUnit *         fractureEventBufferStart;   
00529     FractureEventHeader *       next;                       
00530 };
00531 
00535 struct FractureEventUnit
00536 {
00537     uint32_t    chunkIndex;         
00538     uint32_t    fractureEventFlags; 
00539     PxVec3      position;           
00540     PxVec3      direction;          
00541     PxVec3      impulse;            
00542 };
00543 
00544 /*** Sync-able Transform Data ***/
00545 
00546 struct ChunkTransformUnit;
00547 
00551 struct ChunkTransformHeader
00552 {
00553     uint32_t                    userActorID;                
00554     uint32_t                    chunkTransformCount;        
00555     ChunkTransformUnit *        chunkTransformBufferStart;  
00556     ChunkTransformHeader *      next;                       
00557 };
00558 
00562 struct ChunkTransformUnit
00563 {
00564     uint32_t    chunkIndex;         
00565     PxVec3      chunkPosition;      
00566     PxQuat      chunkOrientation;   
00567 };
00568 
00569 
00573 struct DestructibleActorRaycastFlags
00574 {
00578     enum Enum
00579     {
00580         NoChunks =      (0),
00581         StaticChunks =  (1 << 0),
00582         DynamicChunks = (1 << 1),
00583 
00584         AllChunks =                 StaticChunks | DynamicChunks,
00585 
00586         SegmentIntersect =  (1 << 2),   
00587 
00588         ForceAccurateRaycastsOn =   (1 << 3),
00589         ForceAccurateRaycastsOff =  (1 << 4),
00590     };
00591 };
00592 
00593 
00597 struct DestructibleCallbackSchedule
00598 {
00602     enum Enum
00603     {
00604         Disabled =      (0),
00605         BeforeTick,     
00606         FetchResults,   
00607 
00608         Count
00609     };
00610 };
00611 
00612 
00616 class ModuleDestructible : public Module
00617 {
00618 public:
00628     virtual DestructibleActorJoint*         createDestructibleActorJoint(const DestructibleActorJointDesc& desc, Scene& scene) = 0;
00629 
00635     virtual bool                            isDestructibleActorJointActive(const DestructibleActorJoint* candidateJoint, Scene& apexScene) const = 0;
00636 
00646     virtual void                            setMaxDynamicChunkIslandCount(uint32_t maxCount) = 0;
00647 
00654     virtual void                            setMaxChunkCount(uint32_t maxCount) = 0;
00655 
00660     virtual void                            setSortByBenefit(bool sortByBenefit) = 0;
00661 
00665     virtual void                            setValidBoundsPadding(float pad) = 0;
00666 
00673     virtual void                            setMaxChunkDepthOffset(uint32_t maxChunkDepthOffset) = 0;
00674 
00680     virtual void                            setMaxChunkSeparationLOD(float separationLOD) = 0;
00681 
00682 
00688     virtual void                            setChunkReport(UserChunkReport* chunkReport) = 0;
00689 
00694     virtual void                            setImpactDamageReportCallback(UserImpactDamageReport* impactDamageReport) = 0;
00695 
00700     virtual void                            setChunkReportBitMask(uint32_t chunkReportBitMask) = 0;
00701 
00706     virtual void                            setDestructiblePhysXActorReport(UserDestructiblePhysXActorReport* destructiblePhysXActorReport) = 0;
00707 
00713     virtual void                            setChunkReportMaxFractureEventDepth(uint32_t chunkReportMaxFractureEventDepth) = 0;
00714 
00721     virtual void                            scheduleChunkStateEventCallback(DestructibleCallbackSchedule::Enum chunkStateEventCallbackSchedule) = 0;
00722 
00727     virtual void                            setChunkCrumbleReport(UserChunkParticleReport* chunkCrumbleReport) = 0;
00728 
00735     virtual void                            setChunkDustReport(UserChunkParticleReport* chunkDustReport) = 0;
00736 
00742     virtual void                            setWorldSupportPhysXScene(Scene& apexScene, PxScene* physxScene) = 0;
00743 
00748     virtual bool                            owns(const PxRigidActor* actor) const = 0;
00749 
00750 #if APEX_RUNTIME_FRACTURE
00751 
00755     virtual bool                            isRuntimeFractureShape(const PxShape& shape) const = 0;
00756 #endif
00757 
00764     virtual DestructibleActor*              getDestructibleAndChunk(const PxShape* shape, int32_t* chunkIndex = NULL) const = 0;
00765 
00776     virtual void                            applyRadiusDamage(Scene& scene, float damage, float momentum,
00777             const PxVec3& position, float radius, bool falloff) = 0;
00778 
00783     virtual void                            setMaxActorCreatesPerFrame(uint32_t maxActorsPerFrame) = 0;
00784 
00789     virtual void                            setMaxFracturesProcessedPerFrame(uint32_t maxFracturesProcessedPerFrame) = 0;
00790 
00794     virtual bool                            setSyncParams(UserDestructibleSyncHandler<DamageEventHeader> * userDamageEventHandler, UserDestructibleSyncHandler<FractureEventHeader> * userFractureEventHandler, UserDestructibleSyncHandler<ChunkTransformHeader> * userChunkMotionHandler) = 0;
00795 
00806     virtual void                            setUseLegacyChunkBoundsTesting(bool useLegacyChunkBoundsTesting) = 0;
00807 
00819     virtual void                            setUseLegacyDamageRadiusSpread(bool useLegacyDamageRadiusSpread) = 0;
00820 
00837     virtual bool                            setMassScaling(float massScale, float scaledMassExponent, Scene& apexScene) = 0;
00838 
00845     virtual void                            invalidateBounds(const PxBounds3* bounds, uint32_t boundsCount, Scene& apexScene) = 0;
00846 
00857     virtual void                            setDamageApplicationRaycastFlags(nvidia::DestructibleActorRaycastFlags::Enum flags, Scene& apexScene) = 0;
00858 
00868     virtual bool                            setChunkCollisionHullCookingScale(const PxVec3& scale) = 0;
00869 
00873     virtual PxVec3                          getChunkCollisionHullCookingScale() const = 0;
00874 
00878     virtual class FractureToolsAPI*         getFractureTools() const = 0;
00879 
00880 protected:
00881     virtual                                 ~ModuleDestructible() {}
00882 };
00883 
00884 
00885 #if !defined(_USRDLL)
00886 
00890 void instantiateModuleDestructible();
00891 #endif
00892 
00893 PX_POP_PACK
00894 
00895 }
00896 } // end namespace nvidia
00897 
00898 #endif // MODULE_DESTRUCTIBLE_H

Generated on Sat Dec 1 2018 15:52:05

Copyright © 2012-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.