aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/canvas-runtime.js32
-rwxr-xr-xassets/shaders/linearGradient.vert.glsl5
-rw-r--r--assets/shaders/radialGradient.vert.glsl4
-rwxr-xr-xjs/document/html-document.js4
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js146
-rwxr-xr-xjs/helper-classes/3D/view-utils.js13
-rwxr-xr-xjs/lib/geom/circle.js124
-rwxr-xr-xjs/lib/geom/rectangle.js190
-rw-r--r--js/lib/geom/shape-primitive.js27
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js36
-rwxr-xr-xjs/lib/rdge/materials/material.js4
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js70
12 files changed, 373 insertions, 282 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index 9bf22313..af860b95 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -906,11 +906,12 @@ NinjaCvsRt.RuntimeRectangle = Object.create(NinjaCvsRt.RuntimeGeomObj, {
906 inset = Math.ceil( lw ) - 0.5; 906 inset = Math.ceil( lw ) - 0.5;
907 907
908 if(this._fillColor.gradientMode) { 908 if(this._fillColor.gradientMode) {
909 if(this._fillColor.gradientMode === "radial") { 909 if(this._fillColor.gradientMode === "radial") {
910 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(w, h)/2); 910 var ww = w - 2*lw, hh = h - 2*lw;
911 } else { 911 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(ww, hh)/2);
912 gradient = ctx.createLinearGradient(inset/2, h/2, w-inset, h/2); 912 } else {
913 } 913 gradient = ctx.createLinearGradient(inset, h/2, w-inset, h/2);
914 }
914 colors = this._fillColor.color; 915 colors = this._fillColor.color;
915 916
916 len = colors.length; 917 len = colors.length;
@@ -940,11 +941,10 @@ NinjaCvsRt.RuntimeRectangle = Object.create(NinjaCvsRt.RuntimeGeomObj, {
940 inset = Math.ceil( 0.5*lw ) - 0.5; 941 inset = Math.ceil( 0.5*lw ) - 0.5;
941 942
942 if(this._strokeColor.gradientMode) { 943 if(this._strokeColor.gradientMode) {
943 if(this._strokeColor.gradientMode === "radial") { 944 if(this._strokeColor.gradientMode === "radial")
944 gradient = ctx.createRadialGradient(w/2, h/2, Math.min(h, w)/2-inset, w/2, h/2, Math.max(h, w)/2); 945 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(h, w)/2);
945 } else { 946 else
946 gradient = ctx.createLinearGradient(0, h/2, w, h/2); 947 gradient = ctx.createLinearGradient(0, h/2, w, h/2);
947 }
948 colors = this._strokeColor.color; 948 colors = this._strokeColor.color;
949 949
950 len = colors.length; 950 len = colors.length;
@@ -1144,9 +1144,9 @@ NinjaCvsRt.RuntimeOval = Object.create(NinjaCvsRt.RuntimeGeomObj, {
1144 if(this._fillColor.gradientMode) { 1144 if(this._fillColor.gradientMode) {
1145 if(this._fillColor.gradientMode === "radial") { 1145 if(this._fillColor.gradientMode === "radial") {
1146 gradient = ctx.createRadialGradient(xCtr, yCtr, 0, 1146 gradient = ctx.createRadialGradient(xCtr, yCtr, 0,
1147 xCtr, yCtr, Math.max(this._width, this._height)/2); 1147 xCtr, yCtr, Math.max(this._width, this._height)/2 - lineWidth);
1148 } else { 1148 } else {
1149 gradient = ctx.createLinearGradient(lineWidth/2, this._height/2, this._width-lineWidth, this._height/2); 1149 gradient = ctx.createLinearGradient(lineWidth, this._height/2, this._width-lineWidth, this._height/2);
1150 } 1150 }
1151 colors = this._fillColor.color; 1151 colors = this._fillColor.color;
1152 1152
@@ -1222,7 +1222,7 @@ NinjaCvsRt.RuntimeOval = Object.create(NinjaCvsRt.RuntimeGeomObj, {
1222 if (this._strokeColor) { 1222 if (this._strokeColor) {
1223 if(this._strokeColor.gradientMode) { 1223 if(this._strokeColor.gradientMode) {
1224 if(this._strokeColor.gradientMode === "radial") { 1224 if(this._strokeColor.gradientMode === "radial") {
1225 gradient = ctx.createRadialGradient(xCtr, yCtr, Math.min(xScale, yScale), 1225 gradient = ctx.createRadialGradient(xCtr, yCtr, 0,
1226 xCtr, yCtr, 0.5*Math.max(this._height, this._width)); 1226 xCtr, yCtr, 0.5*Math.max(this._height, this._width));
1227 } else { 1227 } else {
1228 gradient = ctx.createLinearGradient(0, this._height/2, this._width, this._height/2); 1228 gradient = ctx.createLinearGradient(0, this._height/2, this._width, this._height/2);
@@ -1484,6 +1484,8 @@ NinjaCvsRt.RuntimeRadialGradientMaterial = Object.create(NinjaCvsRt.RuntimeMater
1484 _colorStop3: { value: 0.6, writable: true }, 1484 _colorStop3: { value: 0.6, writable: true },
1485 _colorStop4: { value: 1.0, writable: true }, 1485 _colorStop4: { value: 1.0, writable: true },
1486 1486
1487 _textureTransform: { value: [1,0,0, 0,1,0, 0,0,1], writable: true },
1488
1487 init: { 1489 init: {
1488 value: function(world) { 1490 value: function(world) {
1489 var material = this._materialNode; 1491 var material = this._materialNode;
@@ -1505,6 +1507,8 @@ NinjaCvsRt.RuntimeRadialGradientMaterial = Object.create(NinjaCvsRt.RuntimeMater
1505 this._shader["default"].u_colorStop3.set( [this._colorStop3] ); 1507 this._shader["default"].u_colorStop3.set( [this._colorStop3] );
1506 this._shader["default"].u_colorStop4.set( [this._colorStop4] ); 1508 this._shader["default"].u_colorStop4.set( [this._colorStop4] );
1507 1509
1510 this._shader["default"].u_texTransform.set( this._textureTransform );
1511
1508 if (this._angle !== undefined) 1512 if (this._angle !== undefined)
1509 this._shader["default"].u_cos_sin_angle.set([Math.cos(this._angle), Math.sin(this._angle)]); 1513 this._shader["default"].u_cos_sin_angle.set([Math.cos(this._angle), Math.sin(this._angle)]);
1510 } 1514 }
@@ -1524,6 +1528,8 @@ NinjaCvsRt.RuntimeRadialGradientMaterial = Object.create(NinjaCvsRt.RuntimeMater
1524 this._colorStop3 = jObj.colorStop3; 1528 this._colorStop3 = jObj.colorStop3;
1525 this._colorStop4 = jObj.colorStop4; 1529 this._colorStop4 = jObj.colorStop4;
1526 1530
1531 this._textureTransform = jObj.textureTransform;
1532
1527 if (this._angle !== undefined) 1533 if (this._angle !== undefined)
1528 this._angle = jObj.angle; 1534 this._angle = jObj.angle;
1529 } 1535 }
diff --git a/assets/shaders/linearGradient.vert.glsl b/assets/shaders/linearGradient.vert.glsl
index aac9cbee..f0800812 100755
--- a/assets/shaders/linearGradient.vert.glsl
+++ b/assets/shaders/linearGradient.vert.glsl
@@ -37,6 +37,7 @@ uniform float u_colorStop3;
37uniform float u_colorStop4; 37uniform float u_colorStop4;
38uniform vec2 u_cos_sin_angle; 38uniform vec2 u_cos_sin_angle;
39//uniform int u_colorCount; // currently using 4 39//uniform int u_colorCount; // currently using 4
40uniform mat3 u_texTransform;
40 41
41varying vec2 v_uv; 42varying vec2 v_uv;
42 43
@@ -44,5 +45,7 @@ varying vec2 v_uv;
44void main(void) 45void main(void)
45{ 46{
46 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; 47 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ;
47 v_uv = texcoord; 48 //v_uv = texcoord;
49 vec3 tmp = u_texTransform * vec3( texcoord, 1.0);
50 v_uv = tmp.xy;
48} 51}
diff --git a/assets/shaders/radialGradient.vert.glsl b/assets/shaders/radialGradient.vert.glsl
index c3e1b50a..7994ac12 100644
--- a/assets/shaders/radialGradient.vert.glsl
+++ b/assets/shaders/radialGradient.vert.glsl
@@ -18,11 +18,13 @@ attribute vec2 texcoord;
18// matrix uniforms 18// matrix uniforms
19uniform mat4 u_mvMatrix; 19uniform mat4 u_mvMatrix;
20uniform mat4 u_projMatrix; 20uniform mat4 u_projMatrix;
21uniform mat3 u_texTransform;
21 22
22varying vec2 v_uv; 23varying vec2 v_uv;
23 24
24void main(void) 25void main(void)
25{ 26{
26 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; 27 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ;
27 v_uv = texcoord; 28 vec3 tmp = u_texTransform * vec3( texcoord, 1.0);
29 v_uv = tmp.xy;
28} \ No newline at end of file 30} \ No newline at end of file
diff --git a/js/document/html-document.js b/js/document/html-document.js
index bcf2b5c2..447d90e3 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -209,8 +209,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
209 { 209 {
210 /* 210 /*
211 // Use this code to test the runtime version of WebGL 211 // Use this code to test the runtime version of WebGL
212 var cdm = new NinjaCvsRt.CanvasDataManager(); 212 var cvsDataMngr = Object.create(NinjaCvsRt.CanvasDataManager, {});
213 cdm.loadGLData(elt, value, null ); 213 cvsDataMngr.loadGLData(elt, value);
214 */ 214 */
215 215
216 // /* 216 // /*
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index e22ac3ad..0f456e1e 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -223,64 +223,22 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
223 else 223 else
224 parentPt = [xScreen, yScreen, 0.0]; 224 parentPt = [xScreen, yScreen, 0.0];
225 225
226 var eyePt = []; 226 if (!snap3D && this._hasDragPlane)
227 var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt); 227 this.activateDragPlane();
228 if (vec) 228
229 { 229 var hitRec = this.snapToStage( parentPt, quadPt );
230 // activate the drag working plane 230
231 if (!snap3D && this.hasDragPlane()) 231 // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed
232 this.activateDragPlane(); 232 if (this.gridSnapEnabled())
233 233 this.snapToGrid( hitRec );
234 // project to the working plane 234
235 var currentWorkingPlane = workingPlane.slice(0); 235 // save the hit record
236 var wp = currentWorkingPlane.slice(0); 236 hitRecArray.push( hitRec );
237 var mat = viewUtils.getMatrixFromElement(stage); 237
238 wp = MathUtils.transformPlane(wp, mat); 238 // restore the original working plane
239 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); 239 if (!snap3D && this.hasDragPlane())
240 if (projPt) 240 this.deactivateDragPlane();
241 { 241
242 // the local point gets stored in the coordinate space of the plane
243 var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane));
244 projPt[3] = 1.0;
245 //var planeToViewMat = mat.multiply(wpMat);
246 var planeToViewMat = glmat4.multiply(mat, wpMat, []);
247 //var viewToPlaneMat = planeToViewMat.inverse();
248 var viewToPlaneMat = glmat4.inverse( planeToViewMat, [] );
249 var planePt = projPt.slice(0);
250 planePt[3] = 1.0;
251 //planePt = viewToPlaneMat.multiply(planePt);
252 planePt = glmat4.multiplyVec3( viewToPlaneMat, planePt );
253
254 // get the screen position of the projected point
255 viewUtils.setViewportObj(stage);
256 var offset = viewUtils.getElementOffset(stage);