diff options
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 105 |
1 files changed, 74 insertions, 31 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index b85433a0..81a8556d 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -17,6 +17,9 @@ exports.Rectangle = Object.create(GeomObj, { | |||
17 | // CONSTANTS | 17 | // CONSTANTS |
18 | N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? | 18 | N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? |
19 | 19 | ||
20 | //if (!MaterialsModel) | ||
21 | // MaterialsModel = require("js/models/materials-model").MaterialsModel; | ||
22 | |||
20 | /////////////////////////////////////////////////////////////////////// | 23 | /////////////////////////////////////////////////////////////////////// |
21 | // Instance variables | 24 | // Instance variables |
22 | /////////////////////////////////////////////////////////////////////// | 25 | /////////////////////////////////////////////////////////////////////// |
@@ -70,16 +73,19 @@ exports.Rectangle = Object.create(GeomObj, { | |||
70 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; | 73 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; |
71 | 74 | ||
72 | if(strokeMaterial) { | 75 | if(strokeMaterial) { |
73 | this._strokeMaterial = strokeMaterial; | 76 | this._strokeMaterial = strokeMaterial.dup(); |
74 | } else { | 77 | } else { |
75 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 78 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); |
76 | } | 79 | } |
80 | if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); | ||
81 | |||
77 | 82 | ||
78 | if(fillMaterial) { | 83 | if(fillMaterial) { |
79 | this._fillMaterial = fillMaterial; | 84 | this._fillMaterial = fillMaterial.dup(); |
80 | } else { | 85 | } else { |
81 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 86 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); |
82 | } | 87 | } |
88 | if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); | ||
83 | } | 89 | } |
84 | }, | 90 | }, |
85 | 91 | ||
@@ -286,19 +292,23 @@ exports.Rectangle = Object.create(GeomObj, { | |||
286 | var strokeMaterialName = jObj.strokeMat; | 292 | var strokeMaterialName = jObj.strokeMat; |
287 | var fillMaterialName = jObj.fillMat; | 293 | var fillMaterialName = jObj.fillMat; |
288 | 294 | ||
289 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | 295 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); |
290 | if (!strokeMat) { | 296 | if (!strokeMat) { |
291 | console.log( "object material not found in library: " + strokeMaterialName ); | 297 | console.log( "object material not found in library: " + strokeMaterialName ); |
292 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 298 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); |
293 | } | 299 | } |
294 | this._strokeMaterial = strokeMat; | 300 | this._strokeMaterial = strokeMat; |
301 | if (this._strokeMaterial.hasProperty( 'color' )) | ||
302 | this._strokeMaterial.setProperty( 'color', this._strokeColor ); | ||
295 | 303 | ||
296 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | 304 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); |
297 | if (!fillMat) { | 305 | if (!fillMat) { |
298 | console.log( "object material not found in library: " + fillMaterialName ); | 306 | console.log( "object material not found in library: " + fillMaterialName ); |
299 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 307 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); |
300 | } | 308 | } |
301 | this._fillMaterial = fillMat; | 309 | this._fillMaterial = fillMat; |
310 | if (this._fillMaterial.hasProperty( 'color' )) | ||
311 | this._fillMaterial.setProperty( 'color', this._fillColor ); | ||
302 | 312 | ||
303 | this.importMaterialsJSON( jObj.materials ); | 313 | this.importMaterialsJSON( jObj.materials ); |
304 | } | 314 | } |
@@ -942,13 +952,13 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
942 | } | 952 | } |
943 | 953 | ||
944 | //refine the mesh for vertex deformations | 954 | //refine the mesh for vertex deformations |
945 | // if (material) { | 955 | if (material) { |
946 | // if (material.hasVertexDeformation()) { | 956 | if (material.hasVertexDeformation()) { |
947 | // var paramRange = material.getVertexDeformationRange(); | 957 | var paramRange = material.getVertexDeformationRange(); |
948 | // var tolerance = material.getVertexDeformationTolerance(); | 958 | var tolerance = material.getVertexDeformationTolerance(); |
949 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 959 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
950 | // } | 960 | } |
951 | // } | 961 | } |
952 | 962 | ||
953 | // create the RDGE primitive | 963 | // create the RDGE primitive |
954 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 964 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1174,13 +1184,15 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1174 | } | 1184 | } |
1175 | 1185 | ||
1176 | //refine the mesh for vertex deformations | 1186 | //refine the mesh for vertex deformations |
1177 | // if (material) { | 1187 | if (material) |
1178 | // if (material.hasVertexDeformation()) { | 1188 | { |
1179 | // var paramRange = material.getVertexDeformationRange(); | 1189 | if (material.hasVertexDeformation()) |
1180 | // var tolerance = material.getVertexDeformationTolerance(); | 1190 | { |
1181 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1191 | var paramRange = material.getVertexDeformationRange(); |
1182 | // } | 1192 | var tolerance = material.getVertexDeformationTolerance(); |
1183 | // } | 1193 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1194 | } | ||
1195 | } | ||
1184 | 1196 | ||
1185 | // create the RDGE primitive | 1197 | // create the RDGE primitive |
1186 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 1198 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1258,15 +1270,15 @@ RectangleGeometry.create = function( ctr, width, height, material ) { | |||
1258 | RectangleGeometry.pushIndices( 0, 3, 2 ); | 1270 | RectangleGeometry.pushIndices( 0, 3, 2 ); |
1259 | 1271 | ||
1260 | //refine the mesh for vertex deformations | 1272 | //refine the mesh for vertex deformations |
1261 | // if (material) | 1273 | if (material) |
1262 | // { | 1274 | { |
1263 | // if (material.hasVertexDeformation()) | 1275 | if (material.hasVertexDeformation()) |
1264 | // { | 1276 | { |
1265 | // var paramRange = material.getVertexDeformationRange(); | 1277 | var paramRange = material.getVertexDeformationRange(); |
1266 | // var tolerance = material.getVertexDeformationTolerance(); | 1278 | var tolerance = material.getVertexDeformationTolerance(); |
1267 | // nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1279 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1268 | // } | 1280 | } |
1269 | // } | 1281 | } |
1270 | 1282 | ||
1271 | // create the RDGE primitive | 1283 | // create the RDGE primitive |
1272 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | 1284 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
@@ -1279,5 +1291,36 @@ RectangleGeometry.pushIndices = RectangleFill.pushIndices; | |||
1279 | RectangleGeometry.getVertex = RectangleFill.getVertex; | 1291 | RectangleGeometry.getVertex = RectangleFill.getVertex; |
1280 | RectangleGeometry.getUV = RectangleFill.getUV; | 1292 | RectangleGeometry.getUV = RectangleFill.getUV; |
1281 | 1293 | ||
1294 | RectangleGeometry.init = function() | ||
1295 | { | ||
1296 | this.vertices = []; | ||
1297 | this.normals = []; | ||
1298 | this.uvs = []; | ||
1299 | this.indices = []; | ||
1300 | } | ||
1301 | |||
1302 | RectangleGeometry.addQuad = function( verts, normals, uvs ) | ||
1303 | { | ||
1304 | var offset = this.vertices.length/3; | ||
1305 | for (var i=0; i<4; i++) | ||
1306 | { | ||
1307 | RectangleGeometry.pushVertex( verts[i][0], verts[i][1], verts[i][2]); | ||
1308 | RectangleGeometry.pushNormal( normals[i] ); | ||
1309 | RectangleGeometry.pushUV( uvs[i] ); | ||
1310 | } | ||
1311 | |||
1312 | RectangleGeometry.pushIndices( 0+offset, 1+offset, 2+offset ); | ||
1313 | RectangleGeometry.pushIndices( 2+offset, 3+offset, 0+offset ); | ||
1314 | } | ||
1315 | |||
1316 | RectangleGeometry.buildPrimitive = function() | ||
1317 | { | ||
1318 | var nVertices = this.vertices.length/3; | ||
1319 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); | ||
1320 | } | ||
1321 | |||
1322 | |||
1323 | |||
1324 | exports.RectangleGeometry = RectangleGeometry; | ||
1282 | 1325 | ||
1283 | 1326 | ||