This document uses the ParticleDemo to explain the steps from loading resources through to playing an animation.
You can generate instances of the ParticleContext and ParticleSceneUpdater classes. You only need one instance of each class per system.
The ParticleContext class manages work memory and random numbers required by the particle system. Shared memory
is used as a temporary buffer in the MaxEmission update process. The larger of the following two values is required.
In most cases, the latter will be larger.
MaxStreamLength is enabled only when UseDoubleBuffer is true. Memory is not allocated if it is false. Memory allocated in this manner is used to work around the previous particle position when executing multiple update processes in the same frame. The required value is the maximum number of work memories during execution.
The ParticleSceneUpdater class updates the created node.
s_ParticleContext = nw::gfx::ParticleContext::Builder()
.MaxEmission(1000)
.MaxStreamLength(1000)
.UseDoubleBuffer(true)
.Create(&s_DeviceAllocator);
s_ParticleSceneUpdater = nw::gfx::ParticleSceneUpdater::Builder()
.Create(&s_DeviceAllocator);
Use the nw::demo::Utility::LoadResources function to easily load resources. Then set up the loaded resources. See Loading and Setting Up ResGraphicsFiles and ResGraphicsFile Operations for details.
// Place the texture resource in VRAM. resourceSet->resource.ForeachTexture(nw::gfx::LocationFlagSetter(NN_GX_MEM_VRAMA | GL_NO_COPY_FCRAM_DMP)); // Set up the resource. nw::gfx::Result result = resourceSet->resource.Setup(&s_DeviceAllocator);
ParticleModel and ParticleEmitter ClassesGenerate instances of the ParticleModel and ParticleEmitter classes from the ResModelArray and ResEmitterArray objects. See Model Display for more details.
for (nw::gfx::ResModelArray::iterator modelResource = models.begin();
modelResource != modelsEnd; ++modelResource)
{
nw::gfx::SceneNode* node = nw::demo::Utility::CreateSceneNode(…);
sceneNodeArray.push_back(node);
:
}
for (nw::gfx::ResEmitterArray::iterator emitterResource = emitters.begin();
emitterResource != emitters.end(); ++emitterResource)
{
nw::gfx::SceneNode* node = nw::demo::Utility::CreateSceneNode(…);
sceneNodeArray.push_back(node);
:
}
Use the SceneHelper::ResolveReference function to resolve the node reference structure. See Model Display for more details.
nw::gfx::SceneHelper::ResolveReference(sceneNodeArray);
Call the SetupParticleObject function to resolve a particle object's internal references and initialize its random numbers. See Generating Instances for more details.
nw::gfx::ParticleUtil::SetupParticleObject(&sceneNodeArray, s_ParticleContext);
Add the SceneNode to the scene tree after resolving references. Particle generation begins after adding the node to the tree.
nw::gfx::SceneHelper::ForeachRootNodes(…);
Call the nw::demo::SceneSystem::UpdateScene function to update nodes registered in the scene tree.
s_SceneSystem->UpdateScene();
Call the nw::gfx::ParticleSceneUpdater::UpdateNode function to update particle frames and animate emitters and particles. See Features Used in Particle Calculations for details.
s_ParticleSceneUpdater->UpdateNode(s_SceneSystem->GetSceneContext(), s_ParticleContext);
Run the normal gfx rendering. You do not need to do any specific particle processing at the application level. See Features Used in Particle Calculations for details.
CONFIDENTIAL