aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/geom-obj.js110
-rwxr-xr-xjs/lib/geom/rectangle.js83
-rw-r--r--js/lib/geom/shape-primitive.js130
3 files changed, 264 insertions, 59 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 7cb9b80f..4efa5d60 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -10,7 +10,8 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel;
10// Class GLGeomObj 10// Class GLGeomObj
11// Super class for all geometry classes 11// Super class for all geometry classes
12/////////////////////////////////////////////////////////////////////// 12///////////////////////////////////////////////////////////////////////
13var GeomObj = function GLGeomObj() { 13var GeomObj = function GLGeomObj()
14{
14 /////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////
15 // Constants 16 // Constants
16 /////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////
@@ -141,14 +142,18 @@ var GeomObj = function GLGeomObj() {
141 this.setStrokeColor = function (c) { 142 this.setStrokeColor = function (c) {
142 this.setMaterialColor(c, "stroke"); 143 this.setMaterialColor(c, "stroke");
143 }; 144 };
145
144 /////////////////////////////////////////////////////////////////////// 146 ///////////////////////////////////////////////////////////////////////
145 // Methods 147 // Methods
146 /////////////////////////////////////////////////////////////////////// 148 ///////////////////////////////////////////////////////////////////////
147 this.setMaterialColor = function (c, type) { 149 this.setMaterialColor = function (c, type)
150 {
148 var i = 0, 151 var i = 0,
149 nMats = 0; 152 nMats = 0;
150 if (c) { 153 if (c)
151 if (c.gradientMode) { 154 {
155 if (c.gradientMode)
156 {
152 // Gradient support 157 // Gradient support
153 if (this._materialArray && this._materialTypeArray) { 158 if (this._materialArray && this._materialTypeArray) {
154 nMats = this._materialArray.length; 159 nMats = this._materialArray.length;
@@ -163,15 +168,19 @@ var GeomObj = function GLGeomObj() {
163 len = 4; 168 len = 4;
164 } 169 }
165 170
166 for (var n = 0; n < len; n++) { 171 for (var n = 0; n < len; n++)
172 {
167 var position = colors[n].position / 100; 173 var position = colors[n].position / 100;
168 var cs = colors[n].value; 174 var cs = colors[n].value;
169 var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a]; 175 var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a];
170 stops.push(stop); 176 stops.push(stop);
171 177
172 if (nMats === this._materialTypeArray.length) { 178 if (nMats === this._materialTypeArray.length)
173 for (i = 0; i < nMats; i++) { 179 {
174 if (this._materialTypeArray[i] == type) { 180 for (i = 0; i < nMats; i++)
181 {
182 if (this._materialTypeArray[i] == type)
183 {
175 this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0)); 184 this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0));
176 this._materialArray[i].setProperty("colorStop" + (n + 1), position); 185 this._materialArray[i].setProperty("colorStop" + (n + 1), position);
177 } 186 }
@@ -180,20 +189,24 @@ var GeomObj = function GLGeomObj() {
180 } 189 }
181 if (type === "fill") { 190 if (type === "fill") {
182 this._fillColor = c; 191 this._fillColor = c;
183 } else { 192 }
193 else {
184 this._strokeColor = c; 194 this._strokeColor = c;
185 } 195 }
186 } else { 196 }
197 else {
187 if (type === "fill") { 198 if (type === "fill") {
188 this._fillColor = c.slice(0); 199 this._fillColor = c.slice(0);
189 } else { 200 }
201 else {
190 this._strokeColor = c.slice(0); 202 this._strokeColor = c.slice(0);
191 } 203 }
192 204
193 if (this._materialArray && this._materialTypeArray) { 205 if (this._materialArray && this._materialTypeArray) {
194 nMats = this._materialArray.length; 206 nMats = this._materialArray.length;
195 if (nMats === this._materialTypeArray.length) { 207 if (nMats === this._materialTypeArray.length) {
196 for (i = 0; i < nMats; i++) { 208 for (i = 0; i < nMats; i++)
209 {
197 if (this._materialTypeArray[i] == type) { 210 if (this._materialTypeArray[i] == type) {
198 this._materialArray[i].setProperty("color", c.slice(0)); 211 this._materialArray[i].setProperty("color", c.slice(0));
199 } 212 }
@@ -201,18 +214,25 @@ var GeomObj = function GLGeomObj() {
201 } 214 }
202 } 215 }
203 } 216 }
204 } else { 217 }
218 else
219 {
205 if (type === "fill") { 220 if (type === "fill") {
206 this._fillColor = null; 221 this._fillColor = null;
207 } else { 222 }
223 else {
208 this._strokeColor = null; 224 this._strokeColor = null;
209 } 225 }
210 226
211 if (this._materialArray && this._materialTypeArray) { 227 if (this._materialArray && this._materialTypeArray)
228 {
212 nMats = this._materialArray.length; 229 nMats = this._materialArray.length;
213 if (nMats === this._materialTypeArray.length) { 230 if (nMats === this._materialTypeArray.length)
214 for (i = 0; i < nMats; i++) { 231 {
215 if (this._materialTypeArray[i] == type) { 232 for (i = 0; i < nMats; i++)
233 {
234 if (this._materialTypeArray[i] == type)
235 {
216 // TODO - Not sure how to set color to null values in shaders 236 // TODO - Not sure how to set color to null values in shaders
217 this._materialArray[i].setProperty("color", [0, 0, 0, 0]); 237 this._materialArray[i].setProperty("color", [0, 0, 0, 0]);
218 } 238 }
@@ -227,11 +247,13 @@ var GeomObj = function GLGeomObj() {
227 } 247 }
228 }; 248 };
229 249
230 this.makeStrokeMaterial = function () { 250 this.makeStrokeMaterial = function ()
251 {
231 var strokeMaterial; 252 var strokeMaterial;
232 if (this.getStrokeMaterial()) { 253 if (this.getStrokeMaterial()) {
233 strokeMaterial = this.getStrokeMaterial().dup(); 254 strokeMaterial = this.getStrokeMaterial().dup();
234 } else { 255 }
256 else {
235 strokeMaterial = MaterialsModel.exportFlatMaterial(); 257 strokeMaterial = MaterialsModel.exportFlatMaterial();
236 } 258 }
237 259
@@ -246,14 +268,18 @@ var GeomObj = function GLGeomObj() {
246 this.setStrokeColor(this._strokeColor); 268 this.setStrokeColor(this._strokeColor);
247 } 269 }
248 270
271 this._strokeMaterial = strokeMaterial;
272
249 return strokeMaterial; 273 return strokeMaterial;
250 }; 274 };
251 275
252 this.makeFillMaterial = function () { 276 this.makeFillMaterial = function ()
277 {
253 var fillMaterial; 278 var fillMaterial;
254 if (this.getFillMaterial()) { 279 if (this.getFillMaterial()) {
255 fillMaterial = this.getFillMaterial().dup(); 280 fillMaterial = this.getFillMaterial().dup();
256 } else { 281 }
282 else {
257 fillMaterial = MaterialsModel.exportFlatMaterial(); 283 fillMaterial = MaterialsModel.exportFlatMaterial();
258 } 284 }
259 285
@@ -268,17 +294,24 @@ var GeomObj = function GLGeomObj() {
268 this.setFillColor(this._fillColor); 294 this.setFillColor(this._fillColor);
269 } 295 }
270 296
297 this._fillMaterial = fillMaterial;
298
271 return fillMaterial; 299 return fillMaterial;
272 }; 300 };
273 301
274 this.exportMaterialsJSON = function () { 302 this.exportMaterialsJSON = function ()
303 {
304 MaterialsModel = require("js/models/materials-model").MaterialsModel;
305
275 var jObj; 306 var jObj;
276 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { 307 if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) {
277 var nMats = this._materialArray.length; 308 var nMats = this._materialArray.length;
278 if (nMats > 0) { 309 if (nMats > 0)
310 {
279 var arr = []; 311 var arr = [];
280 312
281 for (var i = 0; i < nMats; i++) { 313 for (var i = 0; i < nMats; i++)
314 {
282 var matObj = 315 var matObj =
283 { 316 {
284 'materialNodeName':this._materialNodeArray[i].name, 317 'materialNodeName':this._materialNodeArray[i].name,
@@ -299,7 +332,10 @@ var GeomObj = function GLGeomObj() {
299 return jObj; 332 return jObj;
300 } 333 }
301 334
302 this.importMaterialsJSON = function (jObj) { 335 this.importMaterialsJSON = function (jObj)
336 {
337 MaterialsModel = require("js/models/materials-model").MaterialsModel;
338
303 this._materialArray = []; 339 this._materialArray = [];
304 this._materialTypeArray = []; 340 this._materialTypeArray = [];
305 341
@@ -307,11 +343,13 @@ var GeomObj = function GLGeomObj() {
307 343
308 var nMaterials = jObj.nMaterials; 344 var nMaterials = jObj.nMaterials;
309 var matArray = jObj.materials; 345 var matArray = jObj.materials;
310 for (var i = 0; i < nMaterials; i++) { 346 for (var i = 0; i < nMaterials; i++)
347 {
311 var mat; 348 var mat;