MCPcopy Create free account
hub / github.com/carbonengine/trinity / Rebuild

Method Rebuild

trinity/Eve/Renderable/EveSceneStaticParticles.cpp:225–328  ·  view source on GitHub ↗

-------------------------------------------------------------------------------- Description: Distributes particles in the clusters. --------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

223// Distributes particles in the clusters.
224// --------------------------------------------------------------------------------
225void EveSceneStaticParticles::Rebuild()
226{
227 if( !m_mesh )
228 {
229 return;
230 }
231
232 // this object must have been set via python
233 Tr2RuntimeInstanceData* instanceData = GetInstanceDataObject();
234 if( !instanceData )
235 {
236 return;
237 }
238
239 // setup particle system
240 Tr2VertexDefinition particleBufferVtxDef;
241 particleBufferVtxDef.Add( Tr2VertexDefinition::FLOAT32_3, Tr2VertexDefinition::POSITION );
242 particleBufferVtxDef.Add( Tr2VertexDefinition::FLOAT32_1, Tr2VertexDefinition::TEXCOORD, 0 );
243 particleBufferVtxDef.Add( Tr2VertexDefinition::FLOAT32_4, Tr2VertexDefinition::TEXCOORD, 1 );
244 instanceData->SetLayout( particleBufferVtxDef );
245
246 // need total radius and a center for all clusters
247 m_centerOfClusters = Vector3d( 0.0, 0.0, 0.0 );
248 for( auto it = m_clusters.begin(); it != m_clusters.end(); ++it )
249 {
250 const ClusterData* clusterData = &( *it );
251 m_centerOfClusters += Vector3d( (double)clusterData->position.x, (double)clusterData->position.y, (double)clusterData->position.z );
252 }
253 m_centerOfClusters /= (double)m_clusters.size();
254
255 // need total size of particle buffer
256 size_t particleBufferSize = 0;
257 for( auto it = m_clusters.begin(); it != m_clusters.end(); ++it )
258 {
259 const ClusterData* clusterData = &( *it );
260 particleBufferSize += size_t( m_clusterParticleDensity * clusterData->radius );
261 }
262
263 // are we too big? Too many particles? Do we need to adjust?
264 m_clusterParticleDensityAdjust = 1.f;
265 if( particleBufferSize > m_maxParticleCount )
266 {
267 m_clusterParticleDensityAdjust = float( m_maxParticleCount ) / float( particleBufferSize );
268 }
269
270 // count particle buffer size again, this time with adjustment
271 particleBufferSize = 0;
272 for( auto it = m_clusters.begin(); it != m_clusters.end(); ++it )
273 {
274 const ClusterData* clusterData = &( *it );
275 particleBufferSize += size_t( m_clusterParticleDensityAdjust * m_clusterParticleDensity * clusterData->radius );
276 }
277
278 // alloc big buffer in the particle system
279 ParticleBufferItem* currentParticleBufferItem = static_cast<ParticleBufferItem*>( instanceData->GetData( (unsigned int)particleBufferSize ) );
280
281 // run over all the clusters and build
282 for( auto it = m_clusters.begin(); it != m_clusters.end(); ++it )

Callers

nothing calls this directly

Calls 15

TriRandomSeedFunction · 0.85
TriFloatRandomGaussFunction · 0.85
LerpFunction · 0.85
TriFloatRandom01Function · 0.85
BoundingSphereFromBoxFunction · 0.85
sizeMethod · 0.80
UpdateBoundingBoxMethod · 0.80
Vector3dClass · 0.50
Vector3Class · 0.50
AddMethod · 0.45
SetLayoutMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected