Simplest Method of Using Particles

This document uses the ParticleDemo to explain the steps from loading resources through to playing an animation.

From Loading Resources Until Playback

Generating Class Instances Required for Particle Playback

Generate instances of the ParticleContext and ParticleSceneUpdater classes. The ParticleContext class carries out required particle system work and manages random numbers, and the ParticleSceneUpdater class updates generated nodes. You only need one instance of each class per system.

s_ParticleContext = nw::gfx::ParticleContext::Builder()
    .MaxEmission(1000)
    .Create(&s_DeviceAllocator);

s_ParticleSceneUpdater = nw::gfx::ParticleSceneUpdater::Builder()
    .Create(&s_DeviceAllocator);

Loading and Setting Up Resources

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);

Generating Instances of the ParticleModel and ParticleEmitter Classes

Generate 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);
    :
}

Resolving the Hierarchical Node Structure

Use the SceneHelper::ResolveReference function to resolve the node reference structure. See Model Display for more details.

nw::gfx::SceneHelper::ResolveReference(sceneNodeArray);

Initializing Particles

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);

Adding Generated Instances to the Scene Tree

Add the SceneNode to the scene tree after resolving references. Particle generation begins after adding the node to the tree.

nw::gfx::SceneHelper::ForeachRootNodes(…);

Updating

Updating the Scene Tree

Call the nw::demo::SceneSystem::UpdateScene function to update nodes registered in the scene tree.

s_SceneSystem->UpdateScene();

Updating Particles

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);

Rendering

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