From 818582d389f504c915be0c9052fafa33e3e76c92 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 7 Mar 2012 16:48:48 -0800 Subject: File IO --- js/lib/drawing/world.js | 90 +++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 37 deletions(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 3d6c6fc4..b8bceda6 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -4,17 +4,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -// Useless Global variables. -// TODO: Remove this as soon as QE test pass -/* -var shaderProgramArray = new Array; -var glContextArray = new Array; -var vertexShaderSource = ""; -var fragmentShaderSource = ""; -var rdgeStarted = false; -*/ - -var nodeCounter = 0; var GeomObj = require("js/lib/geom/geom-obj").GeomObj; var Line = require("js/lib/geom/line").Line; @@ -22,6 +11,8 @@ var Rectangle = require("js/lib/geom/rectangle").Rectangle; var Circle = require("js/lib/geom/circle").Circle; var MaterialsModel = require("js/models/materials-model").MaterialsModel; +var worldCounter = 0; + /////////////////////////////////////////////////////////////////////// // Class GLWorld // Manages display in a canvas @@ -76,6 +67,12 @@ var World = function GLWorld( canvas, use3D ) { // no animated materials this._firstRender = true; + this._worldCount = worldCounter; + worldCounter++; + + // keep a counter for generating node names + this._nodeCounter = 0; + /////////////////////////////////////////////////////////////////////// // Property accessors /////////////////////////////////////////////////////////////////////// @@ -350,9 +347,12 @@ var World = function GLWorld( canvas, use3D ) { return false; }; - - // END RDGE - //////////////////////////////////////////////////////////////////////////////////// + this.generateUniqueNodeID = function() + { + var str = String( this._nodeCounter ); + this._nodeCounter++; + return str; + } // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state @@ -391,7 +391,7 @@ World.prototype.updateObject = function (obj) { if (nPrims > 0) { ctrTrNode = obj.getTransformNode(); if (ctrTrNode == null) { - ctrTrNode = createTransformNode("objRootNode_" + nodeCounter++); + ctrTrNode = createTransformNode("objRootNode_" + this._nodeCounter++); this._rootNode.insertAsChild( ctrTrNode ); obj.setTransformNode( ctrTrNode ); } @@ -401,7 +401,7 @@ World.prototype.updateObject = function (obj) { }); ctrTrNode.meshes = []; - ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + nodeCounter++, prims[0]); + ctrTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prims[0]); ctrTrNode.attachMaterial(materialNodes[0]); } @@ -420,12 +420,12 @@ World.prototype.updateObject = function (obj) { }); childTrNode.meshes = []; } else { - childTrNode = createTransformNode("objNode_" + nodeCounter++); + childTrNode = createTransformNode("objNode_" + this._nodeCounter++); ctrTrNode.insertAsChild(childTrNode); } // attach the instanced box goe - childTrNode.attachMeshNode(this.renderer.id + "_prim_" + nodeCounter++, prim); + childTrNode.attachMeshNode(this.renderer.id + "_prim_" + this._nodeCounter++, prim); childTrNode.attachMaterial(materialNodes[i]); } }; @@ -727,7 +727,7 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { } }; -World.prototype.export = function() { +World.prototype.export = function( exportForPublish ) { var exportStr = "GLWorld 1.0\n"; var id = this.getCanvas().getAttribute( "data-RDGE-id" ); exportStr += "id: " + id + "\n"; @@ -736,17 +736,28 @@ World.prototype.export = function() { exportStr += "zNear: " + this._zNear + "\n"; exportStr += "zFar: " + this._zFar + "\n"; exportStr += "viewDist: " + this._viewDist + "\n"; + if (this._useWebGL) + exportStr += "webGL: true\n"; // we need 2 export modes: One for save/restore, one for publish. // hardcoding for now - var exportForPublish = false; + //var exportForPublish = false; + if (!exportForPublish) exportForPublish = false; exportStr += "publish: " + exportForPublish + "\n"; - if (exportForPublish) { + if (exportForPublish && this._useWebGL) + { exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; - } else { + + // write out all of the objects + exportStr += "tree\n"; + exportStr += this.exportObjects( this._geomRoot ); + exportStr += "endtree\n"; + } + else + { // output the material library - exportStr += MaterialsModel.exportMaterials(); + //exportStr += MaterialsLibrary.export(); // THIS NEEDS TO BE DONE AT THE DOC LEVEL // write out all of the objects exportStr += "tree\n"; @@ -800,21 +811,26 @@ World.prototype.import = function( importStr ) { // determine if the data was written for export (no Ninja objects) // or for save/restore - var index = importStr.indexOf( "scenedata: " ); - if (index >= 0) { - var rdgeStr = importStr.substr( index+11 ); - var endIndex = rdgeStr.indexOf( "endscene\n" ); - if (endIndex < 0) throw new Error( "ill-formed WebGL data" ); - var len = endIndex - index + 11; - rdgeStr = rdgeStr.substr( 0, endIndex ); - - this.myScene.importJSON( rdgeStr ); - } else { - // load the material library - importStr = MaterialsModel.importMaterials( importStr ); + //var index = importStr.indexOf( "scenedata: " ); + var index = importStr.indexOf( "webGL: " ); + this._useWebGL = (index >= 0) + if (this._useWebGL) + { + // start RDGE + rdgeStarted = true; + var id = this._canvas.getAttribute( "data-RDGE-id" ); + this._canvas.rdgeid = id; + g_Engine.registerCanvas(this._canvas, this); + RDGEStart( this._canvas ); + this._canvas.task.stop() + } + + this.importObjects( importStr, this._rootNode ); - // import the objects - this.importObjects( importStr, this._rootNode ); + if (!this._useWebGL) + { + // render using canvas 2D + this.render(); } }; -- cgit v1.2.3 From 7b6e8194b91168abdeb94702eb350d14f147858b Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 8 Mar 2012 17:29:18 -0800 Subject: Canvas IO --- js/lib/drawing/world.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index b8bceda6..cffd0083 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -349,7 +349,7 @@ var World = function GLWorld( canvas, use3D ) { this.generateUniqueNodeID = function() { - var str = String( this._nodeCounter ); + var str = "" + this._nodeCounter; this._nodeCounter++; return str; } @@ -727,7 +727,8 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { } }; -World.prototype.export = function( exportForPublish ) { +World.prototype.export = function( imagePath ) +{ var exportStr = "GLWorld 1.0\n"; var id = this.getCanvas().getAttribute( "data-RDGE-id" ); exportStr += "id: " + id + "\n"; @@ -742,9 +743,17 @@ World.prototype.export = function( exportForPublish ) { // we need 2 export modes: One for save/restore, one for publish. // hardcoding for now //var exportForPublish = false; - if (!exportForPublish) exportForPublish = false; + //if (!exportForPublish) exportForPublish = false; + var exportForPublish = true; exportStr += "publish: " + exportForPublish + "\n"; + // the relative path for local assets needs to be modified to + // the path specified by argument 'imagePath'. Save that path + // so exporting functions can call newPath = world.cleansePath( oldPath ); + this._imagePath = imagePath.slice(); + var endchar = this._imagePath[this._imagePath.length-1] + if (endchar != '/') this._imagePath += '/'; + if (exportForPublish && this._useWebGL) { exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; @@ -928,6 +937,20 @@ World.prototype.importSubObject = function( objStr, parentNode ) { return trNode; }; +World.prototype.cleansePath = function( url ) +{ + //this._imagePath + var searchStr = "assets/"; + var index = url.indexOf( searchStr ); + var rtnPath = url; + if (index >= 0) + { + rtnPath = url.substr( index + searchStr.length ); + rtnPath = this._imagePath + rtnPath; + } + return rtnPath; +} + if (typeof exports === "object") { exports.World = World; } \ No newline at end of file -- cgit v1.2.3 From 86784888a98a05523dbedcbe32fd4dea336878e7 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 9 Mar 2012 08:21:13 -0800 Subject: Eyedropper support for getting color value from webgl shapes. Signed-off-by: Nivesh Rajbhandari --- js/lib/drawing/world.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 3d6c6fc4..04e4d96b 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -26,7 +26,7 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel; // Class GLWorld // Manages display in a canvas /////////////////////////////////////////////////////////////////////// -var World = function GLWorld( canvas, use3D ) { +var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { /////////////////////////////////////////////////////////////////////// // Instance variables /////////////////////////////////////////////////////////////////////// @@ -39,7 +39,11 @@ var World = function GLWorld( canvas, use3D ) { this._canvas = canvas; if (this._useWebGL) { - this._glContext = canvas.getContext("experimental-webgl"); + if(preserveDrawingBuffer) { + this._glContext = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true}); + } else { + this._glContext = canvas.getContext("experimental-webgl"); + } } else { this._2DContext = canvas.getContext( "2d" ); } @@ -680,7 +684,7 @@ World.prototype.render = function() { var root = this.getGeomRoot(); this.hRender( root ); } else { - g_Engine.setContext( this._canvas.rdgeId ); + g_Engine.setContext( this._canvas.rdgeid ); //this.draw(); this.restartRenderLoop(); } -- cgit v1.2.3 From e92a6da7b84c58803489d70efedf74837ddfe4cd Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 9 Mar 2012 13:34:09 -0800 Subject: Removed asset path replacement at authortime. --- js/lib/drawing/world.js | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index cffd0083..44c9e37d 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -727,7 +727,7 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { } }; -World.prototype.export = function( imagePath ) +World.prototype.export = function() { var exportStr = "GLWorld 1.0\n"; var id = this.getCanvas().getAttribute( "data-RDGE-id" ); @@ -747,13 +747,6 @@ World.prototype.export = function( imagePath ) var exportForPublish = true; exportStr += "publish: " + exportForPublish + "\n"; - // the relative path for local assets needs to be modified to - // the path specified by argument 'imagePath'. Save that path - // so exporting functions can call newPath = world.cleansePath( oldPath ); - this._imagePath = imagePath.slice(); - var endchar = this._imagePath[this._imagePath.length-1] - if (endchar != '/') this._imagePath += '/'; - if (exportForPublish && this._useWebGL) { exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; @@ -937,20 +930,6 @@ World.prototype.importSubObject = function( objStr, parentNode ) { return trNode; }; -World.prototype.cleansePath = function( url ) -{ - //this._imagePath - var searchStr = "assets/"; - var index = url.indexOf( searchStr ); - var rtnPath = url; - if (index >= 0) - { - rtnPath = url.substr( index + searchStr.length ); - rtnPath = this._imagePath + rtnPath; - } - return rtnPath; -} - if (typeof exports === "object") { exports.World = World; } \ No newline at end of file -- cgit v1.2.3 From ca985ed7031af3f4e76d26fd5b99846620fc5733 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 13 Mar 2012 18:11:48 -0700 Subject: Some code cleanup - removing unused assignments. Signed-off-by: Valerio Virgillito --- js/lib/drawing/world.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index df24f556..049145ce 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -351,20 +351,18 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { return false; }; - this.generateUniqueNodeID = function() - { + this.generateUniqueNodeID = function() { var str = "" + this._nodeCounter; this._nodeCounter++; return str; - } + }; // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state // in the case of a procedurally built scene an init state is not needed for loading data if (this._useWebGL) { rdgeStarted = true; - var id = this._canvas.getAttribute( "data-RDGE-id" ); - this._canvas.rdgeid = id; + this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); g_Engine.registerCanvas(this._canvas, this); RDGEStart( this._canvas ); this._canvas.task.stop() -- cgit v1.2.3