aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-07-23 17:15:47 -0700
committerJose Antonio Marquez2012-07-23 17:15:47 -0700
commit6908422084dbfef5420e1a9ce584d56aad9a2c14 (patch)
treec5e74cc54e1d4d38ee08378998ce1c93453489b3 /js/lib
parentafc7ad4f240fdf7890a79c2d4d7f8eb2e7c30a34 (diff)
parenta3f04ac0a68e428017dc51a1ba28c33f250adaf6 (diff)
downloadninja-6908422084dbfef5420e1a9ce584d56aad9a2c14.tar.gz
Merge branch 'refs/heads/Ninja-Master' into Document
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/rdge/materials/material.js4
4 files changed, 46 insertions, 3 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/rdge/materials/material.js b/js/lib/rdge/materials/material.js
index e8571e9d..227a772a 100755
--- a/js/lib/rdge/materials/material.js
+++ b/js/lib/rdge/materials/material.js
@@ -263,6 +263,10 @@ var Material = function GLMaterial( world ) {
263 var material = this._materialNode; 263 var material = this._materialNode;
264 if (material) technique = material.shaderProgram[this.getTechniqueName()]; 264 if (material) technique = material.shaderProgram[this.getTechniqueName()];
265 265
266 // make sure RDGE has the correct context
267 if (this.getWorld())
268 RDGE.globals.engine.setContext( this.getWorld().getCanvas().rdgeid );
269
266 if(prop === "gradient") { 270 if(prop === "gradient") {
267 this.setGradientData(value); 271 this.setGradientData(value);
268 } else { 272 } else {