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      <h3>Generating Class Instances Required for Particle Playback</h3>
15      <p>You can generate instances of the ParticleContext and ParticleSceneUpdater classes. You only need one instance of each class per system.<BR> The ParticleContext class manages work memory and random numbers required by the particle system.  Shared memory </p>
16      <p>is used as a temporary buffer in the MaxEmission update process. The larger of the following two values is required.</p>
17      <ul>
18        <li>The maximum number of particles that can be emitted from a single emitter at one time (Note that this can become very large at a high playback rate.)</li>
19        <li>(Maximum number of work memories during execution + 8) ÷ 3 (truncated)</li>
20      </ul>
21      <p> In most cases, the latter will be larger.</p>
22<p>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. </p>
23<p>The ParticleSceneUpdater class updates the created node.<BR>
24</p>
25<pre>
26s_ParticleContext = nw::gfx::ParticleContext::Builder()
27    .MaxEmission(1000)
28    .MaxStreamLength(1000)
29    .UseDoubleBuffer(true)
30    .Create(&amp;s_DeviceAllocator);
31s_ParticleSceneUpdater = nw::gfx::ParticleSceneUpdater::Builder()
32    .Create(&amp;s_DeviceAllocator);
33</pre>
34      <h3>Loading and Setting Up Resources</h3>
35      <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>
36<pre>
37// Place the texture resource in VRAM.
38resourceSet-&gt;resource.ForeachTexture(nw::gfx::LocationFlagSetter(NN_GX_MEM_VRAMA | GL_NO_COPY_FCRAM_DMP));
39// Set up the resource.
40nw::gfx::Result result = resourceSet-&gt;resource.Setup(&amp;s_DeviceAllocator);
41</pre>
42      <h3>Generating Instances of the <CODE>ParticleModel</CODE> and <CODE>ParticleEmitter</CODE> Classes</h3>
43      <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>
44<pre>
45for (nw::gfx::ResModelArray::iterator modelResource = models.begin();
46     modelResource != modelsEnd; ++modelResource)
47{
48    nw::gfx::SceneNode* node = nw::demo::Utility::CreateSceneNode(…);
49    sceneNodeArray.push_back(node);
50    :
51}
52for (nw::gfx::ResEmitterArray::iterator emitterResource = emitters.begin();
53    emitterResource != emitters.end(); ++emitterResource)
54{
55    nw::gfx::SceneNode* node = nw::demo::Utility::CreateSceneNode(…);
56    sceneNodeArray.push_back(node);
57    :
58}
59</pre>
60      <h3>Resolving the Hierarchical Node Structure</h3>
61      <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>
62<pre>
63nw::gfx::SceneHelper::ResolveReference(sceneNodeArray);
64</pre>
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(&amp;sceneNodeArray, s_ParticleContext);
69</pre>
70      <h3>Adding Generated Instances to the Scene Tree</h3>
71      <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>
72<pre>
73nw::gfx::SceneHelper::ForeachRootNodes(…);
74</pre>
75      <h2>Updating</h2>
76
77      <h3>Updating the Scene Tree</h3>
78      <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>
79<pre>
80s_SceneSystem-&gt;UpdateScene();
81</pre>
82      <h3>Updating Particles</h3>
83      <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>
84<pre>
85s_ParticleSceneUpdater-&gt;UpdateNode(s_SceneSystem-&gt;GetSceneContext(), s_ParticleContext);
86</pre>
87      <h2>Rendering</h2>
88      <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>
89  </div>
90  <hr><p>CONFIDENTIAL</p></body>
91</html>
92