From 903b01b9d0501e6f974034273385a0517107b1e3 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Tue, 27 Mar 2012 12:42:42 -0700 Subject: File IO for the brush stroke AND changing the data type of brush stroke from GEOM_TYPE_CUBIC_BEZIER to GEOM_TYPE_BRUSH_STROKE --- js/lib/drawing/world.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 781695b6..1552178d 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -931,6 +931,7 @@ World.prototype.importObjectsJSON = function( jObj, parentGeomObj ) World.prototype.importObjectJSON = function( jObj, parentGeomObj ) { var type = jObj.type; + var BrushStroke = require("js/lib/geom/brush-stroke").BrushStroke; var obj; switch (type) @@ -950,6 +951,11 @@ World.prototype.importObjectJSON = function( jObj, parentGeomObj ) obj.importJSON( jObj ); break; + case 6: //brush stroke + obj = new BrushStroke(); + obj.importJSON(jObj); + break; + default: throw new Error( "Unrecognized object type: " + type ); break; -- cgit v1.2.3 From 5b4f6b1618cf571a6bce5a631f976a008e04a64e Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 29 Mar 2012 15:52:08 -0700 Subject: Updated shapes to always check for its stroke and fill colors and materials instead of relying on the shapeModel cache because it can get out of sync. Signed-off-by: Nivesh Rajbhandari --- js/lib/drawing/world.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index fec6a478..1bf8c2e5 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -930,7 +930,7 @@ World.prototype.importObjectsJSON = function( jObj, parentGeomObj ) // determine if we have children if (jObj.children) { - var nKids = ojObjbj.chilodren.length; + var nKids = jObj.children.length; for (var i=0; i 0) { ctrTrNode = obj.getTransformNode(); if (ctrTrNode == null) { - ctrTrNode = createTransformNode("objRootNode_" + nodeCounter++); + ctrTrNode = RDGE.createTransformNode("objRootNode_" + nodeCounter++); this._rootNode.insertAsChild( ctrTrNode ); obj.setTransformNode( ctrTrNode ); } ctrTrNode.meshes.forEach(function(thisMesh) { - g_meshMan.deleteMesh(thisMesh.mesh.name); + RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name); }); ctrTrNode.meshes = []; @@ -416,11 +416,11 @@ World.prototype.updateObject = function (obj) { childTrNode = children[i-1].transformNode; childTrNode.meshes.forEach(function(thisMesh) { - g_meshMan.deleteMesh(thisMesh.mesh.name); + RDGE.globals.meshMan.deleteMesh(thisMesh.mesh.name); }); childTrNode.meshes = []; } else { - childTrNode = createTransformNode("objNode_" + nodeCounter++); + childTrNode = RDGE.createTransformNode("objNode_" + nodeCounter++); ctrTrNode.insertAsChild(childTrNode); } @@ -522,7 +522,7 @@ World.prototype.clearTree = function() { if (this._useWebGL) { var root = this._rootNode; root.children = new Array(); - g_Engine.unregisterCanvas( this._canvas.rdgeid ) + RDGE.globals.engine.unregisterCanvas( this._canvas.rdgeid ) this.update( 0 ); this.draw(); @@ -657,9 +657,9 @@ World.prototype.setMVMatrix = function() { gl.uniformMatrix4fv(this._shaderProgram.mvMatrixUniform, false, new Float32Array(mvMatrix)); var normalMatrix = mat3.create(); - // mat4.toInverseMat3(mvMatrix, normalMatrix); - // mat4.toInverseMat3(new Float32Array(mvMatrix.flatten()), normalMatrix); - mat4.toInverseMat3(new Float32Array(mvMatrix), normalMatrix); + // RDGE.mat4.toInverseMat3(mvMatrix, normalMatrix); + // RDGE.mat4.toInverseMat3(new Float32Array(mvMatrix.flatten()), normalMatrix); + RDGE.mat4.toInverseMat3(new Float32Array(mvMatrix), normalMatrix); mat3.transpose(normalMatrix); gl.uniformMatrix3fv(this._shaderProgram.nMatrixUniform, false, normalMatrix); } @@ -680,7 +680,7 @@ World.prototype.render = function() { var root = this.getGeomRoot(); this.hRender( root ); } else { - g_Engine.setContext( this._canvas.rdgeId ); + RDGE.globals.engine.setContext( this._canvas.rdgeId ); //this.draw(); this.restartRenderLoop(); } @@ -895,16 +895,16 @@ World.prototype.importSubObject = function( objStr, parentNode ) { i0 += 10; var matText = objStr.substr( i0, i1 - i0 ); var shaderDef = JSON.parse( matText ); - var shader = new jshader(); + var shader = new RDGE.jshader(); shader.def = shaderDef; shader.init(); // set the shader for this material - var matNode = createMaterialNode("objMat") + var matNode = RDGE.createMaterialNode("objMat") matNode.setShader(shader); // create the transformation node - var trNode = createTransformNode("subObjNode_" ); + var trNode = RDGE.createTransformNode("subObjNode_"); trNode.attachMeshNode(this.renderer.id + "_prim_", meshObj); trNode.attachMaterial(matNode); parentNode.insertAsChild(trNode); -- cgit v1.2.3 From b4ba63045158e108356e065c1237fb72b56473a5 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Tue, 3 Apr 2012 09:39:38 -0700 Subject: fixed remaining namespace bugs ensuring the use of the RDGE namespace everywhere it is required --- js/lib/drawing/world.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 436853bd..801c199a 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -901,8 +901,8 @@ World.prototype.importJSON = function( jObj ) rdgeStarted = true; var id = this._canvas.getAttribute( "data-RDGE-id" ); this._canvas.rdgeid = id; - g_Engine.registerCanvas(this._canvas, this); - RDGEStart( this._canvas ); + RDGE.globals.engine.registerCanvas(this._canvas, this); + RDGE.RDGEStart( this._canvas ); this._canvas.task.stop() } @@ -992,8 +992,8 @@ World.prototype.import = function( importStr ) { rdgeStarted = true; var id = this._canvas.getAttribute( "data-RDGE-id" ); this._canvas.rdgeid = id; - g_Engine.registerCanvas(this._canvas, this); - RDGEStart( this._canvas ); + RDGE.globals.engine.registerCanvas(this._canvas, this); + RDGE.RDGEStart( this._canvas ); this._canvas.task.stop() } -- cgit v1.2.3 From 18609d375e7aab9cb48c9b3f5b291f85cbd28683 Mon Sep 17 00:00:00 2001 From: John Mayhew Date: Tue, 3 Apr 2012 13:39:32 -0700 Subject: removed old unused import and export functions. --- js/lib/drawing/world.js | 400 ++++++++++++------------------------------------ 1 file changed, 101 insertions(+), 299 deletions(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 801c199a..ae8c2cce 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -435,38 +435,38 @@ World.prototype.updateObject = function (obj) { } }; -World.prototype.addObject = function( obj ) { - if (!obj) return; +World.prototype.addObject = function (obj) { + if (!obj) return; try { // undefine all the links of the object - obj.setChild( undefined ); - obj.setNext( undefined ); - obj.setPrev( undefined ); - obj.setParent( undefined ); + obj.setChild(undefined); + obj.setNext(undefined); + obj.setPrev(undefined); + obj.setParent(undefined); - obj.setWorld( this ); + obj.setWorld(this); if (this._geomRoot == null) { this._geomRoot = obj; } else { var go = this._geomRoot; - while (go.getNext()) go = go.getNext(); - go.setNext( obj ); - obj.setPrev( go ); + while (go.getNext()) go = go.getNext(); + go.setNext(obj); + obj.setPrev(go); } - // build the WebGL buffers - if (this._useWebGL) { - obj.buildBuffers(); - this.restartRenderLoop(); - } + // build the WebGL buffers + if (this._useWebGL) { + obj.buildBuffers(); + this.restartRenderLoop(); + } } - catch(e) { - alert( "Exception in GLWorld.addObject " + e ); + catch (e) { + alert("Exception in GLWorld.addObject " + e); } -} +}; World.prototype.restartRenderLoop = function() { //console.log( "restartRenderLoop" ); @@ -734,146 +734,76 @@ World.prototype.getShapeFromPoint = function( offsetX, offsetY ) { -World.prototype.exportJSON = function() -{ - // world properties - var worldObj = +World.prototype.exportJSON = function () { + // world properties + var worldObj = { - 'version' : 1.1, - 'id' : this.getCanvas().getAttribute( "data-RDGE-id" ), - 'fov' : this._fov, - 'zNear' : this._zNear, - 'zFar' : this._zFar, - 'viewDist' : this._viewDist, - 'webGL' : this._useWebGL + 'version': 1.1, + 'id': this.getCanvas().getAttribute("data-RDGE-id"), + 'fov': this._fov, + 'zNear': this._zNear, + 'zFar': this._zFar, + 'viewDist': this._viewDist, + 'webGL': this._useWebGL }; - // RDGE scenegraph - if (this._useWebGL) - worldObj.scenedata = this.myScene.exportJSON(); + // RDGE scenegraph + if (this._useWebGL) + worldObj.scenedata = this.myScene.exportJSON(); - // object data - var strArray = []; - this.exportObjectsJSON( this._geomRoot, worldObj ); + // object data + var strArray = []; + this.exportObjectsJSON(this._geomRoot, worldObj); - // You would think that the RDGE export function - // would not be destructive of the data. You would be wrong... - // We need to rebuild everything - if (this._useWebGL) - { - if (worldObj.children && (worldObj.children.length === 1)) - { + // You would think that the RDGE export function + // would not be destructive of the data. You would be wrong... + // We need to rebuild everything + if (this._useWebGL) { + if (worldObj.children && (worldObj.children.length === 1)) { this.rebuildTree(this._geomRoot); this.restartRenderLoop(); - } - } - - // convert the object to a string - var jStr = JSON.stringify( worldObj ); - - // prepend some version information to the string. - // this string is also used to differentiate between JSON - // and pre-JSON versions of fileIO. - // the ending ';' in the version string is necessary - jStr = "v1.0;" + jStr; - - return jStr; -} - -World.prototype.rebuildTree = function( obj ) -{ - if (!obj) return; - - obj.buildBuffers(); - - if (obj.getChild()) { - this.rebuildTree( obj.getChild () ); + } } - if (obj.getNext()) - this.rebuildTree( obj.getNext() ); -} - -World.prototype.exportObjectsJSON = function( obj, parentObj ) -{ - if (!obj) return; - - var jObj = obj.exportJSON(); - if (!parentObj.children) parentObj.children = []; - parentObj.children.push( jObj ); + // convert the object to a string + var jStr = JSON.stringify(worldObj); - if (obj.getChild()) { - this.exportObjectsJSON( obj.getChild (), jObj ); - } + // prepend some version information to the string. + // this string is also used to differentiate between JSON + // and pre-JSON versions of fileIO. + // the ending ';' in the version string is necessary + jStr = "v1.0;" + jStr; - if (obj.getNext()) - this.exportObjectsJSON( obj.getNext(), parentObj ); -} + return jStr; +}; -/* -World.prototype.export = function() -{ - var exportStr = "GLWorld 1.0\n"; - var id = this.getCanvas().getAttribute( "data-RDGE-id" ); - exportStr += "id: " + id + "\n"; - //exportStr += "id: " + this._canvas.rdgeid + "\n"; - exportStr += "fov: " + this._fov + "\n"; - 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; - //if (!exportForPublish) exportForPublish = false; - var exportForPublish = true; - exportStr += "publish: " + exportForPublish + "\n"; - - if (exportForPublish && this._useWebGL) - { - exportStr += "scenedata: " + this.myScene.exportJSON() + "endscene\n"; +World.prototype.rebuildTree = function (obj) { + if (!obj) return; - // write out all of the objects - exportStr += "tree\n"; - exportStr += this.exportObjects( this._geomRoot ); - exportStr += "endtree\n"; - } - else - { - // output the material library - //exportStr += MaterialsLibrary.export(); // THIS NEEDS TO BE DONE AT THE DOC LEVEL + obj.buildBuffers(); - // write out all of the objects - exportStr += "tree\n"; - exportStr += this.exportObjects( this._geomRoot ); - exportStr += "endtree\n"; - } + if (obj.getChild()) { + this.rebuildTree(obj.getChild()); + } - return exportStr; + if (obj.getNext()) + this.rebuildTree(obj.getNext()); }; -World.prototype.exportObjects = function( obj ) { - if (!obj) return; +World.prototype.exportObjectsJSON = function (obj, parentObj) { + if (!obj) return; - var rtnStr = "OBJECT\n"; - rtnStr += obj.export(); + var jObj = obj.exportJSON(); + if (!parentObj.children) parentObj.children = []; + parentObj.children.push(jObj); - if (obj.getChild()) { - rtnStr += this.exportObjects( obj.getChild () ); + if (obj.getChild()) { + this.exportObjectsJSON(obj.getChild(), jObj); } - // the end object goes outside the children - rtnStr += "ENDOBJECT\n"; - - if (obj.getNext()) { - rtnStr += this.exportObjects( obj.getNext() ); - } - - return rtnStr; + if (obj.getNext()) + this.exportObjectsJSON(obj.getNext(), parentObj); }; -*/ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) { //if (trNode == null) trNode = this._ctrNode; @@ -893,51 +823,45 @@ World.prototype.findTransformNodeByMaterial = function( materialNode, trNode ) return rtnNode; }; -World.prototype.importJSON = function( jObj ) -{ - if (jObj.webGL) - { - // start RDGE - rdgeStarted = true; - var id = this._canvas.getAttribute( "data-RDGE-id" ); - this._canvas.rdgeid = id; - RDGE.globals.engine.registerCanvas(this._canvas, this); - RDGE.RDGEStart( this._canvas ); - this._canvas.task.stop() - } +World.prototype.importJSON = function (jObj) { + if (jObj.webGL) { + // start RDGE + rdgeStarted = true; + var id = this._canvas.getAttribute("data-RDGE-id"); + this._canvas.rdgeid = id; + RDGE.globals.engine.registerCanvas(this._canvas, this); + RDGE.RDGEStart(this._canvas); + this._canvas.task.stop() + } - // import the objects - // there should be exactly one child of the parent object - if (jObj.children && (jObj.children.length === 1)) - this.importObjectsJSON( jObj.children[0] ); - else - throw new Error ("unrecoverable canvas import error - inconsistent root object: " + jObj.children ); + // import the objects + // there should be exactly one child of the parent object + if (jObj.children && (jObj.children.length === 1)) + this.importObjectsJSON(jObj.children[0]); + else + throw new Error("unrecoverable canvas import error - inconsistent root object: " + jObj.children); - if (!this._useWebGL) - { - // render using canvas 2D - this.render(); - } - else - this.restartRenderLoop(); -} + if (!this._useWebGL) { + // render using canvas 2D + this.render(); + } + else + this.restartRenderLoop(); +}; -World.prototype.importObjectsJSON = function( jObj, parentGeomObj ) -{ - // read the next object - var gObj = this.importObjectJSON( jObj, parentGeomObj ); +World.prototype.importObjectsJSON = function (jObj, parentGeomObj) { + // read the next object + var gObj = this.importObjectJSON(jObj, parentGeomObj); - // determine if we have children - if (jObj.children) - { - var nKids = ojObjbj.chilodren.length; - for (var i=0; i= 0) - if (this._useWebGL) - { - // start RDGE - rdgeStarted = true; - var id = this._canvas.getAttribute( "data-RDGE-id" ); - this._canvas.rdgeid = id; - RDGE.globals.engine.registerCanvas(this._canvas, this); - RDGE.RDGEStart( this._canvas ); - this._canvas.task.stop() - } - - this.importObjects( importStr, this._rootNode ); - - if (!this._useWebGL) - { - // render using canvas 2D - this.render(); - } -}; - -World.prototype.importObjects = function( importStr, parentNode ) { - var index = importStr.indexOf( "OBJECT\n", 0 ); - while (index >= 0) { - // update the string to the current object - importStr = importStr.substr( index+7 ); - - // read the next object - this.importObject( importStr, parentNode ); - - // determine if we have children - var endIndex = importStr.indexOf( "ENDOBJECT\n" ), - childIndex = importStr.indexOf( "OBJECT\n" ); - if (endIndex < 0) throw new Error( "ill-formed object data" ); - if ((childIndex >= 0) && (childIndex < endIndex)) { - importStr = importStr.substr( childIndex + 7 ); - importStr = this.importObjects( importStr, node ); - endIndex = importStr.indexOf( "ENDOBJECT\n" ) - } - - // remove the string for the object(s) just created - importStr = importStr.substr( endIndex ); - - // get the location of the next object - index = importStr.indexOf( "OBJECT\n", endIndex ); - } - - return importStr; -}; - -World.prototype.importObject = function( objStr, parentNode ) { - var go = new GeomObj(); - var type = Number( go.getPropertyFromString( "type: ", objStr ) ); - - var obj; - switch (type) - { - case 1: - obj = new Rectangle(); - obj.import( objStr ); - break; - - case 2: // circle - obj = new Circle(); - obj.import( objStr ); - break; - - case 3: // line - obj = new Line(); - obj.import( objStr ); - break; - - default: - throw new Error( "Unrecognized object type: " + type ); - break; - } - - if (obj) { - this.addObject( obj ); - } -}; - -World.prototype.importSubObject = function( objStr, parentNode ) { - // get the mesh text - var i0 = objStr.indexOf( "mesh: " ), - i1 = objStr.indexOf( "endMesh\n" ); - if ((i0 < 0) || (i1 < 0)) throw new Error( "ill-formed sub object" ); - i0 += 6; - var meshText = objStr.substr( i0, i1 - i0 ); - var meshObj = JSON.parse(meshText); - - // get the material text - var i0 = objStr.indexOf( "material: " ), - i1 = objStr.indexOf( "endMat\n" ); - if ((i0 < 0) || (i1 < 0)) throw new Error( "ill-formed sub object" ); - i0 += 10; - var matText = objStr.substr( i0, i1 - i0 ); - var shaderDef = JSON.parse( matText ); - var shader = new RDGE.jshader(); - shader.def = shaderDef; - shader.init(); - - // set the shader for this material - var matNode = RDGE.createMaterialNode("objMat") - matNode.setShader(shader); - - // create the transformation node - var trNode = RDGE.createTransformNode("subObjNode_"); - trNode.attachMeshNode(this.renderer.id + "_prim_", meshObj); - trNode.attachMaterial(matNode); - parentNode.insertAsChild(trNode); - - return trNode; -}; - if (typeof exports === "object") { exports.World = World; } \ No newline at end of file -- cgit v1.2.3 From a11ef2eed7049835c8bdfa50a2b893632c46eaa0 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 4 Apr 2012 11:11:58 -0700 Subject: Squashed commit of Preparing for the montage undo-manager: Architecture changes Reworked the add and remove elements into 1 function which can take 1 or more elements. Removed the _element from the selection array Many other changes related to those 2 changes Undo/Redo shortcuts are now using montage undo/redo manager. Signed-off-by: Valerio Virgillito --- js/lib/drawing/world.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'js/lib/drawing/world.js') diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 5a054224..e348f5e8 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js @@ -527,7 +527,7 @@ World.prototype.clearTree = function() { if (this._useWebGL) { var root = this._rootNode; root.children = new Array(); - g_Engine.unregisterCanvas( this._canvas.rdgeid ) + g_Engine.unregisterCanvas( this._canvas.rdgeid ); this.update( 0 ); this.draw(); @@ -540,8 +540,9 @@ World.prototype.updateMaterials = function( obj, time ) { var matArray = obj.getMaterialArray(); if (matArray) { var n = matArray.length; - for (var i=0; i