diff options
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-x | js/lib/geom/geom-obj.js | 189 |
1 files changed, 65 insertions, 124 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 3c4e4bbf..56cf7c98 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js | |||
@@ -19,6 +19,7 @@ var GeomObj = function GLGeomObj() { | |||
19 | this.GEOM_TYPE_LINE = 3; | 19 | this.GEOM_TYPE_LINE = 3; |
20 | this.GEOM_TYPE_PATH = 4; | 20 | this.GEOM_TYPE_PATH = 4; |
21 | this.GEOM_TYPE_CUBIC_BEZIER = 5; | 21 | this.GEOM_TYPE_CUBIC_BEZIER = 5; |
22 | this.GEOM_TYPE_BRUSH_STROKE = 6; | ||
22 | this.GEOM_TYPE_UNDEFINED = -1; | 23 | this.GEOM_TYPE_UNDEFINED = -1; |
23 | 24 | ||
24 | // Needed for calculating dashed/dotted strokes | 25 | // Needed for calculating dashed/dotted strokes |
@@ -110,14 +111,16 @@ var GeomObj = function GLGeomObj() { | |||
110 | return this.GEOM_TYPE_UNDEFINED; | 111 | return this.GEOM_TYPE_UNDEFINED; |
111 | }; | 112 | }; |
112 | 113 | ||
113 | this.getPrimitiveArray = function() { return this._primArray; | 114 | this.getPrimitiveArray = function () { |
115 | return this._primArray; | ||
114 | }; | 116 | }; |
115 | 117 | ||
116 | this.getMaterialNodeArray = function() { | 118 | this.getMaterialNodeArray = function() { |
117 | return this._materialNodeArray; | 119 | return this._materialNodeArray; |
118 | }; | 120 | }; |
119 | 121 | ||
120 | this.getMaterialArray = function() { return this._materialArray; | 122 | this.getMaterialArray = function () { |
123 | return this._materialArray; | ||
121 | }; | 124 | }; |
122 | 125 | ||
123 | this.getTransformNode = function() { | 126 | this.getTransformNode = function() { |
@@ -141,46 +144,65 @@ var GeomObj = function GLGeomObj() { | |||
141 | this.setMaterialColor = function(c, type) { | 144 | this.setMaterialColor = function(c, type) { |
142 | var i = 0, | 145 | var i = 0, |
143 | nMats = 0; | 146 | nMats = 0; |
144 | if(c.gradientMode) { | 147 | if(c) { |
145 | // Gradient support | 148 | if(c.gradientMode) { |
146 | if (this._materialArray && this._materialTypeArray) { | 149 | // Gradient support |
147 | nMats = this._materialArray.length; | 150 | if (this._materialArray && this._materialTypeArray) { |
148 | } | 151 | nMats = this._materialArray.length; |
149 | 152 | } | |
150 | var stops = [], | ||
151 | colors = c.color; | ||
152 | 153 | ||
153 | var len = colors.length; | 154 | var stops = [], |
154 | // TODO - Current shaders only support 4 color stops | 155 | colors = c.color; |
155 | if(len > 4) { | ||
156 | len = 4; | ||
157 | } | ||
158 | 156 | ||
159 | for(var n=0; n<len; n++) { | 157 | var len = colors.length; |
160 | var position = colors[n].position/100; | 158 | // TODO - Current shaders only support 4 color stops |
161 | var cs = colors[n].value; | 159 | if(len > 4) { |
162 | var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a]; | 160 | len = 4; |
163 | stops.push(stop); | 161 | } |
164 | 162 | ||
165 | if (nMats === this._materialTypeArray.length) { | 163 | for(var n=0; n<len; n++) { |
166 | for (i=0; i<nMats; i++) { | 164 | var position = colors[n].position/100; |
167 | if (this._materialTypeArray[i] == type) { | 165 | var cs = colors[n].value; |
168 | this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) ); | 166 | var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a]; |
169 | this._materialArray[i].setProperty( "colorStop"+(n+1), position ); | 167 | stops.push(stop); |
168 | |||
169 | if (nMats === this._materialTypeArray.length) { | ||
170 | for (i=0; i<nMats; i++) { | ||
171 | if (this._materialTypeArray[i] == type) { | ||
172 | this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) ); | ||
173 | this._materialArray[i].setProperty( "colorStop"+(n+1), position ); | ||
174 | } | ||
170 | } | 175 | } |
171 | } | 176 | } |
172 | } | 177 | } |
173 | } | 178 | if (type === "fill") { |
174 | if (type === "fill") { | 179 | this._fillColor = c; |
175 | this._fillColor = c; | 180 | } else { |
181 | this._strokeColor = c; | ||
182 | } | ||
176 | } else { | 183 | } else { |
177 | this._strokeColor = c; | 184 | if (type === "fill") { |
185 | this._fillColor = c.slice(0); | ||
186 | } else { | ||
187 | this._strokeColor = c.slice(0); | ||
188 | } | ||
189 | |||
190 | if (this._materialArray && this._materialTypeArray) { | ||
191 | nMats = this._materialArray.length; | ||
192 | if (nMats === this._materialTypeArray.length) { | ||
193 | for (i=0; i<nMats; i++) { | ||
194 | if (this._materialTypeArray[i] == type) { | ||
195 | this._materialArray[i].setProperty( "color", c.slice(0) ); | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | } | ||
178 | } | 200 | } |
179 | } else { | 201 | } else { |
180 | if (type === "fill") { | 202 | if (type === "fill") { |
181 | this._fillColor = c.slice(0); | 203 | this._fillColor = null; |
182 | } else { | 204 | } else { |
183 | this._strokeColor = c.slice(0); | 205 | this._strokeColor = null; |
184 | } | 206 | } |
185 | 207 | ||
186 | if (this._materialArray && this._materialTypeArray) { | 208 | if (this._materialArray && this._materialTypeArray) { |
@@ -188,7 +210,8 @@ var GeomObj = function GLGeomObj() { | |||
188 | if (nMats === this._materialTypeArray.length) { | 210 | if (nMats === this._materialTypeArray.length) { |
189 | for (i=0; i<nMats; i++) { | 211 | for (i=0; i<nMats; i++) { |
190 | if (this._materialTypeArray[i] == type) { | 212 | if (this._materialTypeArray[i] == type) { |
191 | this._materialArray[i].setProperty( "color", c.slice(0) ); | 213 | // TODO - Not sure how to set color to null values in shaders |
214 | this._materialArray[i].setProperty( "color", [0,0,0,0] ); | ||
192 | } | 215 | } |
193 | } | 216 | } |
194 | } | 217 | } |
@@ -245,18 +268,14 @@ var GeomObj = function GLGeomObj() { | |||
245 | return fillMaterial; | 268 | return fillMaterial; |
246 | }; | 269 | }; |
247 | 270 | ||
248 | this.exportMaterialsJSON = function() | 271 | this.exportMaterialsJSON = function () { |
249 | { | ||
250 | var jObj; | 272 | var jObj; |
251 | if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) | 273 | if (this._materialArray && this._materialNodeArray && this.getWorld().isWebGL()) { |
252 | { | ||
253 | var nMats = this._materialArray.length; | 274 | var nMats = this._materialArray.length; |
254 | if (nMats > 0) | 275 | if (nMats > 0) { |
255 | { | ||
256 | var arr = []; | 276 | var arr = []; |
257 | 277 | ||
258 | for (var i=0; i<nMats; i++) | 278 | for (var i = 0; i < nMats; i++) { |
259 | { | ||
260 | var matObj = | 279 | var matObj = |
261 | { | 280 | { |
262 | 'materialNodeName' : this._materialNodeArray[i].name, | 281 | 'materialNodeName' : this._materialNodeArray[i].name, |
@@ -277,8 +296,7 @@ var GeomObj = function GLGeomObj() { | |||
277 | return jObj; | 296 | return jObj; |
278 | } | 297 | } |
279 | 298 | ||
280 | this.importMaterialsJSON = function( jObj ) | 299 | this.importMaterialsJSON = function (jObj) { |
281 | { | ||
282 | this._materialArray = []; | 300 | this._materialArray = []; |
283 | this._materialTypeArray = []; | 301 | this._materialTypeArray = []; |
284 | 302 | ||
@@ -286,13 +304,11 @@ var GeomObj = function GLGeomObj() { | |||
286 | 304 | ||
287 | var nMaterials = jObj.nMaterials; | 305 | var nMaterials = jObj.nMaterials; |
288 | var matArray = jObj.materials; | 306 | var matArray = jObj.materials; |
289 | for (var i=0; i<nMaterials; i++) | 307 | for (var i = 0; i < nMaterials; i++) { |
290 | { | ||
291 | var mat; | 308 | var mat; |
292 | var matObj = matArray[i].material; | 309 | var matObj = matArray[i].material; |
293 | var shaderName = matObj.material; | 310 | var shaderName = matObj.material; |
294 | switch (shaderName) | 311 | switch (shaderName) { |
295 | { | ||
296 | case "flat": | 312 | case "flat": |
297 | case "radialGradient": | 313 | case "radialGradient": |
298 | case "linearGradient": | 314 | case "linearGradient": |
@@ -324,8 +340,7 @@ var GeomObj = function GLGeomObj() { | |||
324 | break; | 340 | break; |
325 | } | 341 | } |
326 | 342 | ||
327 | if (mat) | 343 | if (mat) { |
328 | { | ||
329 | mat.importJSON( matObj ); | 344 | mat.importJSON( matObj ); |
330 | this._materialArray.push( mat ); | 345 | this._materialArray.push( mat ); |
331 | this._materialTypeArray.push( matObj.type ); | 346 | this._materialTypeArray.push( matObj.type ); |
@@ -334,80 +349,7 @@ var GeomObj = function GLGeomObj() { | |||
334 | else this._strokeMaterial = mat; | 349 | else this._strokeMaterial = mat; |
335 | } | 350 | } |
336 | } | 351 | } |
337 | } | 352 | }; |
338 | |||
339 | this.exportMaterials = function() | ||
340 | { | ||
341 | var rtnStr = ""; | ||
342 | if (this._materialArray && this._materialNodeArray) | ||
343 | { | ||
344 | var nMats = this._materialArray.length; | ||
345 | rtnStr += "nMaterials: " + nMats + "\n"; | ||
346 | for (var i=0; i<nMats; i++) | ||
347 | { | ||
348 | var matNode = this._materialNodeArray[i]; | ||
349 | rtnStr += "materialNodeName: " + matNode.name + "\n"; | ||
350 | |||
351 | var material = this._materialArray[i]; | ||
352 | rtnStr += material.export(); | ||
353 | } | ||
354 | } | ||
355 | else | ||
356 | rtnStr += "nMaterials: 0\n" ; | ||
357 | |||
358 | return rtnStr; |