aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/rdge-compiled.js
blob: 53a99c35f9a1bbd1b87572eb2528943d3c51398e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
var RDGE=RDGE||{};RDGE.vec2={};RDGE.vec2.string=function(a){return"{ "+a[0]+", "+a[1]+" }"};RDGE.vec2.verify=function(a){return void 0==a||void 0==a.length||2>a.length||"number"!=typeof a[0]||"number"!=typeof a[1]?!1:!0};RDGE.vec2.copy=function(a){return void 0==a.length?[a,a]:[a[0],a[1]]};RDGE.vec2.inplace_copy=function(a,b){a[0]=b[0];a[1]=b[1]};RDGE.vec2.zero=function(){return[0,0]};RDGE.vec2.up=function(){return[0,1]};RDGE.vec2.right=function(){return[1,0]};
RDGE.vec2.add=function(a,b){return[a[0]+b[0],a[1]+b[1]]};RDGE.vec2.sub=function(a,b){return[a[0]-b[0],a[1]-b[1]]};RDGE.vec2.mul=function(a,b){return[a[0]*b[0],a[1]*b[1]]};RDGE.vec2.addMul=function(a,b,c){return void 0!=c.length&&2<=c.length?[a[0]+b[0]*c[0],a[1]+b[1]*c[1]]:[a[0]+b[0]*c,a[1]+b[1]*c]};RDGE.vec2.scale=function(a,b){return void 0!=b.length&&2<=b.length?[a[0]*b[0],a[1]*b[1]]:[a[0]*b,a[1]*b]};RDGE.vec2.negate=function(a){return[-a[0],-a[1]]};
RDGE.vec2.normalize=function(a){var b=Math.sqrt(a[0]*a[0],a[1]*a[1]);return 1.0E-4<Math.abs(1-b)?(b=1/b,[a[0]*b,a[1]*b]):a};RDGE.vec2.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]};RDGE.vec2.perp=function(a){return[a[1],-a[0]]};RDGE.vec2.lengthSq=function(a){return a[0]*a[0]+a[1]*a[1]};RDGE.vec2.length=function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1])};RDGE.vec2.min=function(a,b){return[Math.min(a[0],b[0]),Math.min(a[1],b[1])]};RDGE.vec2.max=function(a,b){return[Math.max(a[0],b[0]),Math.max(a[1],b[1])]};
RDGE.vec2.clamp=function(a,b,c){return RDGE.vec2.min(c,RDGE.vec2.max(a,b))};RDGE=RDGE||{};RDGE.vec3={};RDGE.vec3.string=function(a){return"{ "+a[0]+", "+a[1]+", "+a[2]+" }"};RDGE.vec3.verify=function(a){return void 0==a||void 0==a.length||3>a.length||"number"!=typeof a[0]||"number"!=typeof a[1]||"number"!=typeof a[2]?!1:!0};RDGE.vec3.inplace_copy=function(a,b){a[0]=b[0];a[1]=b[1];a[2]=b[2]};RDGE.vec3.copy=function(a){return void 0==a.length?[a,a,a]:[a[0],a[1],a[2]]};RDGE.vec3.translation=function(a){return[a[12],a[13],a[14]]};
RDGE.vec3.basisX=function(a){return[a[0],a[1],a[2]]};RDGE.vec3.basisY=function(a){return[a[4],a[5],a[6]]};RDGE.vec3.basisZ=function(a){return[a[8],a[9],a[10]]};RDGE.vec3.zero=function(){return[0,0,0]};RDGE.vec3.up=function(){return[0,1,0]};RDGE.vec3.forward=function(){return[0,0,1]};RDGE.vec3.right=function(){return[1,0,0]};RDGE.vec3.random=function(a,b){return[a[0]+(b[0]-a[0])*Math.random(),a[1]+(b[1]-a[1])*Math.random(),a[2]+(b[2]-a[2])*Math.random()]};RDGE.vec3.xy=function(a){return[a[0],a[1]]};
RDGE.vec3.xz=function(a){return[a[0],a[2]]};RDGE.vec3.add=function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2]]};RDGE.vec3.plusEqual=function(a,b){a[0]+=b[0];a[1]+=b[1];a[2]+=b[2]};RDGE.vec3.sub=function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2]]};RDGE.vec3.mul=function(a,b){return[a[0]*b[0],a[1]*b[1],a[2]*b[2]]};RDGE.vec3.addMul=function(a,b,c){return void 0!=c.length&&3<=c.length?[a[0]+b[0]*c[0],a[1]+b[1]*c[1],a[2]+b[2]*c[2]]:[a[0]+b[0]*c,a[1]+b[1]*c,a[2]+b[2]*c]};
RDGE.vec3.plusEqualMul=function(a,b,c){void 0!==c.length&&3<=c.length?(a[0]+=b[0]*c[0],a[1]+=b[1]*c[1],a[2]+=b[2]*c[2]):(a[0]+=b[0]*c,a[1]+=b[1]*c,a[2]+=b[2]*c)};RDGE.vec3.scale=function(a,b){return void 0!==b.length&&3<=b.length?[a[0]*b[0],a[1]*b[1],a[2]*b[2]]:[a[0]*b,a[1]*b,a[2]*b]};RDGE.vec3.inplace_scale=function(a,b){void 0!==b.length&&3<=b.length?(a[0]*=b[0],a[1]*=b[1],a[2]*=b[2]):(a[0]*=b,a[1]*=b,a[2]*=b)};RDGE.vec3.negate=function(a){return[-a[0],-a[1],-a[2]]};
RDGE.vec3.inplace_negate=function(a){a[0]=-a[0];a[1]=-a[1];a[2]=-a[2]};RDGE.vec3.normalize=function(a){var b=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);return 1.0E-4<Math.abs(1-b)?(b=1/b,[a[0]*b,a[1]*b,a[2]*b]):a};RDGE.vec3.cross=function(a,b){return[a[1]*b[2]-b[1]*a[2],a[2]*b[0]-b[2]*a[0],a[0]*b[1]-b[0]*a[1]]};RDGE.vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]};RDGE.vec3.lengthSq=function(a){return a[0]*a[0]+a[1]*a[1]+a[2]*a[2]};
RDGE.vec3.length=function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2])};RDGE.vec3.distanceSq=function(a,b){var c=[a[0]-b[0],a[1]-b[1],a[2]-b[2]];return c[0]*c[0]+c[1]*c[1]+c[2]*c[2]};RDGE.vec3.distance=function(a,b){var c=[a[0]-b[0],a[1]-b[1],a[2]-b[2]];return Math.sqrt(c[0]*c[0]+c[1]*c[1]+c[2]*c[2])};RDGE.vec3.angle=function(a,b){return Math.acos(RDGE.vec3.dot(a,b))/(RDGE.vec3.length(a)*RDGE.vec3.length(b))};RDGE.vec3.direction=function(a,b){return RDGE.vec3.normalize(RDGE.vec3.sub(b,a))};
RDGE.vec3.abs=function(a){return[Math.abs(a[0]),Math.abs(a[1]),Math.abs(a[2])]};RDGE.vec3.min=function(a,b){return[Math.min(a[0],b[0]),Math.min(a[1],b[1]),Math.min(a[2],b[2])]};RDGE.vec3.max=function(a,b){return[Math.max(a[0],b[0]),Math.max(a[1],b[1]),Math.max(a[2],b[2])]};RDGE.vec3.clamp=function(a,b,c){return RDGE.vec3.min(c,RDGE.vec3.max(a,b))};RDGE.vec3.equal=function(a,b,c){c||(c=0.0010);return RDGE.vec3.distanceSq(a,b)<c*c};
RDGE.vec3.lerp=function(a,b,c){return[a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c,a[2]+(b[2]-a[2])*c]};RDGE=RDGE||{};RDGE.vec4={};RDGE.vec4.string=function(a){return"{ "+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+" }"};RDGE.vec4.verify=function(a){return void 0==a||void 0==a.length||4>a.length||"number"!=typeof a[0]||"number"!=typeof a[1]||"number"!=typeof a[2]||"number"!=typeof a[3]?!1:!0};RDGE.vec4.inplace_copy=function(a,b){a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3]};RDGE.vec4.copy=function(a){return void 0==a.length?[a,a,a,a]:3==a.length?[a[0],a[1],a[2],1]:[a[0],a[1],a[2],a[3]]};
RDGE.vec4.zero=function(){return[0,0,0,0]};RDGE.vec4.identity=function(){return[0,0,0,1]};RDGE.vec4.up=function(){return[0,1,0,0]};RDGE.vec4.forward=function(){return[0,0,1,0]};RDGE.vec4.right=function(){return[1,0,0,0]};RDGE.vec4.random=function(a,b){return[a[0]+(b[0]-a[0])*Math.random(),a[1]+(b[1]-a[1])*Math.random(),a[2]+(b[2]-a[2])*Math.random(),a[3]+(b[3]-a[3])*Math.random()]};RDGE.vec4.add=function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2],a[3]+b[3]]};
RDGE.vec4.sub=function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2],a[3]-b[3]]};RDGE.vec4.mul=function(a,b){return[a[0]*b[0],a[1]*b[1],a[2]*b[2],a[3]*b[3]]};RDGE.vec4.addMul=function(a,b,c){return void 0!=c.length&&4<=c.length?[a[0]+b[0]*c[0],a[1]+b[1]*c[1],a[2]+b[2]*c[2],a[3]+b[3]*c[3]]:[a[0]+b[0]*c,a[1]+b[1]*c,a[2]+b[2]*c,a[3]+b[3]*c]};RDGE.vec4.scale=function(a,b){return void 0!=b.length&&4<=b.length?[a[0]*b[0],a[1]*b[1],a[2]*b[2],a[3]*b[3]]:[a[0]*b,a[1]*b,a[2]*b,a[3]*b]};
RDGE.vec4.negate=function(a){return[-a[0],-a[1],-a[2],-a[3]]};RDGE.vec4.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]};RDGE.vec4.normalize=function(a){var b=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3]);return 1.0E-4<Math.abs(1-b)?(b=1/b,[a[0]*b,a[1]*b,a[2]*b,a[3]*b]):a};RDGE.vec4.lengthSq=function(a){return a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3]};RDGE.vec4.length=function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3])};
RDGE.vec4.abs=function(a){return[Math.abs(a[0]),Math.abs(a[1]),Math.abs(a[2]),Math.abs(a[3])]};RDGE.vec4.min=function(a,b){return[Math.min(a[0],b[0]),Math.min(a[1],b[1]),Math.min(a[2],b[2]),Math.min(a[3],b[3])]};RDGE.vec4.max=function(a,b){return[Math.max(a[0],b[0]),Math.max(a[1],b[1]),Math.max(a[2],b[2]),Math.min(a[3],b[3])]};RDGE.vec4.clamp=function(a,b,c){return RDGE.vec4.min(c,RDGE.vec4.max(a,b))};RDGE.vec4.equal=function(a,b,c){c||(c=0.0010);return RDGE.vec4.distanceSq(a,b)<c*c};
RDGE.vec4.lerp=function(a,b,c){return[a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c,a[2]+(b[2]-a[2])*c,a[3]+(b[3]-a[3])*c]};RDGE=RDGE||{};RDGE.mat4={};RDGE.mat4.string=function(a){var b;b="{ "+(a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", ");b+=a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", ";b+=a[8]+", "+a[9]+", "+a[10]+", "+a[11]+", ";return b+=a[12]+", "+a[13]+", "+a[14]+", "+a[15]+" }"};
RDGE.mat4.toCSSString=function(a,b){var c=10;b&&(c=b);var d;d="matrix3d("+(a[0].toFixed(10)+", "+a[1].toFixed(10)+", "+a[2].toFixed(10)+", "+a[3].toFixed(10)+", ");d+=a[4].toFixed(10)+", "+a[5].toFixed(10)+", "+a[6].toFixed(10)+", "+a[7].toFixed(10)+", ";d+=a[8].toFixed(10)+", "+a[9].toFixed(10)+", "+a[10].toFixed(10)+", "+a[11].toFixed(10)+", ";return d+=a[12].toFixed(10)*c+", "+(600-a[13].toFixed(10)*c)+", "+a[14].toFixed(10)*c+", "+a[15].toFixed(10)+")"};
RDGE.mat4.verify=function(a){if(void 0==a||void 0==a.length||16>a.length)return!1;for(var b=16;b--;)if("number"!=typeof a[b])return!1;return!0};RDGE.mat4.copy=function(a){return[a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]]};RDGE.mat4.inplace_copy=function(a,b){a[0]=b[0];a[1]=b[1];a[2]=b[2];a[3]=b[3];a[4]=b[4];a[5]=b[5];a[6]=b[6];a[7]=b[7];a[8]=b[8];a[9]=b[9];a[10]=b[10];a[11]=b[11];a[12]=b[12];a[13]=b[13];a[14]=b[14];a[15]=b[15]};
RDGE.mat4.identity=function(){return[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]};RDGE.mat4.zero=function(){return[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]};RDGE.mat4.basis=function(a,b,c,d){return null==d||void 0==d?[a[0],a[1],a[2],0,b[0],b[1],b[2],0,c[0],c[1],c[2],0,0,0,0,1]:[a[0],a[1],a[2],4==a.length?a[3]:0,b[0],b[1],b[2],4==b.length?b[3]:0,c[0],c[1],c[2],4==c.length?c[3]:0,d[0],d[1],d[2],4==d.length?d[3]:1]};
RDGE.mat4.angleAxis=function(a,b){var a=a*(Math.PI/180),a=a/2,c=Math.sin(a),d=Math.cos(a),f=c*c;RDGE.vec3.normalize(b);0>=RDGE.vec3.lengthSq(b)&&(b=[0,0,0,1]);var g=RDGE.mat4.identity();if(1==b[0]&&0==b[1]&&0==b[2])g[5]=1-2*f,g[6]=2*c*d,g[9]=-2*c*d,g[10]=1-2*f;else if(0==b[0]&&1==b[1]&&0==b[2])g[0]=1-2*f,g[2]=-2*c*d,g[8]=2*c*d,g[10]=1-2*f;else if(0==b[0]&&0==b[1]&&1==b[2])g[0]=1-2*f,g[1]=2*c*d,g[4]=-2*c*d,g[5]=1-2*f;else{var h=b[0],l=b[1],m=b[2],n=h*h,p=l*l,o=m*m;g[0]=1-2*(p+o)*f;g[1]=2*(h*l*f+m*
c*d);g[2]=2*(h*m*f-l*c*d);g[4]=2*(l*h*f-m*c*d);g[5]=1-2*(o+n)*f;g[6]=2*(l*m*f+h*c*d);g[8]=2*(m*h*f+l*c*d);g[9]=2*(m*l*f-h*c*d);g[10]=1-2*(n+p)*f}return g};RDGE.mat4.lookAt=function(a,b,c){b=RDGE.vec3.normalize(RDGE.vec3.sub(a,b));1.0E-4>RDGE.vec3.length(b)&&(b=[0,0,1]);var c=RDGE.vec3.normalize(RDGE.vec3.cross(c,b)),d=RDGE.vec3.normalize(RDGE.vec3.cross(b,c)),f=RDGE.mat4.identity();RDGE.mat4.setRow(f,0,c);RDGE.mat4.setRow(f,1,d);RDGE.mat4.setRow(f,2,b);RDGE.mat4.setRow(f,3,a);return f};
RDGE.mat4.frustum=function(a,b,c,d,f,g){var h=b-a,l=d-c,m=g-f,n=2*f,p=RDGE.mat4.zero();p[0]=n/h;p[5]=n/l;p[8]=(b+a)/h;p[9]=(d+c)/l;p[10]=-(g+f)/m;p[11]=-1;p[14]=-(n*g)/m;return p};RDGE.mat4.perspective=function(a,b,c,d){var a=Math.tan(a*Math.PI/360)*c,f=-a;return RDGE.mat4.frustum(b*f,b*a,f,a,c,d)};RDGE.mat4.orthographic=function(a,b,c,d,f,g){var h=(a+b)/(a-b),l=(c+d)/(c-d),m=(g+f)/(g-f),n=RDGE.mat4.zero();n[0]=2/(a-b);n[5]=2/(c-d);n[10]=-2/(g-f);n[12]=h;n[13]=l;n[14]=m;n[15]=1;return n};
RDGE.mat4.mul=function(a,b){var c=a[0],d=a[1],f=a[2],g=a[3],h=a[4],l=a[5],m=a[6],n=a[7],p=a[8],o=a[9],q=a[10],r=a[11],u=a[12],s=a[13],w=a[14],v=a[15],x=b[0],z=b[1],A=b[2],y=b[3],B=b[4],C=b[5],D=b[6],E=b[7],F=b[8],G=b[9],H=b[10],I=b[11],J=b[12],K=b[13],L=b[14],M=b[15];return[c*x+d*B+f*F+g*J,c*z+d*C+f*G+g*K,c*A+d*D+f*H+g*L,c*y+d*E+f*I+g*M,h*x+l*B+m*F+n*J,h*z+l*C+m*G+n*K,h*A+l*D+m*H+n*L,h*y+l*E+m*I+n*M,p*x+o*B+q*F+r*J,p*z+o*C+q*G+r*K,p*A+o*D+q*H+r*L,p*y+o*E+q*I+r*M,u*x+s*B+w*F+v*J,u*z+s*C+w*G+v*K,u*
A+s*D+w*H+v*L,u*y+s*E+w*I+v*M]};RDGE.mat4.mul4x3=function(a,b){var c=a[0],d=a[1],f=a[2],g=a[4],h=a[5],l=a[6],m=a[8],n=a[9],p=a[10],o=a[12],q=a[13],r=a[14],u=b[0],s=b[1],w=b[2],v=b[4],x=b[5],z=b[6],A=b[8],y=b[9],B=b[10];return[c*u+d*v+f*A,c*s+d*x+f*y,c*w+d*z+f*B,0,g*u+h*v+l*A,g*s+h*x+l*y,g*w+h*z+l*B,0,m*u+n*v+p*A,m*s+n*x+p*y,m*w+n*z+p*B,0,o*u+q*v+r*A+b[12],o*s+q*x+r*y+b[13],o*w+q*z+r*B+b[14],1]};RDGE.mat4._det2x2=function(a,b,c,d){return a*d-b*c};
RDGE.mat4._det3x3=function(a,b,c,d,f,g,h,l,m){return a*RDGE.mat4._det2x2(f,g,l,m)-d*RDGE.mat4._det2x2(b,c,l,m)+h*RDGE.mat4._det2x2(b,c,f,g)};RDGE.mat4._det4x4=function(a){var b=a[1],c=a[2],d=a[3],f=a[4],g=a[5],h=a[6],l=a[7],m=a[8],n=a[9],p=a[10],o=a[11],q=a[12],r=a[13],u=a[14],s=a[15];return a[0]*RDGE.mat4._det3x3(g,n,r,h,p,u,l,o,s)-b*RDGE.mat4._det3x3(f,m,q,h,p,u,l,o,s)+c*RDGE.mat4._det3x3(f,m,q,g,n,r,l,o,s)-d*RDGE.mat4._det3x3(f,m,q,g,n,r,h,p,u)};
RDGE.mat4._adjoint=function(a){var b=a[0],c=a[1],d=a[2],f=a[3],g=a[4],h=a[5],l=a[6],m=a[7],n=a[8],p=a[9],o=a[10],q=a[11],r=a[12],u=a[13],s=a[14],a=a[15];return[RDGE.mat4._det3x3(h,p,u,l,o,s,m,q,a),-RDGE.mat4._det3x3(c,p,u,d,o,s,f,q,a),RDGE.mat4._det3x3(c,h,u,d,l,s,f,m,a),-RDGE.mat4._det3x3(c,h,p,d,l,o,f,m,q),-RDGE.mat4._det3x3(g,n,r,l,o,s,m,q,a),RDGE.mat4._det3x3(b,n,r,d,o,s,f,q,a),-RDGE.mat4._det3x3(b,g,r,d,l,s,f,m,a),RDGE.mat4._det3x3(b,g,n,d,l,o,f,m,q),RDGE.mat4._det3x3(g,n,r,h,p,u,m,q,a),-RDGE.mat4._det3x3(b,
n,r,c,p,u,f,q,a),RDGE.mat4._det3x3(b,g,r,c,h,u,f,m,a),-RDGE.mat4._det3x3(b,g,n,c,h,p,f,m,q),-RDGE.mat4._det3x3(g,n,r,h,p,u,l,o,s),RDGE.mat4._det3x3(b,n,r,c,p,u,d,o,s),-RDGE.mat4._det3x3(b,g,r,c,h,u,d,l,s),RDGE.mat4._det3x3(b,g,n,c,h,p,d,l,o)]};RDGE.mat4.inverse=function(a){var b=RDGE.mat4._det4x4(a);if(1.0E-8>Math.abs(b))return null;a=RDGE.mat4._adjoint(a);b=1/b;return[a[0]*b,a[1]*b,a[2]*b,a[3]*b,a[4]*b,a[5]*b,a[6]*b,a[7]*b,a[8]*b,a[9]*b,a[10]*b,a[11]*b,a[12]*b,a[13]*b,a[14]*b,a[15]*b]};
RDGE.mat4.rigidInverse=function(a){out=RDGE.mat4.transpose3x3(a);out[12]=-RDGE.vec3.dot([out[0],out[4],out[8]],[a[12],a[13],a[14]]);out[13]=-RDGE.vec3.dot([out[1],out[5],out[9]],[a[12],a[13],a[14]]);out[14]=-RDGE.vec3.dot([out[2],out[6],out[10]],[a[12],a[13],a[14]]);return out};RDGE.mat4.transpose=function(a){return[a[0],a[4],a[8],a[12],a[1],a[5],a[9],a[13],a[2],a[6],a[10],a[14],a[3],a[7],a[11],a[15]]};
RDGE.mat4.transpose3x3=function(a){return[a[0],a[4],a[8],a[3],a[1],a[5],a[9],a[7],a[2],a[6],a[10],a[11],a[12],a[13],a[14],a[15]]};RDGE.mat4.transformPoint=function(a,b){var c=b[0],d=b[1],f=b[2],g=4<=b.length?b[3]:1;return[a[0]*c+a[4]*d+a[8]*f+a[12]*g,a[1]*c+a[5]*d+a[9]*f+a[13]*g,a[2]*c+a[6]*d+a[10]*f+a[14]*g,a[3]*c+a[7]*d+a[11]*f+a[15]*g]};
RDGE.mat4.transformVector=function(a,b){var a=RDGE.mat4.inverse(a),c=b[0],d=b[1],f=b[2],g=4<=b.length?b[3]:0;return[a[0]*c+a[1]*d+a[2]*f+a[3]*g,a[4]*c+a[5]*d+a[6]*f+a[7]*g,a[8]*c+a[9]*d+a[10]*f+a[11]*g,a[12]*c+a[13]*d+a[14]*f+a[15]*g]};RDGE.mat4.transformPoint4x3=function(a,b){var c=b[0],d=b[1],f=b[2];return[a[0]*c+a[4]*d+a[8]*f+a[12],a[1]*c+a[5]*d+a[9]*f+a[13],a[2]*c+a[6]*d+a[10]*f+a[14],1]};
RDGE.mat4.transformVector4x3=function(a,b){var a=RDGE.mat4.inverse(a),c=b[0],d=b[1],f=b[2];return[a[0]*c+a[1]*d+a[2]*f,a[4]*c+a[5]*d+a[6]*f,a[8]*c+a[9]*d+a[10]*f,0]};RDGE.mat4.getRow=function(a,b){b*=4;return[a[b],a[b+1],a[b+2],a[b+3]]};RDGE.mat4.getCol=function(a,b){return[a[b],a[b+4],a[b+8],a[b+12]]};RDGE.mat4.setRow=function(a,b,c){b*=4;a[b+0]=c[0];a[b+1]=c[1];a[b+2]=c[2];4<=c.length&&(a[b+3]=c[3]);return a};
RDGE.mat4.setCol=function(a,b,c){a[b+0]=c[0];a[b+4]=c[1];a[b+8]=c[2];4<=c.length&&(a[b+12]=c[3]);return a};RDGE.mat4.rotate=function(a,b,c){return RDGE.mat4.mul(a,RDGE.mat4.angleAxis(b,c))};RDGE.mat4.rotateX=function(a,b){return RDGE.mat4.mul(a,RDGE.mat4.angleAxis(b,RDGE.vec3.basisX(a)))};RDGE.mat4.rotateY=function(a,b){return RDGE.mat4.mul(a,RDGE.mat4.angleAxis(b,RDGE.vec3.basisY(a)))};RDGE.mat4.rotateZ=function(a,b){return RDGE.mat4.mul(a,RDGE.mat4.angleAxis(b,RDGE.vec3.basisZ(a)))};
RDGE.mat4.scale=function(a,b){var c=RDGE.mat4.identity();void 0==b.length&&(b=[b,b,b]);c[0]=b[0];c[5]=b[1];c[10]=b[2];return RDGE.mat4.mul(a,c)};RDGE.mat4.scaleX=function(a,b){return RDGE.mat4.scale(a,[b,1,1])};RDGE.mat4.scaleY=function(a,b){return RDGE.mat4.scale(a,[1,b,1])};RDGE.mat4.scaleZ=function(a,b){return RDGE.mat4.scale(a,[1,1,b])};RDGE.mat4.translate=function(a,b){matT=RDGE.mat4.identity();matT[12]=b[0];matT[13]=b[1];matT[14]=b[2];return RDGE.mat4.mul(a,matT)};
RDGE.mat4.translateX=function(a,b){return RDGE.mat4.translate(a,[b,0,0])};RDGE.mat4.translateY=function(a,b){return RDGE.mat4.translate(a,[0,b,0])};RDGE.mat4.translateZ=function(a,b){return RDGE.mat4.translate(a,[0,0,b])};RDGE=RDGE||{};RDGE.quat={};RDGE.quat.string=function(a){return"{ "+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+" }"};RDGE.quat.verify=function(a){return void 0==a||void 0==a.length||4>a.length||"number"!=typeof a[0]||"number"!=typeof a[1]||"number"!=typeof a[2]||"number"!=typeof a[3]?!1:!0};RDGE.quat.identity=function(){return[0,0,0,1]};RDGE.quat.add=function(a,b){return[a[0]+b[0],a[1]+b[1],a[2]+b[2],a[3]+b[3]]};RDGE.quat.sub=function(a,b){return[a[0]-b[0],a[1]-b[1],a[2]-b[2],a[3]-b[3]]};
RDGE.quat.mul=function(a,b){return[a[3]*b[3]-a[0]*b[0]-a[1]*b[1]-a[2]*b[2],a[3]*b[0]+a[0]*b[3]+a[1]*b[2]-a[2]*b[1],a[3]*b[1]-a[0]*b[2]+a[1]*b[3]+a[2]*b[0],a[3]*b[2]+a[0]*b[1]-a[1]*b[0]+a[2]*b[3]]};RDGE.quat.addMul=function(a,b,c){return void 0!=c.length&&4<=c.length?[a[0]+b[0]*c[0],a[1]+b[1]*c[1],a[2]+b[2]*c[2],a[3]+b[3]*c[3]]:[a[0]+b[0]*c,a[1]+b[1]*c,a[2]+b[2]*c,a[3]+b[3]*c]};
RDGE.quat.scale=function(a,b){return void 0!=b.length&&4<=b.length?[a[0]*b[0],a[1]*a[1],a[2]*b[2],a[3]*b[3]]:[a[0]*b,a[1]*b,a[2]*b,a[3]*b]};RDGE.quat.lengthSq=function(a){return a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3]};RDGE.quat.length=function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3])};RDGE.quat.normalize=function(a){var b=Math.sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]+a[3]*a[3]);return 1.0E-4<Math.abs(1-b)?(b=1/b,[a[0]*b,a[1]*b,a[2]*b,a[3]*b]):a};
RDGE.quat.inverse=function(a){var b=RDGE.vec4.lengthSq(a);return 1.0E-5<b?(b=1/b,[a[0]*-b,a[1]*-b,a[2]*-b,a[3]]):a};RDGE.quat.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]};RDGE.quat.applyRotation=function(a,b){return RDGE.mat4.transformPoint(RDGE.quat.toMatrix(a),b)};RDGE.quat.lerp=function(a,b,c){return RDGE.quat.normalize([a[0]+(b[0]-a[0])*c,a[1]+(b[1]-a[1])*c,a[2]+(b[2]-a[2])*c,a[3]+(b[3]-a[3])*c])};
RDGE.quat.slerp=function(a,b,c){var d=RDGE.quat.dot(a,b);if(0.9<=d)return RDGE.quat.lerp(a,b,c);var f=Math.sqrt(Math.abs(1-d*d));if(0.0010>f)return a;var d=0>d?-1:1,g=Math.asin(f),h=1/f,f=Math.sin((1-c)*g)*h,c=Math.sin(c*g)*h*d;RDGE.quat.scale(a,f);RDGE.quat.scale(b,c);return RDGE.quat.normalize(RDGE.quat.add(a,b))};
RDGE.quat.toMatrix=function(a){var b=2*a[0],c=2*a[1],d=2*a[2],f=b*a[3],g=c*a[3],h=d*a[3],b=b*a[0],l=c*a[0],m=d*a[0],c=c*a[1],n=d*a[1],a=d*a[2];return[1-(c+a),l+h,m-g,0,l-h,1-(b+a),n+f,0,m+g,n-f,1-(b+c),0,0,0,0,1]};RDGE=RDGE||{};
RDGE.objectManager=function(){this.guidCounter=0;this.objects=[];this.numObjects=0;this.freelist=[];this.reset=function(){this.objects=[];this.freelist=[];this.guidCounter=0};this.validHandle=function(a){return-1!=this.handleToIndex(a)};this.handleToIndex=function(a){var b=a>>16&65535;return null!=this.objects[b]&&a==this.objects[b].handle?b:-1};this.handleToObject=function(a){a=this.handleToIndex(a);return-1!=a?this.objects[a]:null};this.addObject=function(a){var b=this.objects.length;0<this.freelist.length&&
(b=this.freelist.pop());65535<=++this.guidCounter&&(this.guidCounter=1);a.handle=b<<16|++this.guidCounter;this.objects[b]=a;return a.handle};this.removeObject=function(a){a=this.handleToIndex(a);if(-1!=a){if(void 0!=this.objects[a].onremove)this.objects[a].onremove();this.objects[a]=null;this.freelist.push(a)}}};RDGE=RDGE||{};
RDGE.rdgeGlobalParameters={u_projMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_mvMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_invMvMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_normalMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_worldMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_viewMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_invViewMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_invWorldMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_inv_viewport_width:{type:"float",data:[1]},
u_inv_viewport_height:{type:"float",data:[1]},u_lightPos:{type:"vec3",data:[-20,50,20]},u_lightDiff:{type:"vec4",data:[0.8,0.8,0.8,1]},u_lightAmb:{type:"vec4",data:[1,1,1,1]},rdge_lights:{u_light0Pos:{type:"vec3",data:[-20,50,20]},u_light0Diff:{type:"vec4",data:[0.8,0.8,0.8,1]},u_light0Amb:{type:"vec4",data:[8.0E-4,8.0E-4,8.0E-4,1]},u_light0Spec:{type:"vec4",data:[1,1,1,1]},u_light1Pos:{type:"vec3",data:[0,0,0]},u_light1Diff:{type:"vec4",data:[0,0,0,0]},u_light1Amb:{type:"vec4",data:[0.5,0.5,0.5,
1]},u_light1Spec:{type:"vec4",data:[1,1,1,1]},u_light2Pos:{type:"vec3",data:[0,0,0]},u_light2Diff:{type:"vec4",data:[0,0,0,1]},u_light2Amb:{type:"vec4",data:[0.5,0.5,0.5,1]},u_light2Spec:{type:"vec4",data:[1,1,1,1]},u_light3Pos:{type:"vec3",data:[0,0,0]},u_light3Diff:{type:"vec4",data:[0.8,0.8,0.8,1]},u_light3Amb:{type:"vec4",data:[0.5,0.5,0.5,1]},u_light3Spec:{type:"vec4",data:[1,1,1,1]}},colMap:{type:"tex2d",data:"assets/images/white.png"},u_matAmbient:{type:"vec4",data:[1,1,1,1]},u_matDiffuse:{type:"vec4",
data:[1,1,1,1]},u_matSpecular:{type:"vec4",data:[1,1,1,1]},u_matShininess:{type:"float",data:[128]},u_matEmission:{type:"float",data:[0,0,0,1]},u_frustumFarZ:{type:"float",data:[1E3]},u_shadowLightWorld:{type:"mat4",data:RDGE.mat4.identity()},u_shadowBiasMatrix:{type:"mat4",data:RDGE.mat4.identity()},u_vShadowLight:{type:"mat4",data:RDGE.mat4.identity()},u_shadowBPV:{type:"mat4",data:RDGE.mat4.identity()},u_farZ:{type:"float",data:[1E3]},u_shadowLightFarZ:{type:"float",data:[1E3]},u_cameraFTR:{type:"vec3",
data:[0,0,0]}};RDGE=RDGE||{};
RDGE.rdgeConstants=function(){return{colorBuffer:16384,depthBuffer:256,stencilBuffer:1024,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,VS_ELEMENT_FLOAT4:4,VS_ELEMENT_POS:3,VS_ELEMENT_NORM:3,VS_ELEMENT_FLOAT3:3,VS_ELEMENT_FLOAT2:2,VS_ELEMENT_UV:2,VS_ELEMENT_FLOAT:1,MAX_ELEM_TYPES:7,BUFFER_STATIC:35040,BUFFER_DYNAMIC:35044,BUFFER_STREAM:35048,MAX_MATERIAL_LIGHTS:4,categoryEnumeration:{BACKGROUND:0,
OPAQUE:1,TRANSPARENT:2,ADDITIVE:3,TRANSLUCENT:4,FOREGROUND:5,MAX_CAT:6},nodeType:{TRNODE:0,MESHNODE:1,MATNODE:2,LIGHTNODE:3}}}();
RDGE._renderer=function(a){try{if(this.ctx=a.getContext("experimental-webgl",{preserveDrawingBuffer:!0}),this.ctx||(this.ctx=a.getContext("webgl",{preserveDrawingBuffer:!0})),this.ctx||(this.ctx=a.getContext("webkit-3d",{preserveDrawingBuffer:!0})),!this.ctx)this.ctx=a.getContext("moz-webgl",{preserveDrawingBuffer:!0})}catch(b){}if(!this.ctx)return window.console.log("Could not create GL context"),null;this.ctx.viewport(0,0,a.width,a.height);this.console="console"in window?window.console:{log:function(){}};
this.ctx.clearColor(1,0,0,1);this.clearColor=[1,0,0,1];this.clearFlags=this.ctx.COLOR_BUFFER_BIT|this.ctx.DEPTH_BUFFER_BIT;this.colorBuffer=this.ctx.COLOR_BUFFER_BIT;this.depthBuffer=this.ctx.DEPTH_BUFFER_BIT;this.stencilBuffer=this.ctx.STENCIL_BUFFER_BIT;this.BUFFER_STATIC=0;this.BUFFER_DYNAMIC=1;this.BUFFER_STREAM=2;this.POINTS=0;this.LINES=1;this.LINE_LOOP=2;this.LINE_STRIP=3;this.TRIANGLES=4;this.TRIANGLE_STRIP=5;this.TRIANGLE_FAN=6;this.BYTE=5120;this.UNSIGNED_BYTE=5121;this.SHORT=5122;this.UNSIGNED_SHORT=
5123;this.INT=5124;this.UNSIGNED_INT=5125;this.FLOAT=5126;this.VS_ELEMENT_FLOAT4=4;this.VS_ELEMENT_FLOAT3=this.VS_ELEMENT_NORM=this.VS_ELEMENT_POS=3;this.VS_ELEMENT_UV=this.VS_ELEMENT_FLOAT2=2;this.VS_ELEMENT_FLOAT=1;this.MAX_ELEM_TYPES=7;this.BUFFER_STATIC=35040;this.BUFFER_DYNAMIC=35044;this.BUFFER_STREAM=35048;this.MAX_MATERIAL_LIGHTS=4;this.usedTextureUnits=5;this.vpY=this.vpX=0;this.vpWidth=a.width;this.vpHeight=a.height;this.cameraMan=new RDGE.cameraManager;this.buffers=[];this.cullBackFace=
function(){this.ctx.cullFace(this.ctx.Back)};this.cullFrontFace=function(){this.ctx.cullFace(this.ctx.FRONT)};this.disableCulling=function(){this.ctx.disable(this.ctx.CULL_FACE)};this.enableCulling=function(){this.ctx.enable(this.ctx.CULL_FACE)};this.enablePolyOffsetFill=function(){this.ctx.enable(this.ctx.POLYGON_OFFSET_FILL)};this.disablePolyOffsetFill=function(){this.ctx.enable(this.ctx.POLYGON_OFFSET_FILL)};this.enablePointSprites=function(){};this.disablePointSprites=function(){};this.setClearColor=
function(a){this.clearColor=a.slice();this.ctx.clearColor(a[0],a[1],a[2],a[3])};this.setClearFlags=function(a){this.clearFlags=a};this._clear=function(){this.ctx.clear(this.clearFlags)};this.clear=function(a){this.ctx.clear(a)};this.flush=function(){this.ctx.flush()};this.setViewPort=function(a,b,f,g){this.vpX=a;this.vpY=b;this.vpWidth=f;this.vpHeight=g;this.ctx.viewport(this.vpX,this.vpY,this.vpWidth,this.vpHeight)};this.cameraManager=function(){return this.cameraMan};this.textureMap=[];this.rttMap=
[];this.getTextureByName=function(a,b,f){var g=a.split(".")[1],g=g?"":".png",h=this.textureMap[a];void 0===h?(a=RDGE.globals.engine.remapAssetFolder(a),h=this.createTexture(a+g,b,f),this.textureMap[a]=h,h.lookUpName=a,h.previouslyReferenced=!1):h.previouslyReferenced=!0;return h};this.unloadedTextureCount=0;_texparams=function(a,b){this.wrap=a;this.mips=b};this.createTexture=function(a,b,f){var g=this.ctx.createTexture();this.unloadedTextureCount++;void 0===b&&(b="CLAMP");void 0===f&&(f=!0);g&&(g.image=
new Image,g.image.src=a,g.image.context=RDGE.globals.engine.getContext(),g.texparams=new _texparams(b,f),g.image.onload=function(){this.context.ctxStateManager.RDGEInitState.loadTexture(g);this.context.renderer.unloadedTextureCount--;g.callback&&g.callback(g);0>this.context.renderer.unloadedTextureCount&&console.log("more textures loaded then created...")},g.image.onerror=function(){this.context.renderer.unloadedTextureCount--;g.callback&&g.callback(g);0>this.context.renderer.unloadedTextureCount&&
console.log("more textures loaded then created...")});return g};this.commitTexture=function(a){this.ctx.bindTexture(this.ctx.TEXTURE_2D,a);this.ctx.texImage2D(this.ctx.TEXTURE_2D,0,this.ctx.RGBA,this.ctx.RGBA,this.ctx.UNSIGNED_BYTE,a.image);a.texparams.mips&&this.ctx.generateMipmap(this.ctx.TEXTURE_2D);this.ctx.texParameteri(this.ctx.TEXTURE_2D,this.ctx.TEXTURE_MAG_FILTER,this.ctx.LINEAR);this.ctx.texParameteri(this.ctx.TEXTURE_2D,this.ctx.TEXTURE_MIN_FILTER,a.texparams.mips?this.ctx.LINEAR_MIPMAP_LINEAR:
this.ctx.LINEAR);this.ctx.texParameteri(this.ctx.TEXTURE_2D,this.ctx.TEXTURE_WRAP_S,"REPEAT"===a.texparams.wrap?this.ctx.REPEAT:this.ctx.CLAMP_TO_EDGE);this.ctx.texParameteri(this.ctx.TEXTURE_2D,this.ctx.TEXTURE_WRAP_T,"REPEAT"===a.texparams.wrap?this.ctx.REPEAT:this.ctx.CLAMP_TO_EDGE);this.ctx.bindTexture(this.ctx.TEXTURE_2D,null)};this.verify=function(a){var b=this.ctx.getError();0!=b&&window.console.log("GLError ( "+a+") : "+b)};this.createRenderTargetTexture=function(a,b,f,g){var h=this.ctx,l=
h.createFramebuffer();h.bindFramebuffer(h.FRAMEBUFFER,l);l.width=b;l.height=f;b=h.createTexture();h.bindTexture(h.TEXTURE_2D,b);try{h.texImage2D(h.TEXTURE_2D,0,h.RGBA,l.width,l.height,0,h.RGBA,h.UNSIGNED_BYTE,null)}catch(m){f=new WebctxUnsignedByteArray(4*l.width*l.height),h.texImage2D(h.TEXTURE_2D,0,h.RGBA,l.width,l.height,0,h.RGBA,h.UNSIGNED_BYTE,f)}h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MAG_FILTER,h.LINEAR);h.texParameteri(h.TEXTURE_2D,h.TEXTURE_MIN_FILTER,g?h.LINEAR_MIPMAP_NEAREST:h.LINEAR);h.texParameteri(h.TEXTURE_2D,
h.TEXTURE_WRAP_S,h.CLAMP_TO_EDGE);h.texParameteri(h.TEXTURE_2D,h.TEXTURE_WRAP_T,h.CLAMP_TO_EDGE);g&&h.generateMipmap(h.TEXTURE_2D);g=h.createRenderbuffer();h.bindRenderbuffer(h.RENDERBUFFER,g);h.renderbufferStorage(h.RENDERBUFFER,h.DEPTH_COMPONENT16,l.width,l.height);h.getError(h.bindFramebuffer(h.FRAMEBUFFER,l));h.getError(h.bindRenderbuffer(h.RENDERBUFFER,g));h.getError(h.renderbufferStorage(h.RENDERBUFFER,h.DEPTH_COMPONENT16,l.width,l.height));h.bindRenderbuffer(h.RENDERBUFFER,null);h.getError(h.framebufferTexture2D(h.FRAMEBUFFER,
h.COLOR_ATTACHMENT0,h.TEXTURE_2D,b,0));h.getError(h.framebufferRenderbuffer(h.FRAMEBUFFER,h.DEPTH_ATTACHMENT,h.RENDERBUFFER,g));h.bindFramebuffer(h.FRAMEBUFFER,null);h.bindTexture(h.TEXTURE_2D,null);h.bindRenderbuffer(h.RENDERBUFFER,null);h.bindFramebuffer(h.FRAMEBUFFER,null);b.id="RT_"+RDGE.nodeIdGen.getId();b.frameBuffer=l;this.textureMap[a]&&window.console.log("Notification: render target: "+a+" has overwritten an existing render target");return this.textureMap[a]=b};this.defaultShaderDefintion=
{shaders:{defaultVShader:"assets/shaders/test_vshader.glsl",defaultFShader:"assets/shaders/test_fshader.glsl"},techniques:{defaultTechnique:[{vshader:"defaultVShader",fshader:"defaultFShader",attributes:{vert:{type:"vec3"},normal:{type:"vec3"},texcoord:{type:"vec2"}},params:{},states:{depthEnable:!0,blendEnable:!1,culling:!0,cullFace:"BACK"}}]}}};
RDGE.rdgeDefaultShaderDefintion={shaders:{defaultVShader:"assets/shaders/Basic.vert.glsl",defaultFShader:"assets/shaders/Basic.frag.glsl"},techniques:{defaultTechnique:[{vshader:"defaultVShader",fshader:"defaultFShader",attributes:{vert:{type:"vec3"},normal:{type:"vec3"},texcoord:{type:"vec2"}},params:{},states:{depthEnable:!0,blendEnable:!1,culling:!0,cullFace:"BACK"}}]}};
RDGE.rdgePrimitiveDefinition=function(){this.type=RDGE.rdgeConstants.TRIANGLE_STRIP;this.vertexDefinition={};this.bufferStreams=[];this.streamUsage=[];this.indexUsage=RDGE.rdgeConstants.BUFFER_STREAM;this.indexBuffer=[];this.setCount=0;this.indexOffsets=[];this.indexCount=this.triCount=this.posCount=0;this.indexElementSize=RDGE.rdgeConstants.UNSIGNED_SHORT;this.bufferHandles=[];this.buffersID=-1;this.indexHandle=null;this.useDoubleBuffer=!1;this.frontBufferIndex=this.doubleBufferOffset=0;this.update=
function(a){if(!this.bufferStreams[a])return null;this.bufferStreams[a].dirty=!0;return this.bufferStreams[a]};this.flip=function(a){if(!0===this.useDoubleBuffer)for(var b=0,c=this.bufferStreams.length;b<c;++b)this.bufferStreams[b].dirty&&(this.bufferStreams[b].dirty=!1,a.updateBuffer(a.buffers[this.buffersID][this.frontBufferIndex*this.doubleBufferOffset+b],this.bufferStreams[b],this.streamUsage[b]),this.frontBufferIndex=1-this.frontBufferIndex)}};RDGE._renderer.prototype._rendererID=0;
RDGE._renderer.prototype.getBufferID=function(){return RDGE._renderer.prototype._rendererID++};RDGE._renderer.prototype.createIndexBufferUINT16=function(a,b){var c=this.ctx.createBuffer();c.type=a.type;this.ctx.bindBuffer(this.ctx.ELEMENT_ARRAY_BUFFER,c);this.ctx.bufferData(this.ctx.ELEMENT_ARRAY_BUFFER,"number"==typeof k?a:new Uint16Array(a),b);return c};
RDGE._renderer.prototype.createIndexBufferUINT8=function(a,b){var c=this.ctx.createBuffer();c.type=a.type;this.ctx.bindBuffer(this.ctx.ELEMENT_ARRAY_BUFFER,c);this.ctx.bufferData(this.ctx.ELEMENT_ARRAY_BUFFER,"number"==typeof k?a:new Uint8Array(a),b);return c};RDGE._renderer.prototype.createBufferFLOAT32=function(a,b){var c=this.ctx.createBuffer();c.type=a.type;this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,c);this.ctx.bufferData(this.ctx.ARRAY_BUFFER,"number"==typeof k?a:new Float32Array(a),b);return c};
RDGE._renderer.prototype.createBufferINT32=function(a,b){var c=this.ctx.createBuffer();c.type=a.type;this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,c);this.ctx.bufferData(this.ctx.ARRAY_BUFFER,"number"==typeof k?a:new Int32Array(a),b);return c};RDGE._renderer.prototype.createBufferINT16=function(a,b){var c=this.ctx.createBuffer();c.type=a.type;this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,c);this.ctx.bufferData(this.ctx.ARRAY_BUFFER,"number"==typeof k?a:new Int16Array(a),b);return c};
RDGE._renderer.prototype.updateBuffer=function(a,b,c,d){this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,a);c===RDGE.rdgeConstants.BUFFER_DYNAMIC?this.ctx.bufferSubData(this.ctx.ARRAY_BUFFER,d||0,new Float32Array(b)):this.ctx.bufferData(this.ctx.ARRAY_BUFFER,new Float32Array(b),c)};RDGE._renderer.prototype.createPrimitive=function(a){if(a.built){if(this.buffers[a.buffersID])return}else a.buffersID=this.getBufferID(),a.built=!0;this.buffers[a.buffersID]=[];this.buffers[a.buffersID].ctxId=this.id;this.updatePrimitive(a)};
RDGE._renderer.prototype.updatePrimitive=function(a){if(a.built){var b=[],c;for(c in a.vertexDefinition){var d=a.vertexDefinition[c];if(!(-1<b.indexOf(d.bufferIndex))&&(b.push(d.bufferIndex),d.debugName=c+" buffer",d.type==this.VS_ELEMENT_POS&&(a.posCount=a.bufferStreams[d.bufferIndex].length,a.positions=a.bufferStreams[d.bufferIndex]),void 0==this.buffers[a.buffersID][d.bufferIndex]?(a.bufferStreams[d.bufferIndex].type=c+" PrimaryBuffer",a.forceVertexCount?(this.buffers[a.buffersID][d.bufferIndex]=
this.createBufferFLOAT32(4*a.forceVertexCount,d.bufferUsage),this.ctx.bufferSubData(this.ctx.ARRAY_BUFFER,0,new Float32Array(a.bufferStreams[d.bufferIndex]),d.bufferUsage)):this.buffers[a.buffersID][d.bufferIndex]=this.createBufferFLOAT32(a.bufferStreams[d.bufferIndex],d.bufferUsage)):(this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,this.buffers[a.buffersID][d.bufferIndex]),this.ctx.bufferSubData(this.ctx.ARRAY_BUFFER,0,new Float32Array(a.bufferStreams[d.bufferIndex]),d.bufferUsage)),!0===a.useDoubleBuffer))a.doubleBufferOffset=
a.bufferStreams.length,a.bufferStreams[d.bufferIndex].type=c+" SecondaryBuffer",void 0==this.buffers[a.buffersID][a.doubleBufferOffset+d.bufferIndex]?a.forceVertexCount?(this.buffers[a.buffersID][a.doubleBufferOffset+d.bufferIndex]=this.createBufferFLOAT32(4*a.prim.forceVertexCount,d.bufferUsage),this.ctx.bufferSubData(this.ctx.ARRAY_BUFFER,0,new Float32Array(a.bufferStreams[d.bufferIndex]),d.bufferUsage)):this.buffers[a.buffersID][a.doubleBufferOffset+d.bufferIndex]=this.createBufferFLOAT32(a.bufferStreams[d.bufferIndex],
d.bufferUsage):(this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,this.buffers[a.buffersID][a.doubleBufferOffset+d.bufferIndex]),this.ctx.bufferSubData(this.ctx.ARRAY_BUFFER,0,new Float32Array(a.bufferStreams[d.bufferIndex]),d.bufferUsage))}0<a.indexBuffer.length?(b=a.indexBuffer.length,a.indexBuffer.debugName="index Buffer",void 0==this.buffers[a.buffersID].indexHandle?a.forceIndexCount?(this.buffers[a.buffersID].indexHandle=this.createIndexBufferUINT16(2*a.forceIndexCount,a.indexUsage),this.ctx.bufferSubData(this.ctx.ELEMENT_ARRAY_BUFFER,
0,new Float32Array(a.indexBuffer),a.indexUsage)):this.buffers[a.buffersID].indexHandle=this.createIndexBufferUINT16(a.indexBuffer,a.indexUsage):(this.ctx.bindBuffer(this.ctx.ELEMENT_ARRAY_BUFFER,this.buffers[a.buffersID].indexHandle),this.ctx.bufferSubData(this.ctx.ELEMENT_ARRAY_BUFFER,0,new Float32Array(a.indexBuffer),a.indexUsage)),a.indexCount=b,a.triCount=b/3):a.triCount=a.posCount/3}else this.createPrimitive(a)};
RDGE._renderer.prototype.deletePrimitive=function(a){var b=this.buffers[a.buffersID];if(b){var c=this;b.forEach(function(a){c.ctx.deleteBuffer(a)});delete this.buffers[a.buffersID]}};RDGE._renderer.prototype.getPrimitiveBuffer=function(a,b){return this.buffers[a.buffersID][b]};RDGE._renderer.prototype.drawPrimitive=function(a,b,c){a.indexCount?this.drawIndexedPrimitive(a,b,c):this.drawNonIndexedPrimitive(a,b,c);!0===a.useDoubleBuffer&&a.flip(this)};
RDGE._renderer.prototype.drawIndexedPrimitive=function(a,b,c){var d=b=0,f=a.buffersID,g="",h=c.length,l=0,m=a.frontBufferIndex*a.doubleBufferOffset;for(RDGE.globals.engine.getContext();l<h;++l)d=c[l].loc,g=c[l].name,a.vertexDefinition[g]&&(b=a.vertexDefinition[g].bufferIndex,this.ctx.enableVertexAttribArray(d),this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,this.buffers[f][m+b]),this.ctx.vertexAttribPointer(d,a.vertexDefinition[g].type,this.FLOAT,!1,0,0));this.ctx.bindBuffer(this.ctx.ELEMENT_ARRAY_BUFFER,
this.buffers[f].indexHandle);this.ctx.drawElements(a.type,a.indexCount,a.indexElementSize,0);for(l=0;l<h;++l)this.ctx.disableVertexAttribArray(c[l].loc)};
RDGE._renderer.prototype.drawIndexedPrimitiveWireFrame=function(a,b,c){for(var d=b=0,f=a.buffersID,g="",h=c.length,l=0,m=a.frontBufferIndex*a.doubleBufferOffset;l<h;++l)d=c[l].loc,g=c[l].name,a.vertexDefinition[g]&&(b=a.vertexDefinition[g].bufferIndex,this.ctx.enableVertexAttribArray(d),this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,this.buffers[f][m+b]),this.ctx.vertexAttribPointer(d,a.vertexDefinition[g].type,this.FLOAT,!1,0,0));this.ctx.bindBuffer(this.ctx.ELEMENT_ARRAY_BUFFER,this.buffers[f].indexHandle);
this.ctx.drawElements(this.LINE_LOOP,a.indexCount,a.indexElementSize,0);for(l=0;l<h;++l)this.ctx.disableVertexAttribArray(c[l].loc)};
RDGE._renderer.prototype.drawNonIndexedPrimitive=function(a,b,c){for(var d=b=0,f=a.buffersID,g="",h=c.length,l=0,m=a.frontBufferIndex*a.doubleBufferOffset;l<h;++l)d=c[l].loc,g=c[l].name,b=a.vertexDefinition[g].bufferIndex,a.vertexDefinition[g]&&(this.ctx.enableVertexAttribArray(d),this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER,this.buffers[f][m+b]),this.ctx.vertexAttribPointer(d,a.vertexDefinition[g].type,this.FLOAT,!1,0,0));this.ctx.drawArrays(a.type,0,a.triCount);for(l=0;l<h;++l)this.ctx.disableVertexAttribArray(c[l].loc)};
RDGE._renderer.prototype.drawIndexedPrimitiveSet=function(a){window.alert("drawIndexedPrimitiveSet is not implemented");for(var b=0;b<a.setCount;++b)this.ctx.drawElements(a.type[b],mesh.numIndices[b],a.indexElementSize[b],a.indexOffsets[b])};RDGE=RDGE||{};RDGE.renderUtils=RDGE.renderUtils||{};
RDGE.renderUtils.createBox=function(){var a=RDGE.globals.engine.getContext().renderer,b=new RDGE.rdgePrimitiveDefinition;b.vertexDefinition={vert:{type:RDGE.rdgeConstants.VS_ELEMENT_POS,bufferIndex:0,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},a_pos:{type:RDGE.rdgeConstants.VS_ELEMENT_POS,bufferIndex:0,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},normal:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT3,bufferIndex:1,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},a_nrm:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT3,
bufferIndex:1,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},texcoord:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT2,bufferIndex:2,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},a_uv:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT2,bufferIndex:2,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC}};b.bufferStreams=[[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,1,-1,-1,1,-1,-1,1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,1,-1,1,1,-1],[0,0,1,0,0,1,0,0,1,0,
0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],[1,1,0,1,0,0,1,0,0,1,0,0,1,0,1,1,1,0,1,1,0,1,0,0,1,1,0,1,0,0,1,0,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1]];b.streamUsage=[RDGE.rdgeConstants.BUFFER_STATIC,RDGE.rdgeConstants.BUFFER_STATIC,RDGE.rdgeConstants.BUFFER_STATIC];b.indexUsage=RDGE.rdgeConstants.BUFFER_STREAM;b.indexBuffer=[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,
23];b.type=RDGE.rdgeConstants.TRIANGLES;a.createPrimitive(b);return b};
RDGE.renderUtils.makeSphere=function(a,b,c,d){for(var f=[],g=[],h=[],l=[],m=0;m<=c;++m)for(var n=0;n<=d;++n){var p=m*Math.PI/c,o=2*n*Math.PI/d,q=Math.sin(p),r=Math.sin(o),p=Math.cos(p),o=Math.cos(o)*q,q=r*q,r=1-n/d,u=m/c;g.push(o);g.push(p);g.push(q);h.push(r);h.push(u);f.push(b*o);f.push(b*p);f.push(b*q)}for(m=0;m<c;++m)for(n=0;n<d;++n)b=m*(d+1)+n,o=b+d+1,l.push(b),l.push(o),l.push(b+1),l.push(o),l.push(o+1),l.push(b+1);c={};c.normalObject=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,c.normalObject);
a.bufferData(a.ARRAY_BUFFER,new Float32Array(g),a.STATIC_DRAW);c.texCoordObject=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,c.texCoordObject);a.bufferData(a.ARRAY_BUFFER,new Float32Array(h),a.STATIC_DRAW);c.vertexObject=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,c.vertexObject);a.bufferData(a.ARRAY_BUFFER,new Float32Array(f),a.STATIC_DRAW);c.numIndices=l.length;c.indexObject=a.createBuffer();a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,c.indexObject);a.bufferData(a.ELEMENT_ARRAY_BUFFER,new Uint16Array(l),
a.STREAM_DRAW);return c};
RDGE.renderUtils.createPlane=function(a,b,c,d,f,g,h){for(var l=RDGE.globals.engine.getContext().renderer,m=Array(3*a*b),n=Array(3*a*b),p=Array(2*a*b),o=Array(a*b),q=0,r=0,u=0;u<b;++u)for(var s=0;s<a;++s)m[q]=s*c-0.5*(a-1)*c,m[q+1]=0,m[q+2]=u*d-0.5*(b-1)*d,n[q]=h[0],n[q+1]=h[1],n[q+2]=h[2],p[r]=s/a*f,p[r+1]=u/b*g,q+=3,r+=2;for(u=c=0;u<b;++u)for(s=0;s<a;++s)o[c+2]=u*a+s,o[c+1]=u*a+(s+1),o[c]=(u+1)*a+s,o[c+5]=(u+1)*a+s,o[c+4]=u*a+(s+1),o[c+3]=(u+1)*a+(s+1),c+=6;a=new RDGE.rdgePrimitiveDefinition;a.vertexDefinition=
{vert:{type:RDGE.rdgeConstants.VS_ELEMENT_POS,bufferIndex:0,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},a_pos:{type:RDGE.rdgeConstants.VS_ELEMENT_POS,bufferIndex:0,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},normal:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT3,bufferIndex:1,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},a_nrm:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT3,bufferIndex:1,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},texcoord:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT2,bufferIndex:2,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},
a_uv:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT2,bufferIndex:2,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC}};a.bufferStreams=[m,n,p];a.streamUsage=[RDGE.rdgeConstants.BUFFER_STATIC,RDGE.rdgeConstants.BUFFER_STATIC,RDGE.rdgeConstants.BUFFER_STATIC];a.indexUsage=RDGE.rdgeConstants.BUFFER_STREAM;a.indexBuffer=o;a.type=RDGE.rdgeConstants.TRIANGLES;l.createPrimitive(a);return a};
RDGE.renderUtils.createCubeVolume=function(a,b,c,d,f,g,h){for(var l=RDGE.globals.engine.getContext().renderer,m=Array(3*a*c*b),n=Array(a*c*b),p=0,o=0,q=0;q<b;++q)for(var r=0;r<c;++r)for(var u=0;u<a;++u)m[p]=u*d-0.5*(a-1)*d,m[p+1]=q*f-0.5*(b-1)*f,m[p+2]=r*g-0.5*(c-1)*g,p+=3,n.push(o++);h&&m.slice();a=new RDGE.rdgePrimitiveDefinition;a.vertexDefinition={a_pos:{type:RDGE.rdgeConstants.VS_ELEMENT_POS,bufferIndex:0,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC}};a.bufferStreams=[m];a.streamUsage=[RDGE.rdgeConstants.BUFFER_DYNAMIC];
a.indexUsage=RDGE.rdgeConstants.BUFFER_STREAM;a.indexBuffer=n;a.type=RDGE.rdgeConstants.POINTS;a.useDoubleBuffer=!0;l.createPrimitive(a);return a};
RDGE.renderUtils.createScreenAlignedQuad=function(){var a=RDGE.globals.engine.getContext().renderer,b=new RDGE.rdgePrimitiveDefinition;b.vertexDefinition={vert:{type:RDGE.rdgeConstants.VS_ELEMENT_POS,bufferIndex:0,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},a_pos:{type:RDGE.rdgeConstants.VS_ELEMENT_POS,bufferIndex:0,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},texcoord:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT2,bufferIndex:1,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC},a_uv:{type:RDGE.rdgeConstants.VS_ELEMENT_FLOAT2,
bufferIndex:1,bufferUsage:RDGE.rdgeConstants.BUFFER_STATIC}};b.bufferStreams=[[-1,1,0,1,1,0,-1,-1,0,-1,-1,0,1,1,0,1,-1,0],[0,0,0,1,1,1,1,1,1,0,0,0]];b.streamUsage=[RDGE.rdgeConstants.BUFFER_STATIC,RDGE.rdgeConstants.BUFFER_STATIC];b.type=RDGE.rdgeConstants.TRIANGLES;a.createPrimitive(b);return b};RDGE=RDGE||{};RDGE.bindMap={};RDGE.bindMap["int"]=function(a,b,c){a.uniform1iv(b,c)};RDGE.bindMap["float"]=function(a,b,c){a.uniform1fv(b,c)};RDGE.bindMap.vec2=function(a,b,c){a.uniform2fv(b,c)};RDGE.bindMap.vec3=function(a,b,c){a.uniform3fv(b,c)};RDGE.bindMap.vec4=function(a,b,c){a.uniform4fv(b,c)};RDGE.bindMap.mat3=function(a,b,c){a.uniformMatrix3fv(b,!1,c)};RDGE.bindMap.mat4=function(a,b,c){a.uniformMatrix4fv(b,!1,c);RDGE.globals.engine.getContext().debug.mat4CallCount++};
RDGE.bindMap.tex2d=function(a,b,c){a.activeTexture(a.TEXTURE0+c[0]);a.bindTexture(a.TEXTURE_2D,c[1]);a.uniform1iv(b,[c[0]])};RDGE.bindMap.texCube=function(a,b,c){a.activeTexture(a.TEXTURE0+c[0]);a.bindTexture(a.TEXTURE_CUBE_MAP,c[1]);a.uniform1iv(b,[c[0]])};RDGE.lightDataMap=[function(a,b,c){a.uniform3fv(b,c.position)},function(a,b,c){a.uniform4fv(b,c.lightDiffuse)},function(a,b,c){a.uniform4fv(b,c.lightAmbient)},function(a,b,c){a.uniform4fv(b,c.lightSpecular)}];RDGE.paramTypeNameMapping=null;
RDGE.jshader=function(a){this.name=a;this.def=null;this.technique={};this.params={};this.compiledShaders={};this.resetRS=!1;this.currentPass=0;this.type_jshader={};this.global={};this.renderer=RDGE.globals.engine.getContext().renderer;this.ctx=this.renderer.ctx;void 0!=a&&null!=a&&(request=new XMLHttpRequest,request.open("GET",a,!1),request.send(null),this.def=JSON.parse(request.responseText));RDGE.paramTypeNameMapping||(a=this.ctx,RDGE.paramTypeNameMapping={},RDGE.paramTypeNameMapping[a.BOOL]="bool",
RDGE.paramTypeNameMapping[a.INT]="int",RDGE.paramTypeNameMapping[a.FLOAT]="float",RDGE.paramTypeNameMapping[a.FLOAT_VEC2]="vec2",RDGE.paramTypeNameMapping[a.FLOAT_VEC3]="vec3",RDGE.paramTypeNameMapping[a.FLOAT_VEC4]="vec4",RDGE.paramTypeNameMapping[a.INT_VEC2]="vec2",RDGE.paramTypeNameMapping[a.INT_VEC3]="vec3",RDGE.paramTypeNameMapping[a.INT_VEC4]="vec4",RDGE.paramTypeNameMapping[a.BOOL_VEC2]="vec2",RDGE.paramTypeNameMapping[a.BOOL_VEC3]="vec3",RDGE.paramTypeNameMapping[a.BOOL_VEC4]="vec4",RDGE.paramTypeNameMapping[a.FLOAT_MAT2]=
"mat2",RDGE.paramTypeNameMapping[a.FLOAT_MAT3]="mat3",RDGE.paramTypeNameMapping[a.FLOAT_MAT4]="mat4",RDGE.paramTypeNameMapping[a.SAMPLER_2D]="tex2d",RDGE.paramTypeNameMapping[a.SAMPLER_CUBE]="texCube");this.bindParameters=function(a){for(var c=a.defParamsList,d=a.lightParams,f=a.lightContext,g=c.length,h=0,l=Array(2),m=0,h=0;h<g;++h)if(c[h].type=="tex2d"||c[h].type=="texCube"){l[0]=m++;l[1]=c[h].data[0];RDGE.bindMap[c[h].type](this.ctx,c[h].loc,l)}else RDGE.bindMap[c[h].type](this.ctx,c[h].loc,RDGE.rdgeGlobalParameters[c[h].name].data);
c=RDGE.rdgeConstants.MAX_MATERIAL_LIGHTS;for(g=0;g<c;++g)if(f[g]!=null&&d[g]){h=d[g].length;for(m=0;m<h;++m)RDGE.lightDataMap[d[g][m].dataIndex](this.ctx,d[g][m].loc,f[g])}m=this.renderer.usedTextureUnits;c=a.paramsList;g=c.length;for(h=0;h<g;++h)if(c[h].type=="tex2d"||c[h].type=="texCube"){l[0]=m++;l[1]=c[h].data[0];RDGE.bindMap[c[h].type](this.ctx,c[h].loc,l)}else RDGE.bindMap[c[h].type](this.ctx,c[h].loc,c[h].data)};createJShaderTexture=function(a,c){var d=null,d=typeof c.data=="string"?a.canvas.renderer.getTextureByName(c.data,
c.wrap,c.repeat,c.mips):a.canvas.renderer.getTextureByName(c.data.lookUpName,c.wrap,c.repeat,c.mips);return[d]};paramType=function(a,c,d,f,g){this.loc=a.getUniformLocation(f,c);this.loc==null&&window.console.log("ctx:"+a.canvas.rdgeid+", technique: "+g+", uniform: "+c+" was not found, jshader param will have no affect");c=d[c];this.type=c.type;if(c.data==void 0)switch(c.type){case "vec4":this.data=RDGE.vec4.zero();break;case "vec3":this.data=RDGE.vec3.zero();break;case "vec2":this.data=RDGE.vec2.zero();
break;case "mat4":this.data=RDGE.mat4.zero();break;case "mat3":this.data=Array(9);break;case "mat2":this.data=[0,0,0,0];break;case "float":this.data=[0];break;case "int":this.data=[0];break;case "tex2d":this.data=[a.canvas.renderer.getTextureByName(RDGE.globals.engine._assetPath+"images/white.png")];break;case "texCube":this.data=[a.canvas.renderer.getTextureByName(RDGE.globals.engine._assetPath+"images/white.png")]}else this.data=c.type=="tex2d"||c.type=="texCube"?createJShaderTexture(a,c):c.data.slice();
this.get=function(){return this.data.slice()};this.set=function(c){if(this.type=="tex2d"||this.type=="texCube"){typeof c=="string"&&(c=a.canvas.renderer.getTextureByName(c));this.data[0]=c}else for(var d=this.data.length,f=0;f<d;++f)this.data[f]=c[f]}};globalParam=function(a,c,d,f){this.type=d.type;this.data=d.data;this.loc=a.getUniformLocation(f,c);if(this.data)this.data=d.type=="tex2d"||d.type=="texCube"?createJShaderTexture(a,d):d.data.slice();else switch(d.type){case "vec4":this.data=RDGE.vec4.zero();
break;case "vec3":this.data=RDGE.vec3.zero();break;case "vec2":this.data=RDGE.vec2.zero();break;case "mat4":this.data=RDGE.mat4.zero();break;case "mat3":this.data=Array(9);break;case "mat2":this.data=[0,0,0,0];break;case "float":this.data=[0];break;case "int":this.data=[0];break;case "tex2d":this.data=[a.canvas.renderer.getTextureByName(RDGE.globals.engine._assetPath+"images/white.png")];break;case "texCube":this.data=[a.canvas.renderer.getTextureByName(RDGE.globals.engine._assetPath+"images/white.png")]}this.get=
function(){return this.data.slice()};this.set=function(c){if(this.type=="tex2d"||this.type=="texCube"){typeof c=="string"&&(c=a.canvas.renderer.getTextureByName(c));this.data[0]=c}else for(var d=this.data.length,f=0;f<d;++f)this.data[f]=c[f]}};this.init=function(){var a=this.def.techniques,c=null;for(t in a){var c=t,d=a[t];this[t]={passes:[]};for(var f=d.length,g=0;g<f;){var h=this.buildProgram(d[g]);this.ctx.useProgram(h);var l=this.ctx.getProgramParameter(h,this.ctx.ACTIVE_ATTRIBUTES);for(j=0;j<
l;++j){var m=this.ctx.getActiveAttrib(h,j);d[g].attributes[m.name]={type:RDGE.paramTypeNameMapping[m.type]}}l=this.ctx.getProgramParameter(h,this.ctx.ACTIVE_UNIFORMS);for(j=0;j<l;++j){m=this.ctx.getActiveUniform(h,j);RDGE.rdgeGlobalParameters[m.name]||(d[g].params[m.name]={type:RDGE.paramTypeNameMapping[m.type]})}h.ctxId=this.ctx.canvas.rdgeid;if(h)this[t].passes.push({program:h,params:{},defParams:{},states:d[g].states,attributes:d[g].attribPairs});else{this.renderer.console.log("Build errors found in technique: "+
t);this.def[t]=null;break}for(var n in RDGE.rdgeGlobalParameters){l=new globalParam(this.ctx,n,RDGE.rdgeGlobalParameters[n],h);if(l.loc!=null){l.loc.ctxID=this.ctx.canvas.rdgeid;this[t].passes[g].defParams[n]=l;this.global[n]=l}}this[t].passes[g].lightParams=[null,null,null,null];this[t].passes[g].lightContext=[null,null,null,null];if(!this[t].passes[g].paramsList)this[t].passes[g].paramsList=[];l=RDGE.rdgeConstants.MAX_MATERIAL_LIGHTS;for(m=0;m<l;++m){this[t].passes[g].lightParams[m]=null;var p=
0,o;for(o in RDGE.globals.engine.lightManager.lightUniforms[m]){loc=this.ctx.getUniformLocation(h,o);if(loc!=null){this[t].passes[g].lightParams[m]||(this[t].passes[g].lightParams[m]=[]);this[t].passes[g].lightParams[m].push({loc:loc,name:o,dataIndex:p})}p++}}for(n in d[g].params)if(typeof d[g].params[n]!="string"){l=new paramType(this.ctx,n,d[g].params,h,t);this[t].passes[g].params[n]=l;this[t][n]=l}for(n in d[g].params)typeof d[g].params[n]=="string"&&(this[t][n]=this[t].passes[g].params[n]);g++}}for(t in a){f=
this[t].passes.length;for(g=0;g<f;++g){this[t].passes[g].defParamsList=[];for(n in this[t].passes[g].params){d=this[t].passes[g].params[n];d.name=n;this[t].passes[g].paramsList.push(d)}for(n in this[t].passes[g].defParams){d=this[t].passes[g].defParams[n];d.name=n;this[t].passes[g].defParamsList.push(d)}}}this.setTechnique(c)};this.initLocalParameter=function(a,c){var d=this.def.techniques;for(t in d)for(var f=d[t],g=f.length,h=0;h<g;){var l=new paramType(this.ctx,a,c,f[h].program,t);if(l){f[h][a]=
l;if(!f[h].paramsList)f[h].paramsList=[];f[h].paramsList.push(l)}h++}};this.buildShader=function(a,c){var c="#define PC\n"+c,d=this.ctx.createShader(a);if(d==null){this.renderer.console.log("*** Error: unable to create shader '"+a+"'");return null}this.ctx.shaderSource(d,c);this.ctx.compileShader(d);if(!this.ctx.getShaderParameter(d,this.ctx.COMPILE_STATUS)){var f=this.ctx.getShaderInfoLog(d);window.console.error("*** Error compiling shader '"+a+"':"+f);this.ctx.deleteShader(d);return null}return d};
this.buildProgram=function(a){window.console.log("building shader pair: <"+a.vshader+", "+a.fshader+">");var c=RDGE.globals.engine.remapAssetFolder(this.def.shaders[a.vshader]),d=RDGE.globals.engine.remapAssetFolder(this.def.shaders[a.fshader]);this.ctx.useProgram(null);var