aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/NJUtils.js1
-rwxr-xr-xjs/lib/drawing/world.js30
-rwxr-xr-xjs/lib/geom/brush-stroke.js14
-rwxr-xr-xjs/lib/geom/circle.js57
-rwxr-xr-xjs/lib/geom/geom-obj.js24
-rwxr-xr-xjs/lib/geom/line.js26
-rwxr-xr-xjs/lib/geom/rectangle.js57
-rwxr-xr-xjs/lib/rdge/materials/material.js4
-rw-r--r--js/lib/rdge/materials/radial-blur-material.js14
-rw-r--r--js/lib/rdge/materials/water-material.js14
10 files changed, 130 insertions, 111 deletions
diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js
index cfb7ef07..bca9b05b 100755
--- a/js/lib/NJUtils.js
+++ b/js/lib/NJUtils.js
@@ -241,6 +241,7 @@ exports.NJUtils = Montage.create(Component, {
241 // 100px will return the following array: [100, px] 241 // 100px will return the following array: [100, px]
242 getValueAndUnits: { 242 getValueAndUnits: {
243 value: function(input) { 243 value: function(input) {
244 if (!input) return [null, null];
244 var numberValue = parseFloat(input); 245 var numberValue = parseFloat(input);
245 246
246 // Ignore all whitespace, digits, negative sign and "." when looking for units label 247 // Ignore all whitespace, digits, negative sign and "." when looking for units label
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
index ca2f07cc..b9f9863f 100755
--- a/js/lib/drawing/world.js
+++ b/js/lib/drawing/world.js
@@ -439,6 +439,11 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) {
439 // in the case of a procedurally built scene an init state is not needed for loading data 439 // in the case of a procedurally built scene an init state is not needed for loading data
440 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); 440 this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" );
441 if (this._useWebGL) { 441 if (this._useWebGL) {
442 // make sure the id is unique
443 var id = this.uniqueifyID( this._canvas.rdgeid );
444 this._canvas.rdgeid = id;
445 this._canvas.setAttribute( "data-rdge-id", id );
446
442 rdgeStarted = true; 447 rdgeStarted = true;
443 RDGE.globals.engine.unregisterCanvas( this._canvas ); 448 RDGE.globals.engine.unregisterCanvas( this._canvas );
444 RDGE.globals.engine.registerCanvas(this._canvas, this); 449 RDGE.globals.engine.registerCanvas(this._canvas, this);
@@ -673,13 +678,35 @@ World.prototype.updateMaterials = function( obj, time ) {
673 var n = matArray.length; 678 var n = matArray.length;
674 for (var i=0; i<n; i++) { 679 for (var i=0; i<n; i++) {
675 matArray[i].update( time ); 680 matArray[i].update( time );
676 } 681 }
677 } 682 }
678 683
679 this.updateMaterials( obj.getNext(), time ); 684 this.updateMaterials( obj.getNext(), time );
680 this.updateMaterials( obj.getChild(), time ); 685 this.updateMaterials( obj.getChild(), time );
681}; 686};
682 687
688
689World.prototype.uniqueifyID = function( id )
690{
691 var ctx = RDGE.globals.engine.getContext( id );
692 while ( ctx )
693 {
694 var num = 0;
695 var index = id.indexOf( "_" );
696 if (index >= 0)
697 {
698 var subStr = id.substr( index+1);
699 num = Number( subStr ) + 1;
700 id = id.substr( 0, index );
701 }
702
703 id = id + "_" + num;
704 ctx = RDGE.globals.engine.getContext( id );
705 }
706
707 return id;
708}
709
683// return the origin of the world in NDC 710// return the origin of the world in NDC
684World.prototype.getNDCOrigin = function() { 711World.prototype.getNDCOrigin = function() {
685 var pt = MathUtils.transformPoint( [0,0,0], this.getCameraMatInverse() ); 712 var pt = MathUtils.transformPoint( [0,0,0], this.getCameraMatInverse() );
@@ -973,7 +1000,6 @@ World.prototype.importJSON = function (jObj)
973 // start RDGE 1000 // start RDGE
974 rdgeStarted = true; 1001 rdgeStarted = true;
975 var id = this._canvas.getAttribute( "data-RDGE-id" ); 1002 var id = this._canvas.getAttribute( "data-RDGE-id" );
976 this._canvas.rdgeid = id;
977 RDGE.globals.engine.registerCanvas(this._canvas, this); 1003 RDGE.globals.engine.registerCanvas(this._canvas, this);
978 RDGE.RDGEStart(this._canvas); 1004 RDGE.RDGEStart(this._canvas);
979 this._canvas.task.stop() 1005 this._canvas.task.stop()
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js
index 12f5c5a1..164d31ee 100755
--- a/js/lib/geom/brush-stroke.js
+++ b/js/lib/geom/brush-stroke.js
@@ -864,6 +864,17 @@ BrushStroke.prototype.drawToContext = function(ctx, drawStageWorldPts, stageWorl
864}; //this.drawToCanvas() 864}; //this.drawToCanvas()
865 865
866 866
867
868BrushStroke.prototype._fixCoordPrecision = function(coord, precision){
869 var i=0;
870 var numPoints = coord.length;
871 for (i=0;i<numPoints;i++){
872 coord[i][0] = parseFloat((coord[i][0]).toFixed(precision));
873 coord[i][1] = parseFloat((coord[i][1]).toFixed(precision));
874 coord[i][2] = parseFloat((coord[i][2]).toFixed(precision));
875 }
876};
877
867BrushStroke.prototype.exportJSON = function(){ 878BrushStroke.prototype.exportJSON = function(){
868 var retObject= new Object(); 879 var retObject= new Object();
869 //the type of this object 880 //the type of this object
@@ -873,9 +884,10 @@ BrushStroke.prototype.exportJSON = function(){
873 //the geometry for this object 884 //the geometry for this object
874 retObject.localPoints = this._LocalPoints.slice(0); 885 retObject.localPoints = this._LocalPoints.slice(0);
875 this._copyCoordinates3D(this._LocalPoints, retObject.localPoints); //todo is this necessary in addition to the slice(0) above? 886 this._copyCoordinates3D(this._LocalPoints, retObject.localPoints); //todo is this necessary in addition to the slice(0) above?
887 this._fixCoordPrecision(retObject.localPoints, 4);
876 retObject.origLocalPoints = this._OrigLocalPoints.slice(0); 888 retObject.origLocalPoints = this._OrigLocalPoints.slice(0);
877 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto> 889 this._copyCoordinates3D(this._OrigLocalPoints, retObject.origLocalPoints); //todo <ditto>
878 890 this._fixCoordPrecision(retObject.origLocalPoints, 4);
879 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]]; 891 retObject.stageWorldCenter = [this._stageWorldCenter[0],this._stageWorldCenter[1],this._stageWorldCenter[2]];
880 retObject.planeMat = this._planeMat; 892 retObject.planeMat = this._planeMat;
881 retObject.planeMatInv = this._planeMatInv; 893 retObject.planeMatInv = this._planeMatInv;
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index ba47603b..4995c2cb 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -83,31 +83,13 @@ exports.Circle = Object.create(GeomObj, {
83 83
84 if(strokeMaterial) { 84 if(strokeMaterial) {
85 this._strokeMaterial = strokeMaterial.dup(); 85 this._strokeMaterial = strokeMaterial.dup();
86 } else {
87 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
88 }
89
90 if(strokeColor) {
91 if(this._strokeMaterial.hasProperty("color")) {
92 this._strokeMaterial.setProperty( "color", this._strokeColor );
93 } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) {
94 this._strokeMaterial.setGradientData(this._strokeColor.color);
95 }
96 } 86 }
97 87
98 if(fillMaterial) { 88 if(fillMaterial) {
99 this._fillMaterial = fillMaterial.dup(); 89 this._fillMaterial = fillMaterial.dup();
100 } else {
101 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
102 } 90 }
103 91
104 if(fillColor) { 92 this.initColors();
105 if(this._fillMaterial.hasProperty("color")) {
106 this._fillMaterial.setProperty( "color", this._fillColor );
107 } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) {
108 this._fillMaterial.setGradientData(this._fillColor.color);
109 }
110 }
111 } 93 }
112 }, 94 },
113 95
@@ -770,8 +752,8 @@ exports.Circle = Object.create(GeomObj, {
770 'fillColor' : this._fillColor, 752 'fillColor' : this._fillColor,
771 'innerRadius' : this._innerRadius, 753 'innerRadius' : this._innerRadius,
772 'strokeStyle' : this._strokeStyle, 754 'strokeStyle' : this._strokeStyle,
773 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 755 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : null,
774 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 756 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : null,
775 'materials' : this.exportMaterialsJSON() 757 'materials' : this.exportMaterialsJSON()
776 }; 758 };
777 759
@@ -790,27 +772,26 @@ exports.Circle = Object.create(GeomObj, {
790 this._fillColor = jObj.fillColor; 772 this._fillColor = jObj.fillColor;
791 this._innerRadius = jObj.innerRadius; 773 this._innerRadius = jObj.innerRadius;
792 this._strokeStyle = jObj.strokeStyle; 774 this._strokeStyle = jObj.strokeStyle;
793 var strokeMaterialName = jObj.strokeMat;
794 var fillMaterialName = jObj.fillMat;
795 775
796 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); 776 if(jObj.strokeMat) {
797 if (!strokeMat) { 777 var strokeMat = MaterialsModel.getMaterial(jObj.strokeMat).dup();
798 console.log( "object material not found in library: " + strokeMaterialName ); 778 if (!strokeMat) {
799 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 779 console.log("object material not found in library: " + jObj.strokeMat);
780 } else {
781 this._strokeMaterial = strokeMat;
782 }
800 } 783 }
801 this._strokeMaterial = strokeMat; 784
802 if (this._strokeMaterial.hasProperty( 'color' )) 785 if(jObj.fillMat) {
803 this._strokeMaterial.setProperty( 'color', this._strokeColor ); 786 var fillMat = MaterialsModel.getMaterial(jObj.fillMat).dup();
804 787 if (!fillMat) {
805 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); 788 console.log("object material not found in library: " + jObj.fillMat);
806 if (!fillMat) { 789 } else {
807 console.log( "object material not found in library: " + fillMaterialName ); 790 this._fillMaterial = fillMat;
808 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 791 }
809 } 792 }
810 this._fillMaterial = fillMat;
811 if (this._fillMaterial.hasProperty( 'color' ))
812 this._fillMaterial.setProperty( 'color', this._fillColor );
813 793
794 this.initColors();
814 this.importMaterialsJSON( jObj.materials ); 795 this.importMaterialsJSON( jObj.materials );
815 } 796 }
816 }, 797 },
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index 3cd3a89b..7b4e49fa 100755
--- a/js/lib/geom/geom-obj.js
+++ b/