aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/circle.js19
-rwxr-xr-xjs/lib/geom/geom-obj.js80
-rwxr-xr-xjs/lib/geom/line.js10
-rwxr-xr-xjs/lib/geom/rectangle.js15
4 files changed, 91 insertions, 33 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index d48bf98b..f74d4e57 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -42,8 +42,8 @@ var Circle = function GLCircle() {
42 42
43 this._strokeWidth = strokeSize; 43 this._strokeWidth = strokeSize;
44 this._innerRadius = innerRadius; 44 this._innerRadius = innerRadius;
45 if (strokeColor) this._strokeColor = strokeColor; 45 this._strokeColor = strokeColor;
46 if (fillColor) this._fillColor = fillColor; 46 this._fillColor = fillColor;
47 47
48 this._strokeStyle = strokeStyle; 48 this._strokeStyle = strokeStyle;
49 } 49 }
@@ -633,6 +633,21 @@ var Circle = function GLCircle() {
633 this._strokeStyle = jObj.strokeStyle; 633 this._strokeStyle = jObj.strokeStyle;
634 var strokeMaterialName = jObj.strokeMat; 634 var strokeMaterialName = jObj.strokeMat;
635 var fillMaterialName = jObj.fillMat; 635 var fillMaterialName = jObj.fillMat;
636
637 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
638 if (!strokeMat) {
639 console.log( "object material not found in library: " + strokeMaterialName );
640 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
641 }
642 this._strokeMaterial = strokeMat;
643
644 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
645 if (!fillMat) {
646 console.log( "object material not found in library: " + fillMaterialName );
647 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
648 }
649 this._fillMaterial = fillMat;
650
636 this.importMaterialsJSON( jObj.materials ); 651 this.importMaterialsJSON( jObj.materials );
637 }; 652 };
638 653
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index f1aa9f8a..44daa291 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -142,46 +142,65 @@ var GeomObj = function GLGeomObj() {
142 this.setMaterialColor = function(c, type) { 142 this.setMaterialColor = function(c, type) {
143 var i = 0, 143 var i = 0,
144 nMats = 0; 144 nMats = 0;
145 if(c.gradientMode) { 145 if(c) {
146 // Gradient support 146 if(c.gradientMode) {
147 if (this._materialArray && this._materialTypeArray) { 147 // Gradient support
148 nMats = this._materialArray.length; 148 if (this._materialArray && this._materialTypeArray) {
149 } 149 nMats = this._materialArray.length;
150 }
150 151
151 var stops = [], 152 var stops = [],
152 colors = c.color; 153 colors = c.color;
153 154
154 var len = colors.length; 155 var len = colors.length;
155 // TODO - Current shaders only support 4 color stops 156 // TODO - Current shaders only support 4 color stops
156 if(len > 4) { 157 if(len > 4) {
157 len = 4; 158 len = 4;
158 } 159 }
159
160 for(var n=0; n<len; n++) {
161 var position = colors[n].position/100;
162 var cs = colors[n].value;
163 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
164 stops.push(stop);
165 160
166 if (nMats === this._materialTypeArray.length) { 161 for(var n=0; n<len; n++) {
167 for (i=0; i<nMats; i++) { 162 var position = colors[n].position/100;
168 if (this._materialTypeArray[i] == type) { 163 var cs = colors[n].value;
169 this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) ); 164 var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a];
170 this._materialArray[i].setProperty( "colorStop"+(n+1), position ); 165 stops.push(stop);
166
167 if (nMats === this._materialTypeArray.length) {
168 for (i=0; i<nMats; i++) {
169 if (this._materialTypeArray[i] == type) {
170 this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) );
171 this._materialArray[i].setProperty( "colorStop"+(n+1), position );
172 }
171 } 173 }
172 } 174 }
173 } 175 }
174 } 176 if (type === "fill") {
175 if (type === "fill") { 177 this._fillColor = c;
176 this._fillColor = c; 178 } else {
179 this._strokeColor = c;
180 }
177 } else { 181 } else {
178 this._strokeColor = c; 182 if (type === "fill") {
183 this._fillColor = c.slice(0);
184 } else {
185 this._strokeColor = c.slice(0);
186 }
187
188 if (this._materialArray && this._materialTypeArray) {
189 nMats = this._materialArray.length;
190 if (nMats === this._materialTypeArray.length) {
191 for (i=0; i<nMats; i++) {
192 if (this._materialTypeArray[i] == type) {
193 this._materialArray[i].setProperty( "color", c.slice(0) );
194 }
195 }
196 }
197 }
179 } 198 }
180 } else { 199 } else {
181 if (type === "fill") { 200 if (type === "fill") {
182 this._fillColor = c.slice(0); 201 this._fillColor = null;
183 } else { 202 } else {
184 this._strokeColor = c.slice(0); 203 this._strokeColor = null;
185 } 204 }
186 205
187 if (this._materialArray && this._materialTypeArray) { 206 if (this._materialArray && this._materialTypeArray) {
@@ -189,7 +208,8 @@ var GeomObj = function GLGeomObj() {
189 if (nMats === this._materialTypeArray.length) { 208 if (nMats === this._materialTypeArray.length) {
190 for (i=0; i<nMats; i++) { 209 for (i=0; i<nMats; i++) {
191 if (this._materialTypeArray[i] == type) { 210 if (this._materialTypeArray[i] == type) {
192 this._materialArray[i].setProperty( "color", c.slice(0) ); 211 // TODO - Not sure how to set color to null values in shaders
212 this._materialArray[i].setProperty( "color", [0,0,0,0] );
193 } 213 }
194 } 214 }
195 } 215 }
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js
index 1848218d..1e98855e 100755
--- a/js/lib/geom/line.js
+++ b/js/lib/geom/line.js
@@ -44,7 +44,7 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
44 44
45 this._slope = slope; 45 this._slope = slope;
46 this._strokeWidth = strokeSize; 46 this._strokeWidth = strokeSize;
47 if (strokeColor) this._strokeColor = strokeColor.slice(); 47 this._strokeColor = strokeColor;
48 48
49 this._strokeStyle = strokeStyle; 49 this._strokeStyle = strokeStyle;
50 this._scaleX = (world.getViewportWidth())/(world.getViewportHeight()); 50 this._scaleX = (world.getViewportWidth())/(world.getViewportHeight());
@@ -137,6 +137,14 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok
137 this._strokeStyle = jObj.strokeStyle; 137 this._strokeStyle = jObj.strokeStyle;
138 this._strokeColor = jObj.strokeColor; 138 this._strokeColor = jObj.strokeColor;
139 var strokeMaterialName = jObj.strokeMat; 139 var strokeMaterialName = jObj.strokeMat;
140
141 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
142 if (!strokeMat) {
143 console.log( "object material not found in library: " + strokeMaterialName );
144 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
145 }
146 this._strokeMaterial = strokeMat;
147
140 this.importMaterialsJSON( jObj.materials ); 148 this.importMaterialsJSON( jObj.materials );
141 }; 149 };
142 150
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index e511d5f4..b01aea53 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -290,6 +290,21 @@ var Rectangle = function GLRectangle() {
290 this._strokeStyle = jObj.strokeStyle; 290 this._strokeStyle = jObj.strokeStyle;
291 var strokeMaterialName = jObj.strokeMat; 291 var strokeMaterialName = jObj.strokeMat;
292 var fillMaterialName = jObj.fillMat; 292 var fillMaterialName = jObj.fillMat;
293
294 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
295 if (!strokeMat) {
296 console.log( "object material not found in library: " + strokeMaterialName );
297 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
298 }
299 this._strokeMaterial = strokeMat;
300
301 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
302 if (!fillMat) {
303 console.log( "object material not found in library: " + fillMaterialName );
304 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
305 }
306 this._fillMaterial = fillMat;
307
293 this.importMaterialsJSON( jObj.materials ); 308 this.importMaterialsJSON( jObj.materials );
294 }; 309 };
295 310