aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/drawing/world.js27
-rwxr-xr-xjs/lib/geom/brush-stroke.js638
-rwxr-xr-xjs/lib/geom/geom-obj.js3
-rwxr-xr-xjs/lib/geom/sub-path.js18
-rw-r--r--js/lib/rdge/materials/radial-blur-material.js18
5 files changed, 488 insertions, 216 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index 781695b6..5a054224 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -761,13 +761,10 @@ World.prototype.exportJSON = function()
761 // We need to rebuild everything 761 // We need to rebuild everything
762 if (this._useWebGL) 762 if (this._useWebGL)
763 { 763 {
764 var root = this._rootNode;
765 root.children = new Array();
766 if (worldObj.children && (worldObj.children.length === 1)) 764 if (worldObj.children && (worldObj.children.length === 1))
767 { 765 {
768 this.init(); 766 this.rebuildTree(this._geomRoot);
769 this._geomRoot = undefined; 767 this.restartRenderLoop();
770 this.importObjectsJSON( worldObj.children[0] );
771 } 768 }
772 } 769 }
773 770
@@ -783,6 +780,20 @@ World.prototype.exportJSON = function()
783 return jStr; 780 return jStr;
784} 781}
785 782
783World.prototype.rebuildTree = function( obj )
784{
785 if (!obj) return;
786
787 obj.buildBuffers();
788
789 if (obj.getChild()) {
790 this.rebuildTree( obj.getChild () );
791 }
792
793 if (obj.getNext())
794 this.rebuildTree( obj.getNext() );
795}
796
786World.prototype.exportObjectsJSON = function( obj, parentObj ) 797World.prototype.exportObjectsJSON = function( obj, parentObj )
787{ 798{
788 if (!obj) return; 799 if (!obj) return;
@@ -931,6 +942,7 @@ World.prototype.importObjectsJSON = function( jObj, parentGeomObj )
931World.prototype.importObjectJSON = function( jObj, parentGeomObj ) 942World.prototype.importObjectJSON = function( jObj, parentGeomObj )
932{ 943{
933 var type = jObj.type; 944 var type = jObj.type;
945 var BrushStroke = require("js/lib/geom/brush-stroke").BrushStroke;
934 946
935 var obj; 947 var obj;
936 switch (type) 948 switch (type)
@@ -950,6 +962,11 @@ World.prototype.importObjectJSON = function( jObj, parentGeomObj )
950 obj.importJSON( jObj ); 962 obj.importJSON( jObj );
951 break; 963 break;
952 964
965 case 6: //brush stroke
966 obj = new BrushStroke();
967 obj.importJSON(jObj);
968 break;
969
953 default: 970 default:
954 throw new Error( "Unrecognized object type: " + type ); 971 throw new Error( "Unrecognized object type: " + type );
955 break; 972 break;
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 4c42539a..22209815 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -4,9 +4,12 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7// Todo: This entire class should be converted to a module
8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; 7var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils;
9var GeomObj = require("js/lib/geom/geom-obj").GeomObj; 8var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
9var CanvasController = require("js/controllers/elements/canvas-controller").CanvasController;
10var ViewUtils = require("js/helper-classes/3D/view-utils").ViewUtils;
11
12// Todo: This entire class should be converted to a module
10 13
11/////////////////////////////////////////////////////////////////////// 14///////////////////////////////////////////////////////////////////////
12// Class GLBrushStroke 15// Class GLBrushStroke
@@ -17,20 +20,20 @@ var BrushStroke = function GLBrushStroke() {
17 /////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////
18 // Instance variables 21 // Instance variables
19 /////////////////////////////////////////////////// 22 ///////////////////////////////////////////////////
20 this._Points = []; 23 this._Points = []; //current state of points in stage-world space (may be different from input)
24 this._LocalPoints = []; //_Points in local coordinates...do this before rendering the points in the canvas
25 this._OrigLocalPoints = []; //copy of input points without any smoothing
26 this._stageWorldCenter = [0,0,0]; //coordinate for the canvas midPoint: a 3D vector in stage world space
21 this._BBoxMin = [0, 0, 0]; 27 this._BBoxMin = [0, 0, 0];
22 this._BBoxMax = [0, 0, 0]; 28 this._BBoxMax = [0, 0, 0];
23 this._dirty = true; 29 this._isDirty = true;
24 30 this._isInit = false;
25 //whether or not to use the canvas drawing to stroke/fill 31
26 this._useCanvasDrawing = true; 32 //the HTML5 canvas that holds this brush stroke
27 33 this._canvas = null;
28 //the X and Y location of this subpath's canvas in stage world space of Ninja
29 this._canvasX = 0;
30 this._canvasY = 0;
31 34
32 //stroke information 35 //stroke information
33 this._strokeWidth = 0.0; 36 this._strokeWidth = 1.0;
34 this._strokeColor = [0.4, 0.4, 0.4, 1.0]; 37 this._strokeColor = [0.4, 0.4, 0.4, 1.0];
35 this._secondStrokeColor = [1, 0.4, 0.4, 1.0]; 38 this._secondStrokeColor = [1, 0.4, 0.4, 1.0];
36 this._strokeHardness = 100; 39 this._strokeHardness = 100;
@@ -39,10 +42,7 @@ var BrushStroke = function GLBrushStroke() {
39 this._strokeDoSmoothing = false; 42 this._strokeDoSmoothing = false;
40 this._strokeUseCalligraphic = false; 43 this._strokeUseCalligraphic = false;
41 this._strokeAngle = 0; 44 this._strokeAngle = 0;
42 45 this._strokeAmountSmoothing = 0;
43 //the wetness of the brush (currently this is multiplied to the square of the stroke width, but todo should be changed to not depend on stroke width entirely
44 //smaller value means more samples for the path
45 this._WETNESS_FACTOR = 0.25;
46 46
47 //threshold that tells us whether two samples are too far apart 47 //threshold that tells us whether two samples are too far apart
48 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5; 48 this._MAX_SAMPLE_DISTANCE_THRESHOLD = 5;
@@ -51,7 +51,7 @@ var BrushStroke = function GLBrushStroke() {
51 this._MIN_SAMPLE_DISTANCE_THRESHOLD = 2; 51 this._MIN_SAMPLE_DISTANCE_THRESHOLD = 2;
52 52
53 //prevent extremely long paths that can take a long time to render 53 //prevent extremely long paths that can take a long time to render
54 this._MAX_ALLOWED_SAMPLES = 500; 54 this._MAX_ALLOWED_SAMPLES = 5000;
55 55
56 //drawing context 56 //drawing context
57 this._world = null; 57 this._world = null;
@@ -61,10 +61,15 @@ var BrushStroke = function GLBrushStroke() {
61 this._planeMat = null; 61 this._planeMat = null;
62 this._planeMatInv = null; 62 this._planeMatInv = null;
63 this._planeCenter = null; 63 this._planeCenter = null;
64 this._dragPlane = null;
64 65
65 ///////////////////////////////////////////////////////// 66 /////////////////////////////////////////////////////////
66 // Property Accessors/Setters 67 // Property Accessors/Setters
67 ///////////////////////////////////////////////////////// 68 /////////////////////////////////////////////////////////
69 this.setCanvas = function(c) {
70 this._canvas = c;
71 }
72
68 this.setWorld = function (world) { 73 this.setWorld = function (world) {
69 this._world = world; 74 this._world = world;
70 }; 75 };
@@ -74,7 +79,7 @@ var BrushStroke = function GLBrushStroke() {
74 }; 79 };
75 80
76 this.geomType = function () { 81 this.geomType = function () {
77 return this.GEOM_TYPE_CUBIC_BEZIER; 82 return this.GEOM_TYPE_BRUSH_STROKE;
78 }; 83 };
79 84
80 this.setDrawingTool = function (tool) { 85 this.setDrawingTool = function (tool) {
@@ -97,24 +102,15 @@ var BrushStroke = function GLBrushStroke() {
97 this._planeCenter = pc; 102 this._planeCenter = pc;
98 }; 103 };
99 104
100 this.getCanvasX = function(){ 105 this.setDragPlane = function(p){
101 return this._canvasX; 106 this._dragPlane = p;
102 };
103
104 this.getCanvasY = function(){
105 return this._canvasY;
106 };
107
108 this.setCanvasX = function(cx){
109 this._canvasX=cx;
110 };
111
112 this.setCanvasY = function(cy){
113 this._canvasY=cy;
114 }; 107 };
115 108
116 this.getNumPoints = function () { 109 this.getNumPoints = function () {
117 return this._Points.length; 110 if (this._LocalPoints.length)
111 return this._LocalPoints.length;
112 else
113 return this._Points.length;
118 }; 114 };
119 115
120 this.getPoint = function (index) { 116 this.getPoint = function (index) {
@@ -125,30 +121,38 @@ var BrushStroke = function GLBrushStroke() {
125 //add the point only if it is some epsilon away from the previous point 121 //add the point only if it is some epsilon away from the previous point
126 var numPoints = this._Points.length; 122 var numPoints = this._Points.length;
127 if (numPoints>0) { 123 if (numPoints>0) {
128 var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD;//this._WETNESS_FACTOR*this._strokeWidth; 124 var threshold = this._MIN_SAMPLE_DISTANCE_THRESHOLD;
129 var prevPt = this._Points[numPoints-1]; 125 var prevPt = this._Points[numPoints-1];
130 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]]; 126 var diffPt = [prevPt[0]-pt[0], prevPt[1]-pt[1]];
131 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]); 127 var diffPtMag = Math.sqrt(diffPt[0]*diffPt[0] + diffPt[1]*diffPt[1]);
132 if (diffPtMag>threshold){ 128 if (diffPtMag>threshold){
133 this._Points.push(pt); 129 this._Points.push(pt);
134 this._dirty=true; 130 this._isDirty=true;
131 this._isInit = false;
135 } 132 }
136 } else { 133 } else {
137 this._Points.push(pt); 134 this._Points.push(pt);
138 this._dirty=true; 135 this._isDirty=true;
136 this._isInit = false;
139 } 137 }
140 }; 138 };
141