aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorhwc4872012-02-07 14:35:55 -0800
committerhwc4872012-02-07 14:35:55 -0800
commit2d4da18a778471b02e188ad668752e331ee76127 (patch)
treed1aee0417e6e9ad0335c9e6232d49001a4e425ba /js
parent9d122c5f1632b1225a543049913c36b9a030110c (diff)
downloadninja-2d4da18a778471b02e188ad668752e331ee76127.tar.gz
test code for deformation shader
Diffstat (limited to 'js')
-rw-r--r--js/helper-classes/RDGE/GLMaterial.js4
-rw-r--r--js/helper-classes/RDGE/GLRectangle.js64
-rw-r--r--js/helper-classes/RDGE/GLWorld.js6
-rw-r--r--js/helper-classes/RDGE/Materials/FlatMaterial.js11
4 files changed, 52 insertions, 33 deletions
diff --git a/js/helper-classes/RDGE/GLMaterial.js b/js/helper-classes/RDGE/GLMaterial.js
index 07a98ab5..a74a74e4 100644
--- a/js/helper-classes/RDGE/GLMaterial.js
+++ b/js/helper-classes/RDGE/GLMaterial.js
@@ -34,7 +34,7 @@ function GLMaterial( world )
34 // vertex deformation variables 34 // vertex deformation variables
35 this._hasVertexDeformation = false; 35 this._hasVertexDeformation = false;
36 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax) 36 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax)
37 this._vertexDeformationTolerance = 0.05; 37 this._vertexDeformationTolerance = 0.1;
38 38
39 // RDGE variables 39 // RDGE variables
40 this._shader; 40 this._shader;
@@ -74,7 +74,7 @@ function GLMaterial( world )
74 // the vertex shader can apply deformations requiring refinement in 74 // the vertex shader can apply deformations requiring refinement in
75 // certain areas. 75 // certain areas.
76 this.hasVertexDeformation = function() { return this._hasVertexDeformation; } 76 this.hasVertexDeformation = function() { return this._hasVertexDeformation; }
77 this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); } 77 this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); }
78 this.getVertexDeformationTolerance = function() { return this._vertexDeformationTolerance; } 78 this.getVertexDeformationTolerance = function() { return this._vertexDeformationTolerance; }
79 79
80 80
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js
index e72b4488..7fe03022 100644
--- a/js/helper-classes/RDGE/GLRectangle.js
+++ b/js/helper-classes/RDGE/GLRectangle.js
@@ -1121,6 +1121,7 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1121 1121
1122 // create the RDGE primitive 1122 // create the RDGE primitive
1123 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1123 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1124 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1124 return prim; 1125 return prim;
1125} 1126}
1126 1127
@@ -1214,6 +1215,7 @@ RectangleGeometry.create = function( ctr, width, height, material )
1214 1215
1215 // create the RDGE primitive 1216 // create the RDGE primitive
1216 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1217 var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
1218 //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices);
1217 return prim; 1219 return prim;
1218} 1220}
1219 1221
@@ -1301,7 +1303,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1301 i2 = indices[index+2]; 1303 i2 = indices[index+2];
1302 1304
1303 // get the uv values 1305 // get the uv values
1304 var vrtIndex = 3*iTriangle; 1306 //var vrtIndex = 3*iTriangle;
1305 var iuv0 = 2 * i0, 1307 var iuv0 = 2 * i0,
1306 iuv1 = 2 * i1, 1308 iuv1 = 2 * i1,
1307 iuv2 = 2 * i2; 1309 iuv2 = 2 * i2;
@@ -1335,7 +1337,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1335 iTriangle++; 1337 iTriangle++;
1336 index += 3; 1338 index += 3;
1337 } 1339 }
1338 else // split the triangle 1340 else // split the triangle into 4 parts
1339 { 1341 {
1340 //calculate the position of the new vertex 1342 //calculate the position of the new vertex
1341 var iPt0 = 3 * i0, 1343 var iPt0 = 3 * i0,
@@ -1344,34 +1346,42 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa
1344 var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], 1346 var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2],
1345 x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], 1347 x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2],
1346 x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; 1348 x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2];
1347 var xMid = (x0 + x1 + x2)/3.0, 1349
1348 yMid = (y0 + y1 + y2)/3.0, 1350 // calculate the midpoints of the edges
1349 zMid = (z0 + z1 + z2)/3.0; 1351 var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0,
1350 1352 xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0,
1351 // calculate the uv value of the new coordinate 1353 xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0;
1352 var uMid = (u0 + u1 + u2)/3.0, 1354
1353 vMid = (v0 + v1 + v2)/3.0; 1355 // calculate the uv values of the new coordinates
1354 1356 var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0,
1355 // calculate the normal for the new coordinate 1357 uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0,
1358 uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0;
1359
1360 // calculate the normals for the new points
1356 var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], 1361 var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2],
1357 nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], 1362 nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2],
1358 nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; 1363 nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2];
1359 var nxMid = (nx0 + nx1 + nx2), 1364 var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ),
1360 nyMid = (ny0 + ny1 + ny2), 1365 nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ),
1361 nzMid = (nz0 + nz1 + nz2); 1366 nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 );
1362 var nrm = VecUtils.vecNormalize(3, [nxMid, nyMid, nzMid], 1.0 ); 1367
1363 1368 // push everything
1364 // push the new vertex 1369 verts.push(xA); verts.push(yA); verts.push(zA);
1365 verts.push(nrm[0]); verts.push(nrm[1]); verts.push(nrm[2]); 1370 verts.push(xB); verts.push(yB); verts.push(zB);
1366 uvs.push(uMid), uvs.push(vMid); 1371 verts.push(xC); verts.push(yC); verts.push(zC);
1367 norms.push(nrm[0]); norms.push(nrm[1]); norms.push(nrm[2]); 1372 uvs.push(uA), uvs.push(vA);
1368 var iMidVrt = nVertices; 1373 uvs.push(uB), uvs.push(vB);
1369 nVertices++; 1374 uvs.push(uC), uvs.push(vC);
1370 1375 norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]);
1371 // split the current triangle into 3 1376 norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]);
1372 indices[index+2] = iMidVrt; 1377 norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]);
1373 indices.push(i1); indices.push(i2); indices.push(iMidVrt); nTriangles++; 1378
1374 indices.push(i2); indices.push(i0); indices.push(iMidVrt); nTriangles++; 1379 // split the current triangle into 4
1380 indices[index+1] = nVertices; indices[index+2] = nVertices+2;
1381 indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++;
1382 indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++;
1383 indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++;
1384 nVertices += 3;
1375 1385
1376 // by not advancing 'index', we examine the first of the 3 triangles generated above 1386 // by not advancing 'index', we examine the first of the 3 triangles generated above
1377 } 1387 }
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js
index c97e29d4..83ed717d 100644
--- a/js/helper-classes/RDGE/GLWorld.js
+++ b/js/helper-classes/RDGE/GLWorld.js
@@ -14,6 +14,7 @@ var fragmentShaderSource = "";
14var rdgeStarted = false; 14var rdgeStarted = false;
15 15
16var nodeCounter = 0; 16var nodeCounter = 0;
17var worldCounter = 0;
17 18
18 19
19/////////////////////////////////////////////////////////////////////// 20///////////////////////////////////////////////////////////////////////
@@ -70,6 +71,9 @@ function GLWorld( canvas, use3D )
70 // no animated materials 71 // no animated materials
71 this._firstRender = true; 72 this._firstRender = true;
72 73
74 this._worldCount = worldCounter;
75 worldCounter++;
76
73 /////////////////////////////////////////////////////////////////////// 77 ///////////////////////////////////////////////////////////////////////
74 // Property accessors 78 // Property accessors
75 /////////////////////////////////////////////////////////////////////// 79 ///////////////////////////////////////////////////////////////////////
@@ -236,7 +240,7 @@ function GLWorld( canvas, use3D )
236 { 240 {
237 renderer.disableCulling(); 241 renderer.disableCulling();
238 this.myScene.render(); 242 this.myScene.render();
239 //console.log( "render" ); 243 console.log( "render" );
240 244
241 if (this._firstRender) 245 if (this._firstRender)
242 { 246 {
diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js
index c8eb3b6c..de039231 100644
--- a/js/helper-classes/RDGE/Materials/FlatMaterial.js
+++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js
@@ -26,10 +26,13 @@ function FlatMaterial()
26 /////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////
27 // Property Accessors 27 // Property Accessors
28 /////////////////////////////////////////////////////////////////////// 28 ///////////////////////////////////////////////////////////////////////
29 this.getColor = function() { return this._color; } 29 this.getColor = function() { return this._color; }
30 this.getShaderName = function() { return this._shaderName; } 30 this.getShaderName = function() { return this._shaderName; }
31 31
32 this.isAnimated = function() { return false; } 32 this.isAnimated = function() { return false; }
33 this.hasVertexDeformation = function() { return true; }
34 this._hasVertexDeformation = true;
35 this._vertexDeformationTolerance = 0.2;
33 36
34 //////////////////////////////////s///////////////////////////////////// 37 //////////////////////////////////s/////////////////////////////////////
35 // Methods 38 // Methods
@@ -55,6 +58,7 @@ function FlatMaterial()
55// this._shader.colorMe.u_limit1.set( [0.25] ); 58// this._shader.colorMe.u_limit1.set( [0.25] );
56// this._shader.colorMe.u_limit2.set( [0.5] ); 59// this._shader.colorMe.u_limit2.set( [0.5] );
57// this._shader.colorMe.u_limit3.set( [0.75] ); 60// this._shader.colorMe.u_limit3.set( [0.75] );
61// this._shader.colorMe.u_center.set( [0.0] );
58// this._shader.colorMe.u_taperAmount.set( [0.5] ); 62// this._shader.colorMe.u_taperAmount.set( [0.5] );
59 } 63 }
60 64
@@ -146,6 +150,7 @@ flatShaderDef =
146 //'u_limit1': { 'type': 'float' },