DestructibleActor.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 DESTRUCTIBLE_ACTOR_H
00031 #define DESTRUCTIBLE_ACTOR_H
00032 
00033 #include "foundation/Px.h"
00034 #include "Actor.h"
00035 #include "Renderable.h"
00036 #include "ModuleDestructible.h"
00037 #include "PxForceMode.h"
00038 
00039 namespace physx
00040 {
00041     class PxRigidDynamic;
00042 };
00043 
00044 #define DESTRUCTIBLE_ACTOR_TYPE_NAME "DestructibleActor"
00045 
00046 namespace nvidia
00047 {
00048 namespace apex
00049 {
00050 
00051 PX_PUSH_PACK_DEFAULT
00052 
00053 struct DestructibleParameters;
00054 class RenderVolume;
00055 class EmitterActor;
00056 class DestructibleRenderable;
00057 class DestructibleBehaviorGroupDesc;
00058 
00059 
00063 struct DestructibleEmitterType
00064 {
00068     enum Enum
00069     {
00070         Crumble,
00071         Dust,   // Note: this is a placeholder.  Its implementation has been removed in 1.2.0, and will be restored in later versions.
00072         Count
00073     };
00074 };
00075 
00079 struct DestructibleParameterizedType
00080 {
00084     enum Enum
00085     {
00086         State,  // The full state of the actor (including params, chunk data, etc...)
00087         Params, // The parameters used to initialize the actor
00088     };
00089 };
00090 
00094 struct DestructibleHitChunk
00095 {
00096     uint32_t chunkIndex;    
00097     uint32_t hitChunkFlags; 
00098 };
00099 
00103 struct DestructibleActorSyncFlags
00104 {
00108     enum Enum
00109     {
00110         None                = 0,
00111         CopyDamageEvents    = (1 << 0),
00112         ReadDamageEvents    = (1 << 1),
00113         CopyFractureEvents  = (1 << 2),
00114         ReadFractureEvents  = (1 << 3),
00115         CopyChunkTransform  = (1 << 4),
00116         ReadChunkTransform  = (1 << 5),
00117         Last                = (1 << 6),
00118     };
00119 };
00120 
00124 struct DestructiblePhysXActorQueryFlags
00125 {
00129     enum Enum
00130     {
00131         None = 0,
00132 
00133         // Actor states
00134         Static = (1 << 0),  
00135         Dynamic = (1 << 1), 
00136         Dormant = (1 << 2), 
00137 
00138         AllStates = Static | Dynamic | Dormant,
00139 
00140         // Other filters
00147         AllowRedundancy = (1 << 3),
00148 
00152         AllowActorsNotInScenes = (1 << 4)
00153     };
00154 };
00155 
00159 struct DestructibleActorSyncState
00160 {
00161     uint32_t    damageEventFilterDepth;     
00162     uint32_t    fractureEventFilterDepth;   
00163 };
00164 
00168 struct DestructibleChunkSyncState
00169 {
00170     bool        disableTransformBuffering;  
00171     bool        excludeSleepingChunks;      
00172     uint32_t    chunkTransformCopyDepth;    
00173 };
00174 
00179 struct DestructibleActorChunkFlags
00180 {
00184     enum Enum
00185     {
00190         ChunkIsWorldSupported   =   (1<<0),
00191     };
00192 };
00193 
00197 class DestructibleActor : public Actor, public Renderable
00198 #if PX_PHYSICS_VERSION_MAJOR == 3
00199     , public ActorSource
00200 #endif
00201 {
00202 public:
00206     virtual const RenderMeshActor*  getRenderMeshActor(DestructibleActorMeshType::Enum type = DestructibleActorMeshType::Skinned) const = 0;
00207 
00211     virtual const DestructibleParameters& getDestructibleParameters() const = 0;
00212 
00216     virtual void                    setDestructibleParameters(const DestructibleParameters& destructibleParameters) = 0;
00217 
00221     virtual PxMat44                 getInitialGlobalPose() const = 0;
00222 
00226     virtual void                    setInitialGlobalPose(const PxMat44& pose) = 0;
00227 
00231     virtual PxVec3                  getScale() const = 0;
00232 
00236     virtual bool                    isInitiallyDynamic() const = 0;
00237 
00245     virtual void                    getChunkVisibilities(uint8_t* visibilityArray, uint32_t visibilityArraySize) const = 0;
00246 
00250     virtual uint32_t                getNumVisibleChunks() const = 0;
00251 
00255     virtual const uint16_t*         getVisibleChunks() const = 0;
00256 
00267     virtual bool                    acquireChunkEventBuffer(const nvidia::DestructibleChunkEvent*& buffer, uint32_t& bufferSize) = 0;
00268 
00275     virtual bool                    releaseChunkEventBuffer(bool clearBuffer = true) = 0;
00276 
00289     virtual bool                    acquirePhysXActorBuffer(physx::PxRigidDynamic**& buffer, uint32_t& bufferSize, uint32_t flags = DestructiblePhysXActorQueryFlags::AllStates) = 0;
00290 
00297     virtual bool                    releasePhysXActorBuffer() = 0;
00298 
00307     virtual physx::PxRigidDynamic*  getChunkPhysXActor(uint32_t chunkIndex) = 0;
00308 
00319     virtual uint32_t                getChunkPhysXShapes(physx::PxShape**& shapes, uint32_t chunkIndex) const = 0;
00320 
00330     virtual PxTransform             getChunkPose(uint32_t chunkIndex) const = 0;
00331 
00341     virtual PxTransform             getChunkTransform(uint32_t chunkIndex) const = 0;
00342 
00348     virtual PxVec3                  getChunkLinearVelocity(uint32_t chunkIndex) const = 0;
00349 
00355     virtual PxVec3                  getChunkAngularVelocity(uint32_t chunkIndex) const = 0;
00356 
00363     virtual const PxMat44           getChunkTM(uint32_t chunkIndex) const = 0;
00364 
00372     virtual int32_t                 getChunkBehaviorGroupIndex(uint32_t chunkIndex) const = 0;
00373 
00380     virtual uint32_t                getChunkActorFlags(uint32_t chunkIndex) const = 0;
00381 
00388     virtual void                    setGlobalPose(const PxMat44& pose) = 0;
00389 
00396     virtual bool                    getGlobalPose(PxMat44& pose) = 0;
00397 
00401     virtual void                    setLinearVelocity(const PxVec3& linearVelocity) = 0;
00402 
00406     virtual void                    setAngularVelocity(const PxVec3& angularVelocity) = 0;
00407 
00413     virtual void                    setDynamic(int32_t chunkIndex = ModuleDestructibleConst::INVALID_CHUNK_INDEX) = 0;
00414 
00418     virtual bool                    isDynamic(uint32_t chunkIndex) const = 0;
00419 
00425     virtual void                    enableHardSleeping() = 0;
00426 
00431     virtual void                    disableHardSleeping(bool wake = false)= 0;
00432 
00436     virtual bool                    isHardSleepingEnabled() const = 0;
00437 
00446     virtual bool                    setChunkPhysXActorAwakeState(uint32_t chunkIndex, bool awake) = 0;
00447 
00459     virtual bool                    addForce(uint32_t chunkIndex, const PxVec3& force, physx::PxForceMode::Enum mode, const PxVec3* position = NULL, bool wakeup = true) = 0;
00460 
00464     virtual void                    setSkinnedOverrideMaterial(uint32_t submeshIndex, const char* overrideMaterialName) = 0;
00465 
00469     virtual void                    setStaticOverrideMaterial(uint32_t submeshIndex, const char* overrideMaterialName) = 0;
00470 
00474     virtual void                    setRuntimeFractureOverridePattern(const char* overridePatternName) = 0;
00475 
00492     virtual void                    applyDamage(float damage, float momentum, const PxVec3& position, const PxVec3& direction, int32_t chunkIndex = ModuleDestructibleConst::INVALID_CHUNK_INDEX, void* damageUserData = NULL) = 0;
00493 
00507     virtual void                    applyRadiusDamage(float damage, float momentum, const PxVec3& position, float radius, bool falloff, void* damageUserData = NULL) = 0;
00508 
00513     virtual void                    takeImpact(const PxVec3& force, const PxVec3& position, uint16_t chunkIndex, PxActor const* damageImpactActor) = 0;
00514 
00530     virtual int32_t                 rayCast(float& time, PxVec3& normal, const PxVec3& worldRayOrig, const PxVec3& worldRayDir, DestructibleActorRaycastFlags::Enum flags, int32_t parentChunkIndex = ModuleDestructibleConst::INVALID_CHUNK_INDEX) const = 0;
00531 
00546     virtual int32_t                 obbSweep(float& time, PxVec3& normal, const PxVec3& worldBoxCenter, const PxVec3& worldBoxExtents, const PxMat33& worldBoxRot, const PxVec3& worldDisplacement, DestructibleActorRaycastFlags::Enum flags) const = 0;
00547 
00551     virtual void                    setCrumbleEmitterState(bool enable) = 0;
00552 
00557     virtual void                    setDustEmitterState(bool enable) = 0;
00558 
00563     virtual void                    setPreferredRenderVolume(RenderVolume* volume, DestructibleEmitterType::Enum type) = 0;
00564 
00565 
00570     virtual EmitterActor*           getApexEmitter(DestructibleEmitterType::Enum type) = 0;
00571 
00576     virtual bool                    recreateApexEmitter(DestructibleEmitterType::Enum type) = 0;
00577 
00583     virtual const ::NvParameterized::Interface* getNvParameterized(DestructibleParameterizedType::Enum type = DestructibleParameterizedType::State) const = 0;
00584 
00590     virtual void                    setNvParameterized(::NvParameterized::Interface*) = 0;
00591 
00611     virtual bool                    setSyncParams(uint32_t userActorID, uint32_t actorSyncFlags = 0, const DestructibleActorSyncState * actorSyncState = NULL, const DestructibleChunkSyncState * chunkSyncState = NULL) = 0;
00612 
00625     virtual bool                    setHitChunkTrackingParams(bool flushHistory, bool startTracking, uint32_t trackingDepth, bool trackAllChunks = true) = 0;
00626 
00632     virtual bool                    getHitChunkHistory(const DestructibleHitChunk *& hitChunkContainer, uint32_t & hitChunkCount) const = 0;
00633 
00644     virtual bool                    forceChunkHits(const DestructibleHitChunk * hitChunkContainer, uint32_t hitChunkCount, bool removeChunks = true, bool deferredEvent = false, PxVec3 damagePosition = PxVec3(0.0f), PxVec3 damageDirection = PxVec3(0.0f)) = 0;
00645 
00651     virtual bool                    getDamageColoringHistory(const DamageEventCoreData *& damageEventCoreDataContainer, uint32_t & damageEventCoreDataCount) const = 0;
00652 
00661     virtual bool                    forceDamageColoring(const DamageEventCoreData * damageEventCoreDataContainer, uint32_t damageEventCoreDataCount) = 0;
00662 
00666     virtual PxBounds3               getLocalBounds() const = 0;
00667 
00671     virtual PxBounds3               getOriginalBounds() const = 0;
00672 
00676     virtual bool                    isChunkSolitary(int32_t chunkIndex) const = 0;
00677 
00681     virtual PxBounds3               getChunkBounds(uint32_t chunkIndex) const = 0;
00682 
00686     virtual PxBounds3               getChunkLocalBounds(uint32_t chunkIndex) const = 0;
00687 
00691     virtual bool                    isChunkDestroyed(int32_t chunkIndex) const = 0;
00692 
00696     virtual uint32_t                getSupportDepthChunkIndices(uint32_t* const OutChunkIndices, uint32_t MaxOutIndices) const = 0;
00697 
00701     virtual uint32_t                getSupportDepth() const = 0;
00702 
00706     virtual void                    setDeleteFracturedChunks(bool inDeleteChunkMode) = 0;
00707 
00713     virtual DestructibleRenderable* acquireRenderableReference() = 0;
00714 
00720     virtual uint32_t                getCustomBehaviorGroupCount() const = 0;
00721 
00728     virtual bool                    getBehaviorGroup(nvidia::DestructibleBehaviorGroupDesc& behaviorGroupDesc, int32_t index = -1) const = 0;
00729 
00730 protected:
00731     virtual                         ~DestructibleActor() {}
00732 };
00733 
00734 PX_POP_PACK
00735 
00736 }
00737 } // end namespace nvidia
00738 
00739 #endif // DESTRUCTIBLE_ACTOR_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.