1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/
#include "RTdef.h"
#if RT_COMPILE
#include <PsUserAllocated.h>
#include "DestructibleActorImpl.h"
#include "Actor.h"
#include "Compound.h"
#include "Convex.h"
#include "CompoundCreator.h"
#include "Delaunay2d.h"
#include "Delaunay3d.h"
#include "PolygonTriangulator.h"
#include "IslandDetector.h"
#include "MeshClipper.h"
#include "FracturePattern.h"
#include "SimScene.h"
namespace nvidia
{
namespace fracture
{
void SimScene::onWake(PxActor** actors, uint32_t count){
if(mAppNotify != NULL)
mAppNotify->onWake(actors,count);
for(uint32_t i = 0; i < count; i++)
{
PxActor* actor = actors[i];
if(actor != NULL && actor->is<physx::PxRigidDynamic>())
{
uint32_t shapeCount = actor->is<physx::PxRigidDynamic>()->getNbShapes();
PxShape** shapes = (PxShape**)PX_ALLOC(sizeof(PxShape*)*shapeCount,"onWake Shapes Temp Buffer");
actor->is<physx::PxRigidDynamic>()->getShapes(shapes,sizeof(PxShape*)*shapeCount,0);
::nvidia::destructible::DestructibleActorImpl* prevActor = NULL;
for(uint32_t j = 0; j < shapeCount; j++)
{
nvidia::fracture::base::Convex* convex = findConvexForShape(*shapes[j]);
if(convex == NULL || convex->getParent() == NULL)
continue;
nvidia::fracture::Compound* parent = (nvidia::fracture::Compound*)convex->getParent();
::nvidia::destructible::DestructibleActorImpl* curActor = parent->getDestructibleActor();
if(convex && convex->getParent() && curActor != prevActor && curActor)
{
curActor->incrementWakeCount();
prevActor = curActor;
}
}
PX_FREE(shapes);
}
}
}
void SimScene::onSleep(PxActor** actors, uint32_t count){
if(mAppNotify != NULL)
mAppNotify->onSleep(actors,count);
for(uint32_t i = 0; i < count; i++)
{
PxActor* actor = actors[i];
if(actor != NULL && actor->is<physx::PxRigidDynamic>())
{
uint32_t shapeCount = actor->is<physx::PxRigidDynamic>()->getNbShapes();
PxShape** shapes = (PxShape**)PX_ALLOC(sizeof(PxShape*)*shapeCount,"onSleep Shapes Temp Buffer");
actor->is<physx::PxRigidDynamic>()->getShapes(shapes,sizeof(PxShape*)*shapeCount,0);
::nvidia::destructible::DestructibleActorImpl* prevActor = NULL;
for(uint32_t j = 0; j < shapeCount; j++)
{
nvidia::fracture::base::Convex* convex = findConvexForShape(*shapes[j]);
if(convex == NULL || convex->getParent() == NULL)
continue;
nvidia::fracture::Compound* parent = (nvidia::fracture::Compound*)convex->getParent();
::nvidia::destructible::DestructibleActorImpl* curActor = parent->getDestructibleActor();
if(convex && convex->getParent() && curActor != prevActor && curActor)
{
curActor->decrementWakeCount();;
prevActor = curActor;
}
}
PX_FREE(shapes);
}
}
}
SimScene* SimScene::createSimScene(PxPhysics *pxPhysics, PxCooking *pxCooking, PxScene *scene, float minConvexSize, PxMaterial* defaultMat, const char *resourcePath)
{
SimScene* s = PX_NEW(SimScene)(pxPhysics,pxCooking,scene,minConvexSize,defaultMat,resourcePath);
s->createSingletons();
return s;
}
void SimScene::createSingletons()
{
mCompoundCreator = PX_NEW(CompoundCreator)(this);
mDelaunay2d = PX_NEW(Delaunay2d)(this);
mDelaunay3d = PX_NEW(Delaunay3d)(this);
mPolygonTriangulator = PX_NEW(PolygonTriangulator)(this);
mIslandDetector = PX_NEW(IslandDetector)(this);
mMeshClipper = PX_NEW(MeshClipper)(this);
mDefaultGlass = PX_NEW(FracturePattern)(this);
mDefaultGlass->createGlass(10.0f,0.25f,30,0.3f,0.03f,1.4f,0.3f);
//mDefaultGlass->create3dVoronoi(PxVec3(10.0f, 10.0f, 10.0f), 50, 10.0f);
addActor(createActor(NULL));
}
base::Actor* SimScene::createActor(::nvidia::destructible::DestructibleActorImpl* actor)
{
return (base::Actor*)PX_NEW(Actor)(this,actor);
}
base::Convex* SimScene::createConvex()
{
return (base::Convex*)PX_NEW(Convex)(this);
}
base::Compound* SimScene::createCompound(const base::FracturePattern *pattern, const base::FracturePattern *secondaryPattern, float contactOffset, float restOffset)
{
return (base::Compound*)PX_NEW(Compound)(this,pattern,secondaryPattern,contactOffset,restOffset);
}
base::FracturePattern* SimScene::createFracturePattern()
{
return (base::FracturePattern*)PX_NEW(FracturePattern)(this);
}
SimScene::SimScene(PxPhysics *pxPhysics, PxCooking *pxCooking, PxScene *scene, float minConvexSize, PxMaterial* defaultMat, const char *resourcePath):
base::SimScene(pxPhysics,pxCooking,scene,minConvexSize,defaultMat,resourcePath)
{
}
// --------------------------------------------------------------------------------------------
SimScene::~SimScene()
{
PX_DELETE(mDefaultGlass);
mDefaultGlass = NULL;
}
}
}
#endif
|