ModuleDestructible.h
00001 /* 00002 * Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved. 00003 * 00004 * NVIDIA CORPORATION and its licensors retain all intellectual property 00005 * and proprietary rights in and to this software, related documentation 00006 * and any modifications thereto. Any use, reproduction, disclosure or 00007 * distribution of this software and related documentation without an express 00008 * license agreement from NVIDIA CORPORATION is strictly prohibited. 00009 */ 00010 00011 00012 #ifndef MODULE_DESTRUCTIBLE_H 00013 #define MODULE_DESTRUCTIBLE_H 00014 00015 #include "foundation/Px.h" 00016 #include "foundation/PxBounds3.h" 00017 #include "Module.h" 00018 00019 #ifndef APEX_RUNTIME_FRACTURE 00020 #define APEX_RUNTIME_FRACTURE 1 00021 #else 00022 #undef APEX_RUNTIME_FRACTURE 00023 #define APEX_RUNTIME_FRACTURE 0 00024 #endif 00025 00026 #if PX_ANDROID 00027 #undef APEX_RUNTIME_FRACTURE 00028 #define APEX_RUNTIME_FRACTURE 0 00029 #endif 00030 00031 namespace physx 00032 { 00033 class PxRigidActor; 00034 class PxRigidDynamic; 00035 class PxScene; 00036 } 00037 00038 namespace nvidia 00039 { 00040 namespace apex 00041 { 00042 00043 PX_PUSH_PACK_DEFAULT 00044 00045 class DestructibleAsset; 00046 class DestructibleAssetAuthoring; 00047 class DestructibleActor; 00048 class DestructibleActorJoint; 00049 class DestructibleChunkDesc; 00050 class DestructibleActorDesc; 00051 class DestructibleActorJointDesc; 00052 00056 struct ApexChunkFlag 00057 { 00061 enum Enum 00062 { 00064 DYNAMIC = 1 << 0, 00065 00067 EXTERNALLY_SUPPORTED = 1 << 1, 00068 00070 WORLD_SUPPORTED = 1 << 2, 00071 00073 FRACTURED = 1 << 3, 00074 00076 DESTROYED_FIFO_FULL = 1 << 4, 00077 00079 DESTROYED_TIMED_OUT = 1 << 5, 00080 00082 DESTROYED_EXCEEDED_MAX_DISTANCE = 1 << 6, 00083 00085 DESTROYED_CRUMBLED = 1 << 7, 00086 00088 DESTROYED_LEFT_VALID_BOUNDS = 1 << 8, 00089 00091 DESTROYED_LEFT_USER_BOUNDS = 1 << 9, 00092 00094 DESTROYED_ENTERED_USER_BOUNDS = 1 << 10 00095 }; 00096 }; 00097 00101 struct ChunkData 00102 { 00104 uint32_t index; 00105 00107 uint32_t depth; 00108 00112 PxBounds3 worldBounds; 00113 00117 float damage; 00118 00123 uint32_t flags; 00124 }; 00125 00129 struct DamageEventReportData 00130 { 00134 DestructibleActor* destructible; 00135 00139 PxVec3 hitDirection; 00140 00145 PxBounds3 worldBounds; 00146 00151 uint32_t totalNumberOfFractureEvents; 00152 00157 uint16_t minDepth; 00158 00163 uint16_t maxDepth; 00164 00173 const ChunkData* fractureEventList; 00174 00180 uint32_t fractureEventListSize; 00181 00185 physx::PxActor const* impactDamageActor; 00186 00187 00191 PxVec3 hitPosition; 00192 00196 void* appliedDamageUserData; 00197 }; 00198 00199 00205 struct DestructibleChunkEvent 00206 { 00210 enum EventMask 00211 { 00212 VisibilityChanged = (1 << 0), 00213 ChunkVisible = (1 << 1) 00214 }; 00215 00216 uint16_t chunkIndex; 00217 uint16_t event; 00218 }; 00219 00220 00224 struct ChunkStateEventData 00225 { 00229 DestructibleActor* destructible; 00230 00234 const DestructibleChunkEvent* stateEventList; 00235 00239 uint32_t stateEventListSize; 00240 }; 00241 00242 00246 class UserChunkReport 00247 { 00248 public: 00255 virtual void onDamageNotify(const DamageEventReportData& damageEvent) = 0; 00256 00267 virtual void onStateChangeNotify(const ChunkStateEventData& visibilityEvent) = 0; 00268 00279 virtual bool releaseOnNoChunksVisible(const DestructibleActor* destructible) { PX_UNUSED(destructible); return false; } 00280 00284 virtual void onDestructibleWake(DestructibleActor** destructibles, uint32_t count) = 0; 00285 00289 virtual void onDestructibleSleep(DestructibleActor** destructibles, uint32_t count) = 0; 00290 00291 protected: 00292 virtual ~UserChunkReport() {} 00293 }; 00294 00295 00299 struct ChunkParticleReportData 00300 { 00302 const PxVec3* positions; 00303 00305 uint32_t positionCount; 00306 00315 const PxVec3* velocities; 00316 00318 uint32_t velocityCount; 00319 }; 00320 00325 class UserChunkParticleReport 00326 { 00327 public: 00337 virtual void onParticleEmission(const ChunkParticleReportData& particleData) = 0; 00338 00339 protected: 00340 virtual ~UserChunkParticleReport() {} 00341 }; 00342 00343 00348 class UserDestructiblePhysXActorReport 00349 { 00350 public: 00352 virtual void onPhysXActorCreate(const physx::PxActor& actor) = 0; 00353 00355 virtual void onPhysXActorRelease(const physx::PxActor& actor) = 0; 00356 protected: 00357 virtual ~UserDestructiblePhysXActorReport() {} 00358 }; 00359 00360 00364 struct ModuleDestructibleConst 00365 { 00369 enum Enum 00370 { 00375 INVALID_CHUNK_INDEX = -1 00376 }; 00377 }; 00378 00382 struct DestructibleActorMeshType 00383 { 00387 enum Enum 00388 { 00389 Skinned, 00390 Static, 00391 Count 00392 }; 00393 }; 00394 00398 struct DamageEventCoreData 00399 { 00400 int32_t chunkIndexInAsset; 00401 PxVec3 position; 00402 float damage; 00403 float radius; 00404 }; 00405 00409 struct ImpactDamageEventData : public DamageEventCoreData 00410 { 00411 nvidia::DestructibleActor* destructible; 00412 PxVec3 direction; 00413 physx::PxActor const* impactDamageActor; 00414 }; 00415 00419 class UserImpactDamageReport 00420 { 00421 public: 00428 virtual void onImpactDamageNotify(const ImpactDamageEventData* buffer, uint32_t bufferSize) = 0; 00429 }; 00430 00434 template<typename DestructibleSyncHeader> 00435 class UserDestructibleSyncHandler 00436 { 00437 public: 00441 virtual void onWriteBegin(DestructibleSyncHeader *& bufferStart, uint32_t bufferSize) = 0; 00442 00446 virtual void onWriteDone(uint32_t headerCount) = 0; 00447 00451 virtual void onPreProcessReadBegin(DestructibleSyncHeader *& bufferStart, uint32_t & bufferSize, bool & continuePointerSwizzling) = 0; 00452 00456 virtual void onPreProcessReadDone(uint32_t headerCount) = 0; 00457 00461 virtual void onReadBegin(const DestructibleSyncHeader *& bufferStart) = 0; 00462 00466 virtual void onReadDone(const char * debugMessage) = 0; 00467 protected: 00468 virtual ~UserDestructibleSyncHandler() {} 00469 }; 00470 00471 /*** Sync-able Damage Data ***/ 00472 00473 struct DamageEventUnit; 00477 struct DamageEventHeader 00478 { 00479 uint32_t userActorID; 00480 uint32_t damageEventCount; 00481 DamageEventUnit * damageEventBufferStart; 00482 DamageEventHeader * next; 00483 }; 00484 00488 struct DamageEventUnit 00489 { 00490 uint32_t chunkIndex; 00491 uint32_t damageEventFlags; 00492 float damage; 00493 float momentum; 00494 float radius; 00495 PxVec3 position; 00496 PxVec3 direction; 00497 }; 00498 00499 /*** Sync-able Fracture Data ***/ 00500 00501 struct FractureEventUnit; 00502 00506 struct FractureEventHeader 00507 { 00508 uint32_t userActorID; 00509 uint32_t fractureEventCount; 00510 FractureEventUnit * fractureEventBufferStart; 00511 FractureEventHeader * next; 00512 }; 00513 00517 struct FractureEventUnit 00518 { 00519 uint32_t chunkIndex; 00520 uint32_t fractureEventFlags; 00521 PxVec3 position; 00522 PxVec3 direction; 00523 PxVec3 impulse; 00524 }; 00525 00526 /*** Sync-able Transform Data ***/ 00527 00528 struct ChunkTransformUnit; 00529 00533 struct ChunkTransformHeader 00534 { 00535 uint32_t userActorID; 00536 uint32_t chunkTransformCount; 00537 ChunkTransformUnit * chunkTransformBufferStart; 00538 ChunkTransformHeader * next; 00539 }; 00540 00544 struct ChunkTransformUnit 00545 { 00546 uint32_t chunkIndex; 00547 PxVec3 chunkPosition; 00548 PxQuat chunkOrientation; 00549 }; 00550 00551 00555 struct DestructibleActorRaycastFlags 00556 { 00560 enum Enum 00561 { 00562 NoChunks = (0), 00563 StaticChunks = (1 << 0), 00564 DynamicChunks = (1 << 1), 00565 00566 AllChunks = StaticChunks | DynamicChunks, 00567 00568 SegmentIntersect = (1 << 2), 00569 00570 ForceAccurateRaycastsOn = (1 << 3), 00571 ForceAccurateRaycastsOff = (1 << 4), 00572 }; 00573 }; 00574 00575 00579 struct DestructibleCallbackSchedule 00580 { 00584 enum Enum 00585 { 00586 Disabled = (0), 00587 BeforeTick, 00588 FetchResults, 00589 00590 Count 00591 }; 00592 }; 00593 00594 00598 class ModuleDestructible : public Module 00599 { 00600 public: 00610 virtual DestructibleActorJoint* createDestructibleActorJoint(const DestructibleActorJointDesc& desc, Scene& scene) = 0; 00611 00617 virtual bool isDestructibleActorJointActive(const DestructibleActorJoint* candidateJoint, Scene& apexScene) const = 0; 00618 00628 virtual void setMaxDynamicChunkIslandCount(uint32_t maxCount) = 0; 00629 00636 virtual void setMaxChunkCount(uint32_t maxCount) = 0; 00637 00642 virtual void setSortByBenefit(bool sortByBenefit) = 0; 00643 00647 virtual void setValidBoundsPadding(float pad) = 0; 00648 00655 virtual void setMaxChunkDepthOffset(uint32_t maxChunkDepthOffset) = 0; 00656 00662 virtual void setMaxChunkSeparationLOD(float separationLOD) = 0; 00663 00664 00670 virtual void setChunkReport(UserChunkReport* chunkReport) = 0; 00671 00676 virtual void setImpactDamageReportCallback(UserImpactDamageReport* impactDamageReport) = 0; 00677 00682 virtual void setChunkReportBitMask(uint32_t chunkReportBitMask) = 0; 00683 00688 virtual void setDestructiblePhysXActorReport(UserDestructiblePhysXActorReport* destructiblePhysXActorReport) = 0; 00689 00695 virtual void setChunkReportMaxFractureEventDepth(uint32_t chunkReportMaxFractureEventDepth) = 0; 00696 00703 virtual void scheduleChunkStateEventCallback(DestructibleCallbackSchedule::Enum chunkStateEventCallbackSchedule) = 0; 00704 00709 virtual void setChunkCrumbleReport(UserChunkParticleReport* chunkCrumbleReport) = 0; 00710 00717 virtual void setChunkDustReport(UserChunkParticleReport* chunkDustReport) = 0; 00718 00724 virtual void setWorldSupportPhysXScene(Scene& apexScene, PxScene* physxScene) = 0; 00725 00730 virtual bool owns(const PxRigidActor* actor) const = 0; 00731 00732 #if APEX_RUNTIME_FRACTURE 00733 00737 virtual bool isRuntimeFractureShape(const PxShape& shape) const = 0; 00738 #endif 00739 00746 virtual DestructibleActor* getDestructibleAndChunk(const PxShape* shape, int32_t* chunkIndex = NULL) const = 0; 00747 00758 virtual void applyRadiusDamage(Scene& scene, float damage, float momentum, 00759 const PxVec3& position, float radius, bool falloff) = 0; 00760 00765 virtual void setMaxActorCreatesPerFrame(uint32_t maxActorsPerFrame) = 0; 00766 00771 virtual void setMaxFracturesProcessedPerFrame(uint32_t maxFracturesProcessedPerFrame) = 0; 00772 00776 virtual bool setSyncParams(UserDestructibleSyncHandler<DamageEventHeader> * userDamageEventHandler, UserDestructibleSyncHandler<FractureEventHeader> * userFractureEventHandler, UserDestructibleSyncHandler<ChunkTransformHeader> * userChunkMotionHandler) = 0; 00777 00788 virtual void setUseLegacyChunkBoundsTesting(bool useLegacyChunkBoundsTesting) = 0; 00789 00801 virtual void setUseLegacyDamageRadiusSpread(bool useLegacyDamageRadiusSpread) = 0; 00802 00819 virtual bool setMassScaling(float massScale, float scaledMassExponent, Scene& apexScene) = 0; 00820 00827 virtual void invalidateBounds(const PxBounds3* bounds, uint32_t boundsCount, Scene& apexScene) = 0; 00828 00839 virtual void setDamageApplicationRaycastFlags(nvidia::DestructibleActorRaycastFlags::Enum flags, Scene& apexScene) = 0; 00840 00850 virtual bool setChunkCollisionHullCookingScale(const PxVec3& scale) = 0; 00851 00855 virtual PxVec3 getChunkCollisionHullCookingScale() const = 0; 00856 00860 virtual class FractureToolsAPI* getFractureTools() const = 0; 00861 00862 protected: 00863 virtual ~ModuleDestructible() {} 00864 }; 00865 00866 00867 #if !defined(_USRDLL) 00868 00872 void instantiateModuleDestructible(); 00873 #endif 00874 00875 PX_POP_PACK 00876 00877 } 00878 } // end namespace nvidia 00879 00880 #endif // MODULE_DESTRUCTIBLE_H
Generated on Fri Dec 15 2017 13:58:35 Copyright © 2012-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.