1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[]> 2<html xml:lang="en-US" lang="en-US"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <meta http-equiv="Content-Style-Type" content="text/css" /> 6 <link rel="stylesheet" href="../../../css/document.css" type="text/css" /> 7 <title>Simplest Method of Using Particles</title> 8 </head> 9 <body> 10 <h1>Simplest Method of Using Particles</h1> 11 <div class="section"> 12 <p>This document uses the <a href="../demo/ParticleDemo.html"><CODE>ParticleDemo</CODE></a> to explain the steps from loading resources through to playing an animation.</p> 13 <h2>From Loading Resources Until Playback</h2> 14 15 <h3>Generating Class Instances Required for Particle Playback</h3> 16 <p>Generate instances of the <CODE>ParticleContext</CODE> and <CODE>ParticleSceneUpdater</CODE> classes. The <CODE>ParticleContext</CODE> class carries out required particle system work and manages random numbers, and the <CODE>ParticleSceneUpdater</CODE> class updates generated nodes. You only need one instance of each class per system.</p> 17<pre> 18s_ParticleContext = nw::gfx::ParticleContext::Builder() 19 .MaxEmission(1000) 20 .Create(&s_DeviceAllocator); 21 22s_ParticleSceneUpdater = nw::gfx::ParticleSceneUpdater::Builder() 23 .Create(&s_DeviceAllocator); 24</pre> 25 26 <h3>Loading and Setting Up Resources</h3> 27 <p>Use the <CODE>nw::demo::Utility::LoadResources</CODE> function to easily load resources. Then set up the loaded resources. See <a href="GenerateDestruction.html#resgraphicsload">Loading and Setting Up <CODE>ResGraphicsFile</CODE>s</a> and <a href="GenerateDestruction.html#resgraphics"><CODE>ResGraphicsFile</CODE> Operations</a> for details.</p> 28<pre> 29// Place the texture resource in VRAM. 30resourceSet->resource.ForeachTexture(nw::gfx::LocationFlagSetter(NN_GX_MEM_VRAMA | GL_NO_COPY_FCRAM_DMP)); 31 32// Set up the resource. 33nw::gfx::Result result = resourceSet->resource.Setup(&s_DeviceAllocator); 34</pre> 35 36 37 <h3>Generating Instances of the <CODE>ParticleModel</CODE> and <CODE>ParticleEmitter</CODE> Classes</h3> 38 <p>Generate instances of the <CODE>ParticleModel</CODE> and <CODE>ParticleEmitter</CODE> classes from the <a href="../../../nw/gfx/res/ResGraphicsFile/GetModels.html"><CODE>ResModelArray</CODE></a> and <a href="../../../nw/gfx/res/ResGraphicsFile/GetEmitters.html"><CODE>ResEmitterArray</CODE></a> objects. See <a href="../BasicFeature.html#play">Model Display</a> for more details.</p> 39<pre> 40for (nw::gfx::ResModelArray::iterator modelResource = models.begin(); 41 modelResource != modelsEnd; ++modelResource) 42{ 43 nw::gfx::SceneNode* node = nw::demo::Utility::CreateSceneNode(…); 44 sceneNodeArray.push_back(node); 45 : 46} 47 48for (nw::gfx::ResEmitterArray::iterator emitterResource = emitters.begin(); 49 emitterResource != emitters.end(); ++emitterResource) 50{ 51 nw::gfx::SceneNode* node = nw::demo::Utility::CreateSceneNode(…); 52 sceneNodeArray.push_back(node); 53 : 54} 55</pre> 56 57 58 <h3>Resolving the Hierarchical Node Structure</h3> 59 <p>Use the <CODE><a href="../../../nw/gfx/SceneHelper/Overview.html">SceneHelper</a>::<a href="../../../nw/gfx/SceneHelper/ResolveReference.html">ResolveReference</a></CODE> function to resolve the node reference structure. See <a href="../BasicFeature.html#play">Model Display</a> for more details.</p> 60<pre> 61nw::gfx::SceneHelper::ResolveReference(sceneNodeArray); 62</pre> 63 64 65 <h3>Initializing Particles</h3> 66 <p>Call the <a href="../../../nw/gfx/ParticleUtil/SetupParticleObject.html"><CODE>SetupParticleObject</CODE></a> function to resolve a particle object's internal references and initialize its random numbers. See <a href="GenerateDestruction.html#createinst">Generating Instances</a> for more details.</p> 67<pre> 68nw::gfx::ParticleUtil::SetupParticleObject(&sceneNodeArray, s_ParticleContext); 69</pre> 70 71 72 <h3>Adding Generated Instances to the Scene Tree</h3> 73 <p>Add the <a href="../../../nw/gfx/SceneNode/Overview.html">SceneNode</a> to the scene tree after resolving references. Particle generation begins after adding the node to the tree.</p> 74<pre> 75nw::gfx::SceneHelper::ForeachRootNodes(…); 76</pre> 77 78 79 <h2>Updating</h2> 80 81 <h3>Updating the Scene Tree</h3> 82 <p>Call the <a href="../../../nw/demo/SceneSystem/UpdateScene.html"><CODE>nw::demo::SceneSystem::UpdateScene</CODE></a> function to update nodes registered in the scene tree.</p> 83<pre> 84s_SceneSystem->UpdateScene(); 85</pre> 86 87 88 <h3>Updating Particles</h3> 89 <p>Call the <a href="../../../nw/gfx/ParticleSceneUpdater/UpdateNode.html"><CODE>nw::gfx::ParticleSceneUpdater::UpdateNode</CODE></a> function to update particle frames and animate emitters and particles. See <a href="Calc.html">Features Used in Particle Calculations</a> for details.</p> 90<pre> 91s_ParticleSceneUpdater->UpdateNode(s_SceneSystem->GetSceneContext(), s_ParticleContext); 92</pre> 93 94 <h2>Rendering</h2> 95 <p>Run the normal <CODE>gfx</CODE> rendering. You do not need to do any specific particle processing at the application level. See <a href="Draw.html">Features Used in Particle Calculations</a> for details.</p> 96 </div> 97 <hr><p>CONFIDENTIAL</p></body> 98</html>