aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/canvas-runtime.js2
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/MeshManager.js22
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/renderer.js4
-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
-rwxr-xr-xjs/tools/modifier-tool-base.js4
8 files changed, 75 insertions, 6 deletions
diff --git a/assets/canvas-runtime.js b/assets/canvas-runtime.js
index 4181dd89..7c2554df 100644
--- a/assets/canvas-runtime.js
+++ b/assets/canvas-runtime.js
@@ -289,7 +289,7 @@ NinjaCvsRt.GLRuntime = Object.create(Object.prototype, {
289 this.renderer.cameraManager().setActiveCamera(cam); 289 this.renderer.cameraManager().setActiveCamera(cam);
290 290
291 // change clear color 291 // change clear color
292 this.renderer.setClearColor([1.0, 1.0, 1.0, 0.0]); 292 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]);
293 293
294 // create an empty scene graph 294 // create an empty scene graph
295 this.myScene = new RDGE.SceneGraph(); 295 this.myScene = new RDGE.SceneGraph();
diff --git a/js/helper-classes/RDGE/src/core/script/MeshManager.js b/js/helper-classes/RDGE/src/core/script/MeshManager.js
index 4ff95cc4..f0600793 100755
--- a/js/helper-classes/RDGE/src/core/script/MeshManager.js
+++ b/js/helper-classes/RDGE/src/core/script/MeshManager.js
@@ -201,11 +201,31 @@ RDGE.MeshManager.prototype.onLoaded = function (meshName) {
201}; 201};
202 202
203RDGE.MeshManager.prototype.exportJSON = function () { 203RDGE.MeshManager.prototype.exportJSON = function () {
204
204 for (var m in this.modelMap) { 205 for (var m in this.modelMap) {
205 this.modelMap[m].primitive.built = false; 206 this.modelMap[m].primitive.built = false;
206 } 207 }
207 208
208 return JSON.stringify(this.modelMap); 209 function replacer(key, value) {
210 if (key === "bufferStreams")
211 {
212 var nStreams = value.length;
213 for (iStream=0; iStream<nStreams; iStream++)
214 {
215 var arr = value[iStream];
216 var n = arr.length;
217 for (var i=0; i<n; i++)
218 {
219 var val = arr[i];
220 arr[i] = val.toFixed ? Number(val.toFixed(4)) : val;
221 }
222 }
223 }
224
225 return value;
226 }
227
228 return JSON.stringify(this.modelMap, replacer);
209}; 229};
210 230
211RDGE.MeshManager.prototype.importJSON = function (jsonMeshExport) { 231RDGE.MeshManager.prototype.importJSON = function (jsonMeshExport) {
diff --git a/js/helper-classes/RDGE/src/core/script/renderer.js b/js/helper-classes/RDGE/src/core/script/renderer.js
index 889cd62e..52158514 100755
--- a/js/helper-classes/RDGE/src/core/script/renderer.js
+++ b/js/helper-classes/RDGE/src/core/script/renderer.js
@@ -363,6 +363,8 @@ RDGE._renderer = function (canvas) {
363 if (mips === undefined) 363 if (mips === undefined)
364 mips = true; 364 mips = true;
365 365
366 //console.log( "createTexture " + url + ", unloadedCount: " + this.unloadedTextureCount + ", world " + RDGE.globals.engine.getContext().renderer._world._worldCount );
367
366 if (texture) { 368 if (texture) {
367 texture.image = new Image(); 369 texture.image = new Image();
368 texture.image.src = url; 370 texture.image.src = url;
@@ -380,7 +382,7 @@ RDGE._renderer = function (canvas) {
380 texture.image.onerror = function () { 382 texture.image.onerror = function () {
381 this.context.renderer.unloadedTextureCount--; 383 this.context.renderer.unloadedTextureCount--;
382 if (texture.callback) texture.callback(texture); 384 if (texture.callback) texture.callback(texture);
383 //console.log( "Error loading texture: " + texture.image.src ); 385 console.log( "Error loading texture: " + texture.image.src );
384 if (this.context.renderer.unloadedTextureCount < 0) 386 if (this.context.renderer.unloadedTextureCount < 0)
385 console.log("more textures loaded then created..."); 387 console.log("more textures loaded then created...");
386 }; 388 };
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 {
diff --git a/js/tools/modifier-tool-base.js b/js/tools/modifier-tool-base.js
index c772e36c..d12ba7d2 100755
--- a/js/tools/modifier-tool-base.js
+++ b/js/tools/modifier-tool-base.js
@@ -569,7 +569,11 @@ exports.ModifierToolBase = Montage.create(DrawingTool, {
569 var alignArray = new Array(); 569 var alignArray = new Array();
570 snapManager.snapA