diff options
Diffstat (limited to 'js/lib')
-rwxr-xr-x | js/lib/geom/circle.js | 3 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 6 | ||||
-rw-r--r-- | js/lib/geom/shape-primitive.js | 27 | ||||
-rwxr-xr-x | js/lib/rdge/materials/linear-gradient-material.js | 14 | ||||
-rwxr-xr-x | js/lib/rdge/materials/material.js | 4 | ||||
-rwxr-xr-x | js/lib/rdge/materials/radial-gradient-material.js | 43 |
6 files changed, 84 insertions, 13 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 425b869a..b60ad58f 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -311,6 +311,7 @@ exports.Circle = Object.create(GeomObj, { | |||
311 | 311 | ||
312 | if (fillPrim) { | 312 | if (fillPrim) { |
313 | fillMaterial = this.makeFillMaterial(); | 313 | fillMaterial = this.makeFillMaterial(); |
314 | fillMaterial.fitToPrimitive( fillPrim ); | ||
314 | 315 | ||
315 | this._primArray.push( fillPrim ); | 316 | this._primArray.push( fillPrim ); |
316 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); | 317 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); |
@@ -318,6 +319,7 @@ exports.Circle = Object.create(GeomObj, { | |||
318 | 319 | ||
319 | if (strokePrim0) { | 320 | if (strokePrim0) { |
320 | strokeMaterial0 = this.makeStrokeMaterial(); | 321 | strokeMaterial0 = this.makeStrokeMaterial(); |
322 | strokeMaterial0.fitToPrimitive( strokePrim0 ); | ||
321 | 323 | ||
322 | this._primArray.push( strokePrim0 ); | 324 | this._primArray.push( strokePrim0 ); |
323 | this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); | 325 | this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); |
@@ -325,6 +327,7 @@ exports.Circle = Object.create(GeomObj, { | |||
325 | 327 | ||
326 | if (strokePrim1) { | 328 | if (strokePrim1) { |
327 | strokeMaterial2 = this.makeStrokeMaterial(); | 329 | strokeMaterial2 = this.makeStrokeMaterial(); |
330 | strokeMaterial2.fitToPrimitive( strokePrim1 ); | ||
328 | 331 | ||
329 | this._primArray.push( strokePrim1 ); | 332 | this._primArray.push( strokePrim1 ); |
330 | this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); | 333 | this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); |
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index d75abb05..cf0e7fc8 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -56,8 +56,6 @@ exports.Rectangle = Object.create(GeomObj, { | |||
56 | this._strokeStyle = strokeStyle; | 56 | this._strokeStyle = strokeStyle; |
57 | 57 | ||
58 | this._matrix = Matrix.I(4); | 58 | this._matrix = Matrix.I(4); |
59 | //this._matrix[12] = xoffset; | ||
60 | //this._matrix[13] = yoffset; | ||
61 | } | 59 | } |
62 | 60 | ||
63 | // the overall radius includes the fill and the stroke. separate the two based on the stroke width | 61 | // the overall radius includes the fill and the stroke. separate the two based on the stroke width |
@@ -124,7 +122,6 @@ exports.Rectangle = Object.create(GeomObj, { | |||
124 | this._fillMaterial = m; | 122 | this._fillMaterial = m; |
125 | } | 123 | } |
126 | }, | 124 | }, |
127 | |||
128 | /////////////////////////////////////////////////////////////////////// | 125 | /////////////////////////////////////////////////////////////////////// |
129 | // update the "color of the material | 126 | // update the "color of the material |
130 | getFillColor: { | 127 | getFillColor: { |
@@ -138,7 +135,6 @@ exports.Rectangle = Object.create(GeomObj, { | |||
138 | // this._fillColor = c; | 135 | // this._fillColor = c; |
139 | // } | 136 | // } |
140 | // }, | 137 | // }, |
141 | |||
142 | getStrokeColor: { | 138 | getStrokeColor: { |
143 | value: function() { | 139 | value: function() { |
144 | return this._strokeColor; | 140 | return this._strokeColor; |
@@ -379,6 +375,7 @@ exports.Rectangle = Object.create(GeomObj, { | |||
379 | // stroke | 375 | // stroke |
380 | var strokeMaterial = this.makeStrokeMaterial(); | 376 | var strokeMaterial = this.makeStrokeMaterial(); |
381 | var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); | 377 | var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); |
378 | strokeMaterial.fitToPrimitive( strokePrim ); | ||
382 | this._primArray.push( strokePrim ); | 379 | this._primArray.push( strokePrim ); |
383 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | 380 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); |
384 | 381 | ||
@@ -392,6 +389,7 @@ exports.Rectangle = Object.create(GeomObj, { | |||
392 | var fillMaterial = this.makeFillMaterial(); | 389 | var fillMaterial = this.makeFillMaterial(); |
393 | //console.log( "fillMaterial: " + fillMaterial.getName() ); | 390 | //console.log( "fillMaterial: " + fillMaterial.getName() ); |
394 | var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); | 391 | var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); |
392 | fillMaterial.fitToPrimitive( fillPrim ); | ||
395 | this._primArray.push( fillPrim ); | 393 | this._primArray.push( fillPrim ); |
396 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); | 394 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); |
397 | 395 | ||
diff --git a/js/lib/geom/shape-primitive.js b/js/lib/geom/shape-primitive.js index 97873d32..9864a8e9 100644 --- a/js/lib/geom/shape-primitive.js +++ b/js/lib/geom/shape-primitive.js | |||
@@ -49,6 +49,33 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver | |||
49 | return prim; | 49 | return prim; |
50 | }; | 50 | }; |
51 | 51 | ||
52 | ShapePrimitive.getBounds = function( prim ) | ||
53 | { | ||
54 | var verts = prim.bufferStreams[0]; | ||
55 | var nVerts = verts.length; | ||
56 | var xMin = verts[0], xMax = verts[0], | ||
57 | yMin = verts[1], yMax = verts[1], | ||
58 | zMin = verts[2], zMax = verts[2]; | ||
59 | |||
60 | for (var index=3; index<verts.length; ) | ||
61 | { | ||
62 | if (verts[index] < xMin) xMin = verts[index]; | ||
63 | else if (verts[index] > xMax) xMax = verts[index]; | ||
64 | |||
65 | index++; | ||
66 | if (verts[index] < yMin) yMin = verts[index]; | ||
67 | else if (verts[index] > yMax) yMax = verts[index]; | ||
68 | |||
69 | index++; | ||
70 | if (verts[index] < zMin) zMin = verts[index]; | ||
71 | else if (verts[index] > zMax) zMax = verts[index]; | ||
72 | |||
73 | index++; | ||
74 | } | ||
75 | |||
76 | return [xMin, yMin, zMin, xMax, yMax, zMax]; | ||
77 | }; | ||
78 | |||
52 | if (typeof exports === "object") { | 79 | if (typeof exports === "object") { |
53 | exports.ShapePrimitive = ShapePrimitive; | 80 | exports.ShapePrimitive = ShapePrimitive; |
54 | } \ No newline at end of file | 81 | } \ No newline at end of file |
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js index 51a7430c..79f323db 100755 --- a/js/lib/rdge/materials/linear-gradient-material.js +++ b/js/lib/rdge/materials/linear-gradient-material.js | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | ||
9 | 10 | ||
10 | var LinearGradientMaterial = function LinearGradientMaterial() { | 11 | var LinearGradientMaterial = function LinearGradientMaterial() { |
11 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
@@ -132,12 +133,6 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
132 | } | 133 | } |
133 | }; | 134 | }; |
134 | 135 | ||
135 | // this.getColorCount = function() { return this._colorCount; }; | ||
136 | // this.setColorCount = function(c) { this._colorCount = c; | ||
137 | // if (this._shader && this._shader['default']) | ||
138 | // this._shader['default'].u_colorCount.set([c]); | ||
139 | // }; | ||
140 | |||
141 | this.getAngle = function () { | 136 | this.getAngle = function () { |
142 | return this._angle; | 137 | return this._angle; |
143 | }; | 138 | }; |
@@ -245,7 +240,9 @@ var LinearGradientMaterial = function LinearGradientMaterial() { | |||
245 | this._shader['default'].u_colorStop4.set([s]); | 240 | this._shader['default'].u_colorStop4.set([s]); |
246 | 241 | ||
247 | this.setAngle(this.getAngle()); | 242 | this.setAngle(this.getAngle()); |
248 | } | 243 | |
244 | this._shader['default'].u_texTransform.set( [1,0,0, 0,1,0, 0,0,1] ); | ||
245 | } | ||
249 | }; | 246 | }; |
250 | 247 | ||
251 | this.exportJSON = function () { | 248 | this.exportJSON = function () { |
@@ -367,7 +364,8 @@ var linearGradientMaterialDef = | |||
367 | 'u_colorStop2': { 'type' : 'float' }, | 364 | 'u_colorStop2': { 'type' : 'float' }, |
368 | 'u_colorStop3': { 'type' : 'float' }, | 365 | 'u_colorStop3': { 'type' : 'float' }, |
369 | 'u_colorStop4': { 'type' : 'float' }, | 366 | 'u_colorStop4': { 'type' : 'float' }, |
370 | 'u_cos_sin_angle' : { 'type' : 'vec2' } | 367 | 'u_cos_sin_angle': { 'type' : 'vec2' }, |
368 | 'u_texTransform': { 'type' : 'mat3' } | ||
371 | //'u_colorCount': {'type' : 'int' } | 369 | //'u_colorCount': {'type' : 'int' } |
372 | 370 | ||
373 | }, | 371 | }, |
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js index 276c7687..b96768b3 100755 --- a/js/lib/rdge/materials/material.js +++ b/js/lib/rdge/materials/material.js | |||
@@ -228,6 +228,10 @@ var Material = function GLMaterial( world ) { | |||
228 | // animated materials should implement the update method | 228 | // animated materials should implement the update method |
229 | }; | 229 | }; |
230 | 230 | ||
231 | this.fitToPrimitive = function( prim ) { | ||
232 | // some materials need to preserve an aspect ratio - or someting else. | ||
233 | }; | ||
234 | |||
231 | this.registerTexture = function( texture ) { | 235 | this.registerTexture = function( texture ) { |
232 | // the world needs to know about the texture map | 236 | // the world needs to know about the texture map |
233 | var world = this.getWorld(); | 237 | var world = this.getWorld(); |
diff --git a/js/lib/rdge/materials/radial-gradient-material.js b/js/lib/rdge/materials/radial-gradient-material.js index dd40d31d..a671ee42 100755 --- a/js/lib/rdge/materials/radial-gradient-material.js +++ b/js/lib/rdge/materials/radial-gradient-material.js | |||
@@ -6,6 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; |
8 | var Material = require("js/lib/rdge/materials/material").Material; | 8 | var Material = require("js/lib/rdge/materials/material").Material; |
9 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | ||
9 | 10 | ||
10 | var RadialGradientMaterial = function RadialGradientMaterial() { | 11 | var RadialGradientMaterial = function RadialGradientMaterial() { |
11 | /////////////////////////////////////////////////////////////////////// | 12 | /////////////////////////////////////////////////////////////////////// |
@@ -24,6 +25,9 @@ var RadialGradientMaterial = function RadialGradientMaterial() { | |||
24 | this._colorStop4 = 1.0; | 25 | this._colorStop4 = 1.0; |
25 | // this._colorCount = 4; | 26 | // this._colorCount = 4; |
26 | 27 | ||