aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/lib/geom/rectangle.js46
-rw-r--r--js/lib/geom/shape-primitive.js130
-rw-r--r--js/lib/rdge/materials/flag-material.js6
-rwxr-xr-xjs/lib/rdge/materials/material.js5
-rw-r--r--js/lib/rdge/materials/twist-vert-material.js1
-rw-r--r--js/lib/rdge/texture.js527
-rwxr-xr-xjs/models/materials-model.js4
7 files changed, 428 insertions, 291 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index e511d5f4..51947ff1 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -943,13 +943,13 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad,
943 } 943 }
944 944
945 //refine the mesh for vertex deformations 945 //refine the mesh for vertex deformations
946// if (material) { 946 if (material) {
947// if (material.hasVertexDeformation()) { 947 if (material.hasVertexDeformation()) {
948// var paramRange = material.getVertexDeformationRange(); 948 var paramRange = material.getVertexDeformationRange();
949// var tolerance = material.getVertexDeformationTolerance(); 949 var tolerance = material.getVertexDeformationTolerance();
950// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 950 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
951// } 951 }
952// } 952 }
953 953
954 // create the RDGE primitive 954 // create the RDGE primitive
955 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 955 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
@@ -1175,13 +1175,13 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad,
1175 } 1175 }
1176 1176
1177 //refine the mesh for vertex deformations 1177 //refine the mesh for vertex deformations
1178// if (material) { 1178 if (material) {
1179// if (material.hasVertexDeformation()) { 1179 if (material.hasVertexDeformation()) {
1180// var paramRange = material.getVertexDeformationRange(); 1180 var paramRange = material.getVertexDeformationRange();
1181// var tolerance = material.getVertexDeformationTolerance(); 1181 var tolerance = material.getVertexDeformationTolerance();
1182// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1182 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1183// } 1183 }
1184// } 1184 }
1185 1185
1186 // create the RDGE primitive 1186 // create the RDGE primitive
1187 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1187 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
@@ -1259,15 +1259,15 @@ RectangleGeometry.create = function( ctr, width, height, material ) {
1259 RectangleGeometry.pushIndices( 0, 3, 2 ); 1259 RectangleGeometry.pushIndices( 0, 3, 2 );
1260 1260
1261 //refine the mesh for vertex deformations 1261 //refine the mesh for vertex deformations
1262// if (material) 1262 if (material)
1263// { 1263 {
1264// if (material.hasVertexDeformation()) 1264 if (material.hasVertexDeformation())
1265// { 1265 {
1266// var paramRange = material.getVertexDeformationRange(); 1266 var paramRange = material.getVertexDeformationRange();
1267// var tolerance = material.getVertexDeformationTolerance(); 1267 var tolerance = material.getVertexDeformationTolerance();
1268// nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); 1268 nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance );
1269// } 1269 }
1270// } 1270 }
1271 1271
1272 // create the RDGE primitive 1272 // create the RDGE primitive
1273 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); 1273 return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices);
diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js
index bf0087b2..44a7aa52 100644
--- a/js/lib/geom/shape-primitive.js
+++ b/js/lib/geom/shape-primitive.js
@@ -49,6 +49,136 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver
49 return prim; 49 return prim;
50}; 50};
51 51
52ShapePrimitive.getMeshBounds = function( verts, nVerts )
53{
54 if (!verts || (nVerts <= 0)) return null;
55
56 var bounds = [verts[0], verts[1], verts[2], verts[0], verts[1], verts[2]];
57 var index = 3;
58 for (var i=1; i<nVerts; i++)
59 {
60 var x = verts[index], y = verts[index+1], z = verts[index+2];
61 index += 3;
62
63 if (x < bounds[0]) bounds[0] = x;
64 else if (x > bounds[3]) bounds[3] = x;
65 if (y < bounds[1]) bounds[1] = y;
66 else if (y > bounds[4]) bounds[4] = y;
67 if (z < bounds[2]) bounds[2] = z;
68 else if (z > bounds[5]) bounds[5] = z;
69 }
70
71 return bounds;
72};
73
74ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance )
75{
76 var oldVrtCount = nVertices;
77
78 // get the param range
79 var pUMin = paramRange[0], pVMin = paramRange[1],
80 pUMax = paramRange[2], pVMax = paramRange[3];
81 var iTriangle = 0;
82 var nTriangles = indices.length/3;
83 var index = 0;
84 while (iTriangle < nTriangles)
85 {
86 // get the indices of the 3 vertices
87 var i0 = indices[index],
88 i1 = indices[index+1],
89 i2 = indices[index+2];
90
91 // get the uv values
92 //var vrtIndex = 3*iTriangle;
93 var iuv0 = 2 * i0,
94 iuv1 = 2 * i1,
95 iuv2 = 2 * i2;
96 var u0 = uvs[iuv0], v0 = uvs[iuv0+1],
97 u1 = uvs[iuv1], v1 = uvs[iuv1+1],
98 u2 = uvs[iuv2], v2 = uvs[iuv2+1];
99
100 // find the u and v range
101 var uMin = u0, vMin = v0;
102 if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1;
103 if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2;
104 var uMax = u0, vMax = v0;
105 if (u1 > uMax) uMax = u1; if (v1 > vMax) vMax = v1;
106 if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2;
107
108 // if the parameter range of the triangle is outside the
109 // desired parameter range, advance to the next polygon and continue
110 if ((uMin > pUMax) || (uMax < pUMin) || (vMin > pVMax) || (vMax < pVMin))
111 {
112 // go to the next triangle
113 iTriangle++;
114 index += 3;
115 }
116 else
117 {
118 // check thesize of the triangle in uv space. If small enough, advance
119 // to the next triangle. If not small enough, split the triangle into 3;
120 var du = uMax - uMin, dv = vMax - vMin;
121 if ((du < tolerance) && (dv < tolerance))
122 {
123 iTriangle++;
124 index += 3;
125 }
126 else // split the triangle into 4 parts
127 {
128 //calculate the position of the new vertex
129 var iPt0 = 3 * i0,
130 iPt1 = 3 * i1,
131 iPt2 = 3 * i2;
132 var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2],
133 x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2],
134 x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2];
135
136 // calculate the midpoints of the edges
137 var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0,
138 xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0,
139 xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0;
140
141 // calculate the uv values of the new coordinates
142 var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0,
143 uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0,
144 uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0;
145
146 // calculate the normals for the new points
147 var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2],
148 nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2],
149 nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2];
150 var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ),
151 nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ),
152 nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 );
153
154 // push everything
155 verts.push(xA); verts.push(yA); verts.push(zA);
156 verts.push(xB); verts.push(yB); verts.push(zB);
157 verts.push(xC); verts.push(yC); verts.push(zC);
158 uvs.push(uA), uvs.push(vA);
159 uvs.push(uB), uvs.push(vB);
160 uvs.push(uC), uvs.push(vC);
161 norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]);
162 norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]);
163 norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]);
164
165 // split the current triangle into 4
166 indices[index+1] = nVertices; indices[index+2] = nVertices+2;
167 indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++;
168 indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++;
169 indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++;
170 nVertices += 3;
171
172 // by not advancing 'index', we examine the first of the 3 triangles generated above
173 }
174 }
175 }
176
177 console.log( "refine mesh vertex count " + oldVrtCount + " => " + nVertices );
178 return nVertices;
179};
180
181
52if (typeof exports === "object") { 182if (typeof exports === "object") {
53 exports.ShapePrimitive = ShapePrimitive; 183 exports.ShapePrimitive = ShapePrimitive;
54} \ No newline at end of file 184} \ No newline at end of file
diff --git a/js/lib/rdge/materials/flag-material.js b/js/lib/rdge/materials/flag-material.js
index 77991a8c..8d4d1ee3 100644
--- a/js/lib/rdge/materials/flag-material.js
+++ b/js/lib/rdge/materials/flag-material.js
@@ -23,6 +23,8 @@ var FlagMaterial = function FlagMaterial() {
23 this._defaultWaveWidth = 1.0; 23 this._defaultWaveWidth = 1.0;
24 this._defaultWaveHeight = 1.0; 24 this._defaultWaveHeight = 1.0;