-------------------------------------------------------------------------------- Description: Distributes particles in the clusters. --------------------------------------------------------------------------------
| 223 | // Distributes particles in the clusters. |
| 224 | // -------------------------------------------------------------------------------- |
| 225 | void 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 ) |
nothing calls this directly
no test coverage detected