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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/*
* 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.
*/
#ifndef __PARTICLE_IOS_ACTOR_IMPL_H__
#define __PARTICLE_IOS_ACTOR_IMPL_H__
#include "Apex.h"
#include "ParticleIosActor.h"
#include "iofx/IofxActor.h"
#include "ParticleIosAssetImpl.h"
#include "InstancedObjectSimulationIntl.h"
#include "ParticleIosScene.h"
#include "ApexActor.h"
#include "ApexContext.h"
#include "ApexFIFO.h"
#include "ParticleIosCommonCode.h"
#include "InplaceStorage.h"
#include "ApexMirroredArray.h"
#include "PxParticleExt.h"
#include "ApexRWLockable.h"
namespace nvidia
{
namespace apex
{
class FieldSamplerQueryIntl;
class FieldSamplerCallbackIntl;
}
namespace pxparticleios
{
/* Class for managing the interactions with each emitter */
class ParticleParticleInjector : public IosInjectorIntl, public ApexResourceInterface, public ApexResource, public ApexRWLockable
{
public:
APEX_RW_LOCKABLE_BOILERPLATE
void setPreferredRenderVolume(RenderVolume* volume);
float getLeastBenefitValue() const
{
return 0.0f;
}
bool isBacklogged() const
{
return false;
}
void createObjects(uint32_t count, const IosNewObject* createList);
#if APEX_CUDA_SUPPORT
void createObjects(ApexMirroredArray<const IosNewObject>& createArray);
#endif
void setLODWeights(float maxDistance, float distanceWeight, float speedWeight, float lifeWeight, float separationWeight, float bias);
PxTaskID getCompletionTaskID() const;
void release();
void destroy();
// ApexResourceInterface methods
void setListIndex(ResourceList& list, uint32_t index);
uint32_t getListIndex() const
{
return m_listIndex;
}
virtual void setPhysXScene(PxScene*) {}
virtual PxScene* getPhysXScene() const
{
return NULL;
}
void assignSimParticlesCount(uint32_t input)
{
mSimulatedParticlesCount = input;
}
virtual uint32_t getSimParticlesCount() const
{
return mSimulatedParticlesCount;
}
virtual uint32_t getActivePaticleCount() const;
virtual void setObjectScale(float objectScale);
protected:
ParticleIosActorImpl* mIosActor;
IofxManagerClientIntl* mIofxClient;
RenderVolume* mVolume;
physx::Array<uint16_t> mRandomActorClassIDs;
uint32_t mLastRandomID;
uint16_t mVolumeID;
uint32_t mInjectorID;
uint32_t mSimulatedParticlesCount;
/* insertion buffer */
ApexFIFO<IosNewObject> mInjectedParticles;
ParticleParticleInjector(ResourceList& list, ParticleIosActorImpl& actor, uint32_t injectorID);
~ParticleParticleInjector() {}
void init(IofxAsset* iofxAsset);
friend class ParticleIosActorImpl;
};
class ParticleIosActorImpl : public InstancedObjectSimulationIntl,
public ParticleIosActor,
public ApexResourceInterface,
public ApexResource,
public ApexRWLockable
{
public:
APEX_RW_LOCKABLE_BOILERPLATE
ParticleIosActorImpl(ResourceList& list, ParticleIosAssetImpl& asset, ParticleIosScene& scene, IofxAsset& iofxAsset, bool isDataOnDevice);
~ParticleIosActorImpl();
// ApexInterface API
void release();
void destroy();
// Actor API
void setPhysXScene(PxScene* s);
PxScene* getPhysXScene() const;
virtual void putInScene(PxScene* scene);
Asset* getOwner() const
{
READ_ZONE();
return (Asset*) mAsset;
}
// ApexContext
void getLodRange(float& min, float& max, bool& intOnly) const;
float getActiveLod() const;
void forceLod(float lod);
/**
\brief Selectively enables/disables debug visualization of a specific APEX actor. Default value it true.
*/
virtual void setEnableDebugVisualization(bool state)
{
WRITE_ZONE();
ApexActor::setEnableDebugVisualization(state);
}
// ApexResourceInterface methods
void setListIndex(ResourceList& list, uint32_t index)
{
m_listIndex = index;
m_list = &list;
}
uint32_t getListIndex() const
{
return m_listIndex;
}
// IOSIntl
float getObjectRadius() const
{
return getParticleRadius();
}
float getObjectDensity() const
{
return 1.0f;
} // mAsset->getRestDensity(); }
// ParticleIosActor
float getParticleRadius() const
{
return mAsset->getParticleRadius();
}
//float getRestDensity() const { return mAsset->getRestDensity();}
uint32_t getParticleCount() const
{
return mParticleCount;
}
PX_INLINE void setOnStartFSCallback(FieldSamplerCallbackIntl* callback)
{
if (mFieldSamplerQuery)
{
mFieldSamplerQuery->setOnStartCallback(callback);
}
}
PX_INLINE void setOnFinishIOFXCallback(IofxManagerCallbackIntl* callback)
{
if (mIofxMgr)
{
mIofxMgr->setOnFinishCallback(callback);
}
}
const PxVec3* getRecentPositions(uint32_t& count, uint32_t& stride) const;
void visualize();
virtual PxTaskID submitTasks(PxTaskManager* tm) = 0;
virtual void setTaskDependencies(PxTaskID taskStartAfterID, PxTaskID taskFinishBeforeID) = 0;
virtual void fetchResults();
IosInjectorIntl* allocateInjector(IofxAsset* iofxAsset);
void releaseInjector(IosInjectorIntl&);
virtual void setDensityOrigin(const PxVec3& v)
{
mDensityOrigin = v;
}
protected:
virtual void removeFromScene();
void injectNewParticles();
bool isParticleDescValid( const ParticleIosAssetParam* desc) const;
void initStorageGroups(InplaceStorage& storage);
void setTaskDependencies(PxTaskID taskStartAfterID, PxTaskID taskFinishBeforeID, PxTask* iosTask, bool isDataOnDevice);
ParticleIosAssetImpl* mAsset;
ParticleIosScene* mParticleIosScene;
bool mIsParticleSystem; // true:SimpleParticleSystemParams , false:FluidParticleSystemParams
PxActor* mParticleActor;
IofxManagerIntl* mIofxMgr;
IosBufferDescIntl mBufDesc;
ResourceList mInjectorList;
physx::Array<IofxAsset*> mIofxAssets;
physx::Array<uint32_t> mIofxAssetRefs;
PxVec3 mUp;
float mGravity;
float mTotalElapsedTime; //AM: People, methinks this will backfire eventually due to floating point precision loss!
uint32_t mMaxParticleCount;
uint32_t mMaxTotalParticleCount;
uint32_t mParticleCount;
uint32_t mParticleBudget;
uint32_t mInjectedCount;
float mInjectedBenefitSum;
float mInjectedBenefitMin;
float mInjectedBenefitMax;
uint32_t mLastActiveCount;
float mLastBenefitSum;
float mLastBenefitMin;
float mLastBenefitMax;
ApexMirroredArray<float> mLifeSpan;
ApexMirroredArray<float> mLifeTime;
ApexMirroredArray<uint32_t> mInjector;
ApexMirroredArray<float> mBenefit;
ApexMirroredArray<uint32_t> mInjectorsCounters;
ApexMirroredArray<uint32_t> mInputIdToParticleIndex;
ApexMirroredArray<float> mGridDensityGrid;
ApexMirroredArray<float> mGridDensityGridLowPass;
// Only for use by the IOS Asset, the actor is unaware of this
bool mIsMesh;
FieldSamplerQueryIntl* mFieldSamplerQuery;
ApexMirroredArray<PxVec4> mField;
InplaceStorageGroup mSimulationStorageGroup;
class InjectTask : public PxTask
{
public:
InjectTask(ParticleIosActorImpl& actor) : mActor(actor) {}
const char* getName() const
{
return "ParticleIosActorImpl::InjectTask";
}
void run()
{
mActor.injectNewParticles();
}
protected:
ParticleIosActorImpl& mActor;
private:
InjectTask& operator=(const InjectTask&);
};
InjectTask mInjectTask;
// Particle Density Origin
PxVec3 mDensityOrigin;
PxMat44 mDensityDebugMatInv;
GridDensityParams mGridDensityParams;
FieldSamplerCallbackIntl* mOnStartCallback;
IofxManagerCallbackIntl* mOnFinishCallback;
friend class ParticleIosAssetImpl;
friend class ParticleParticleInjector;
};
}
} // namespace nvidia
#endif // __PARTICLE_IOS_ACTOR_IMPL_H__
|