diff options
author | Nivesh Rajbhandari | 2012-04-16 16:06:24 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-16 16:06:24 -0700 |
commit | c253192a08b499ea7be46fa5438d273e51f7ec5a (patch) | |
tree | 18a1f0e3679c0eb993a9dedb537035d3861f49ac /js/helper-classes/RDGE/src/core/script/particle.js | |
parent | e19376c54eedd1f1c457ba405b2f110be376a559 (diff) | |
parent | 4b900ea5cd6bb77eb30cec8c03b9ec9fa662c1e9 (diff) | |
download | ninja-c253192a08b499ea7be46fa5438d273e51f7ec5a.tar.gz |
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/particle.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/particle.js | 1591 |
1 files changed, 761 insertions, 830 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/particle.js b/js/helper-classes/RDGE/src/core/script/particle.js index dd83433e..3968786d 100755 --- a/js/helper-classes/RDGE/src/core/script/particle.js +++ b/js/helper-classes/RDGE/src/core/script/particle.js | |||
@@ -4,839 +4,770 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | particleStats = function() { | 7 | var RDGE = RDGE || {}; |
8 | this.numParticles = new stat("particles", "numParticles", 0); | 8 | |
9 | this.numDrawCalls = new stat("particles", "numDrawCalls", 0); | 9 | RDGE.particle = function (def, id) { |
10 | this.numVerts = new stat("particles", "numVerts", 0); | 10 | this.id = id; |
11 | this.numTris = new stat("particles", "numTris", 0); | 11 | this.def = def; |
12 | 12 | if (this.def.numFrames == undefined) { | |
13 | this.report = function(psys) { | 13 | if (this.def.textureSize && this.def.frameSize) { |
14 | for (em in psys.emitters) { | 14 | this.def.numFrames = (this.def.textureSize[0] / this.def.frameSize[0]) * (this.def.textureSize[1] / this.def.frameSize[1]); |
15 | var pbuffer = psys.emitters[em].pbuffer; | 15 | } else { |
16 | var idxBuffer = pbuffer.indexBuffer.front(); | 16 | this.def.numFrames = 0; |
17 | var posBuffer = pbuffer.posBuffer.front(); | 17 | } |
18 | this.numParticles.value += idxBuffer.numIndices / 6; | 18 | } |
19 | this.numTris.value += idxBuffer.numIndices / 3; | 19 | |
20 | this.numVerts.value += this.numParticles.value * 4; | 20 | this.pos = RDGE.vec3.zero(); |
21 | if(this.numParticles.value > 0) { | 21 | this.delta = RDGE.vec3.zero(); |
22 | this.numDrawCalls.value++; | 22 | this.rotate = 0.0; |
23 | } | 23 | this.age = 0.0; |
24 | } | 24 | this.lifespan = 0.0; |
25 | } | 25 | this.velocity = RDGE.vec3.zero(); |
26 | }; | 26 | this.gravity = RDGE.vec3.zero(); |
27 | 27 | this.frame = 0; | |
28 | g_particleStats = null; | 28 | this.frameCount = 0; |
29 | //if( g_enableBenchmarks ) { | 29 | this.lastPos = RDGE.vec3.zero(); |
30 | // g_particleStats = new particleStats; | 30 | this.state = 0; |
31 | //} | 31 | this.hide = false; |
32 | 32 | this.color = RDGE.vec4.zero(); | |
33 | particle = function(def, id) { | 33 | |
34 | this.id = id; | 34 | this.randomize = function (min, max) { |
35 | this.def = def; | 35 | return min + (max - min) * Math.random(); |
36 | if( this.def.numFrames == undefined ) { | 36 | }; |
37 | if( this.def.textureSize && this.def.frameSize ) { | 37 | this.rate = this.randomize(-1.0, 1.0); |
38 | this.def.numFrames = ( this.def.textureSize[0] / this.def.frameSize[0] ) * ( this.def.textureSize[1] / this.def.frameSize[1] ); | 38 | |
39 | } else { | 39 | this.randomize3 = function (min, max) { |
40 | this.def.numFrames = 0; | 40 | return [this.randomize(min[0], max[0]), |
41 | } | ||
42 | } | ||
43 | |||
44 | this.pos = vec3.zero(); | ||
45 | this.delta = vec3.zero(); | ||
46 | this.rotate = 0.0; | ||
47 | this.age = 0.0; | ||
48 | this.lifespan = 0.0; | ||
49 | this.velocity = vec3.zero(); | ||
50 | this.gravity = vec3.zero(); | ||
51 | this.frame = 0; | ||
52 | this.frameCount = 0; | ||
53 | this.lastPos = vec3.zero(); | ||
54 | this.state = 0; | ||
55 | this.hide = false; | ||
56 | this.color = vec4.zero(); | ||
57 | |||
58 | this.randomize = function(min, max) { | ||
59 | return min + (max - min) * Math.random(); | ||
60 | } | ||
61 | this.rate = this.randomize( -1.0, 1.0 ); | ||
62 | |||
63 | this.randomize3 = function(min, max) { | ||
64 | return [this.randomize(min[0], max[0]), | ||
65 | this.randomize(min[1], max[1]), | 41 | this.randomize(min[1], max[1]), |
66 | this.randomize(min[2], max[2])]; | 42 | this.randomize(min[2], max[2])]; |
67 | } | 43 | }; |
68 | 44 | ||
69 | this.spawn = function(spawnMatrix) { | 45 | this.spawn = function (spawnMatrix) { |
70 | if( this.def.initialframe == undefined ) { | 46 | if (this.def.initialframe == undefined) { |
71 | this.frame = this.id % this.def.numFrames; | 47 | this.frame = this.id % this.def.numFrames; |
72 | } else { | 48 | } else { |
73 | this.frame = this.randomize( this.def.initialframe[0], this.def.initialframe[1] ); | 49 | this.frame = this.randomize(this.def.initialframe[0], this.def.initialframe[1]); |
74 | } | 50 | } |
75 | this.pos = this.randomize3(this.def.initialpos[0], this.def.initialpos[1]); | 51 | this.pos = this.randomize3(this.def.initialpos[0], this.def.initialpos[1]); |
76 | if (this.def.worldSpace) { | 52 | if (this.def.worldSpace) { |
77 | // calculate the initial position in world space. | 53 | // calculate the initial position in world space. |
78 | this.pos = mat4.transformPoint( spawnMatrix, this.pos ); | 54 | this.pos = RDGE.mat4.transformPoint(spawnMatrix, this.pos); |
79 | } | 55 | } |
80 | // all other values are assumed to be defined in local or world space depending on | 56 | // all other values are assumed to be defined in local or world space depending on |
81 | // the particles worldSpace designation. | 57 | // the particles worldSpace designation. |
82 | var toRadians = Math.PI/180.0; | 58 | var toRadians = Math.PI / 180.0; |
83 | if( this.def.initialsize ) { | 59 | if (this.def.initialsize) { |
84 | this.size = this.randomize(this.def.initialsize[0], this.def.initialsize[1]); | 60 | this.size = this.randomize(this.def.initialsize[0], this.def.initialsize[1]); |
85 | } else { | 61 | } else { |
86 | this.size = 1.0; | 62 | this.size = 1.0; |
87 | } | 63 | } |
88 | this.velocity = this.randomize3(this.def.initialvel[0], this.def.initialvel[1]); | 64 | this.velocity = this.randomize3(this.def.initialvel[0], this.def.initialvel[1]); |
89 | this.gravity = [this.def.gravity[0], this.def.gravity[1], this.def.gravity[2]]; | 65 | this.gravity = [this.def.gravity[0], this.def.gravity[1], this.def.gravity[2]]; |
90 | this.rotate = this.randomize(this.def.initialrot[0] * toRadians, this.def.initialrot[1] * toRadians); | 66 | this.rotate = this.randomize(this.def.initialrot[0] * toRadians, this.def.initialrot[1] * toRadians); |
91 | this.lifespan = this.randomize(this.def.lifespan[0], this.def.lifespan[1]); | 67 | this.lifespan = this.randomize(this.def.lifespan[0], this.def.lifespan[1]); |
92 | this.age = 0.0; | 68 | this.age = 0.0; |
93 | this.delta = [0.0, 0.0, 0.0]; | 69 | this.delta = [0.0, 0.0, 0.0]; |
94 | this.lastPos = vec3.add(this.pos, vec3.scale(this.velocity, -1.0 / 30.0)); | 70 | this.lastPos = RDGE.vec3.add(this.pos, RDGE.vec3.scale(this.velocity, -1.0 / 30.0)); |
95 | this.color = [1,1,1,1];//vec4.random( [0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0] ); | 71 | this.color = [1, 1, 1, 1]; //RDGE.vec4.random( [0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0] ); |
96 | } | 72 | }; |
97 | } | 73 | }; |
98 | 74 | ||
99 | // double buffered array utility class | 75 | // double buffered array utility class |
100 | DoubleBuffer = function(arrType, size) { | 76 | RDGE.DoubleBuffer = function (arrType, size) { |
101 | this.buffer = {}; | 77 | this.buffer = {}; |
102 | this.buffer[0] = new arrType(size); | 78 | this.buffer[0] = new arrType(size); |
103 | this.buffer[1] = new arrType(size); | 79 | this.buffer[1] = new arrType(size); |
104 | this.bufferIndex = 0; | 80 | this.bufferIndex = 0; |
105 | 81 | ||
106 | this.flip = function() { | 82 | this.flip = function () { |
107 | this.bufferIndex = 1 - this.bufferIndex; | 83 | this.bufferIndex = 1 - this.bufferIndex; |
108 | } | 84 | } |
109 | this.front = function() { | 85 | this.front = function () { |
110 | return this.buffer[this.bufferIndex]; | 86 | return this.buffer[this.bufferIndex]; |
111 | } | 87 | } |
112 | this.back = function() { | 88 | this.back = function () { |
113 | return this.buffer[1 - this.bufferIndex]; | 89 | return this.buffer[1 - this.bufferIndex]; |
114 | } | 90 | } |
115 | } | 91 | }; |
116 | 92 | ||
117 | 93 | ||
118 | // cycling buffer | 94 | // cycling buffer |
119 | particleBuffer = function(pdef, emitter, size) | 95 | RDGE.particleBuffer = function (pdef, emitter, size) { |
120 | { | 96 | var renderer = RDGE.globals.engine.getContext().renderer; |
121 | var renderer = g_Engine.getContext().renderer; | 97 | var ctx = renderer.ctx; |
122 | var ctx = renderer.ctx; | 98 | |
123 | 99 | s_particleShader = new RDGE.jshader(); | |
124 | s_particleShader = new jshader(); | 100 | s_particleShader.def = { |
125 | s_particleShader.def = { | 101 | 'shaders': { |
126 | 'shaders': { | 102 | 'defaultVShader': "assets/shaders/particle_vshader.glsl", |
127 | 'defaultVShader': "assets/shaders/particle_vshader.glsl", | 103 | 'defaultFShader': "assets/shaders/particle_fshader.glsl" |
128 | 'defaultFShader': "assets/shaders/particle_fshader.glsl" | 104 | }, |
129 | }, | 105 | 'techniques': { |
130 | 'techniques': { | 106 | 'defaultTechnique': [{ |
131 | 'defaultTechnique': [{ | 107 | 'vshader': 'defaultVShader', |
132 | 'vshader' : 'defaultVShader', | 108 | 'fshader': 'defaultFShader', |
133 | 'fshader' : 'defaultFShader', | 109 | 'attributes': { |
134 | 'attributes' : { | 110 | 'a_pos': { 'type': 'vec4' }, |
135 | 'a_pos' : { 'type' : 'vec4' }, | 111 | 'a_posId': { 'type': 'float' }, |
136 | 'a_posId' : { 'type' : 'float' }, | 112 | 'a_rotation': { 'type': 'float' }, |