From 486d9a31a85dd833a1c798049a00403756703034 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 6 Feb 2012 11:35:49 -0800 Subject: Support use WebGL checkbox in the PI. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 5efbccd0..48072309 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -76,6 +76,7 @@ exports.ShapesController = Montage.create(CanvasController, { case "fillMaterial": case "border": case "background": + case "useWebGl": return this.getShapeProperty(el, p); default: return CanvasController.getProperty(el, p); -- cgit v1.2.3 From 5737864d1d55d96e3cc3c1bc9b38ec58303b3981 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 6 Feb 2012 13:35:30 -0800 Subject: Allow users to switch between 2d and webGL mode. Note that this doesn't currently work. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 48072309..22ba66b3 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -56,6 +56,10 @@ exports.ShapesController = Montage.create(CanvasController, { el.elementModel.shapeModel.GLWorld.setViewportFromCanvas(el); el.elementModel.shapeModel.GLGeomObj.buildBuffers(); break; + case "useWebGl": + this.toggleWebGlMode(el, value); + el.elementModel.shapeModel.GLGeomObj.buildBuffers(); + break; default: CanvasController.setProperty(el, p, value); } @@ -276,6 +280,60 @@ exports.ShapesController = Montage.create(CanvasController, { { return (el.elementModel && el.elementModel.isShape); } + }, + + toggleWebGlMode: { + value: function(el, useWebGl) + { + if(useWebGl) + { + this.convertToWebGlWorld(el); + } + else + { + this.convertTo2DWorld(el); + } + } + }, + + convertToWebGlWorld: { + value: function(el) + { + if(el.elementModel.shapeModel.useWebGl) + { + return; + } + var world, + worldData = el.elementModel.shapeModel.GLWorld.export(); + if(worldData) + { + world = new GLWorld(el, true); + el.elementModel.shapeModel.GLWorld = world; + el.elementModel.shapeModel.useWebGl = true; + world.import(worldData); + } + + } + }, + + convertTo2DWorld: { + value: function(el) + { + if(!el.elementModel.shapeModel.useWebGl) + { + return; + } + var world, + worldData = el.elementModel.shapeModel.GLWorld.export(); + if(worldData) + { + world = new GLWorld(el, false); + el.elementModel.shapeModel.GLWorld = world; + el.elementModel.shapeModel.useWebGl = false; + world.import(worldData); + } + + } } }); -- cgit v1.2.3 From f94b0c5ada403379b3ff8a900c2a2aabcecce49e Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 6 Feb 2012 14:03:40 -0800 Subject: Add enabled property for ComboBox to support enabling/disabling materials dropdowns in the PI. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 22ba66b3..74c88084 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -57,8 +57,9 @@ exports.ShapesController = Montage.create(CanvasController, { el.elementModel.shapeModel.GLGeomObj.buildBuffers(); break; case "useWebGl": - this.toggleWebGlMode(el, value); - el.elementModel.shapeModel.GLGeomObj.buildBuffers(); +// this.toggleWebGlMode(el, value); +// el.elementModel.shapeModel.GLGeomObj.buildBuffers(); + el.elementModel.shapeModel.useWebGl = value; break; default: CanvasController.setProperty(el, p, value); -- cgit v1.2.3 From 75486be2839494c9b54833aff8f5eef3f9542151 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 6 Feb 2012 15:41:48 -0800 Subject: Support toggling between 2d and 3d canvas context. This requires us to create a new canvas with all the same values as the canvas being replaced and copying over all the shape data. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 74c88084..ed45710d 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -5,7 +5,8 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot */ var Montage = require("montage/core/core").Montage, - CanvasController = require("js/controllers/elements/canvas-controller").CanvasController; + CanvasController = require("js/controllers/elements/canvas-controller").CanvasController, + njModule = require("js/lib/NJUtils"); exports.ShapesController = Montage.create(CanvasController, { @@ -57,9 +58,11 @@ exports.ShapesController = Montage.create(CanvasController, { el.elementModel.shapeModel.GLGeomObj.buildBuffers(); break; case "useWebGl": -// this.toggleWebGlMode(el, value); -// el.elementModel.shapeModel.GLGeomObj.buildBuffers(); - el.elementModel.shapeModel.useWebGl = value; + var canvas = njModule.NJUtils.makeNJElement("canvas", "Canvas", "shape", el.className, true); + this.application.ninja.elementMediator.replaceElement(el, canvas); + el = canvas; + this.toggleWebGlMode(el, value); + el.elementModel.shapeModel.GLGeomObj.buildBuffers(); break; default: CanvasController.setProperty(el, p, value); -- cgit v1.2.3 From 92ae17bc800cf82cdbd1482ef1af1a5fd7bd632a Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 6 Feb 2012 16:35:12 -0800 Subject: Force layout canvas and SelectionController to update their info when a 2d canvas is replaced by a 3d canvas (and vice-versa). Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index ed45710d..3f1ccc3d 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -59,7 +59,11 @@ exports.ShapesController = Montage.create(CanvasController, { break; case "useWebGl": var canvas = njModule.NJUtils.makeNJElement("canvas", "Canvas", "shape", el.className, true); + canvas.width = el.width; + canvas.height = el.height; this.application.ninja.elementMediator.replaceElement(el, canvas); + NJevent("elementDeleted", el); + this.application.ninja.selectionController.selectElement(canvas); el = canvas; this.toggleWebGlMode(el, value); el.elementModel.shapeModel.GLGeomObj.buildBuffers(); -- cgit v1.2.3 From 8ad767b61460984a4031ba630f76ac8247a61857 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 7 Feb 2012 11:42:10 -0800 Subject: Fixed PI to support WebGL materials. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 3f1ccc3d..21373aca 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -68,6 +68,24 @@ exports.ShapesController = Montage.create(CanvasController, { this.toggleWebGlMode(el, value); el.elementModel.shapeModel.GLGeomObj.buildBuffers(); break; + case "strokeMaterial": + var sm = Object.create(MaterialsLibrary.getMaterial(value)); + if(sm) + { + el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(sm); + el.elementModel.shapeModel.strokeMaterial = sm; + el.elementModel.shapeModel.GLGeomObj.buildBuffers(); + } + break; + case "fillMaterial": + var fm = Object.create(MaterialsLibrary.getMaterial(value)); + if(fm) + { + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); + el.elementModel.shapeModel.strokeMaterial = fm; + el.elementModel.shapeModel.GLGeomObj.buildBuffers(); + } + break; default: CanvasController.setProperty(el, p, value); } @@ -84,12 +102,13 @@ exports.ShapesController = Montage.create(CanvasController, { case "trRadius": case "blRadius": case "brRadius": - case "strokeMaterial": - case "fillMaterial": case "border": case "background": case "useWebGl": return this.getShapeProperty(el, p); + case "strokeMaterial": + case "fillMaterial": + return this.getShapeProperty(el, p).getName(); default: return CanvasController.getProperty(el, p); } -- cgit v1.2.3 From 3a8875c288049b466bfeb8b7f0510fd8cbfb970d Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 7 Feb 2012 13:30:08 -0800 Subject: Supporting switching materials in the PI. Also, moved makeFillMaterial and makeStrokeMaterial functions into GLGeomObj so shapes other than GLRectangle can use these routines. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 21373aca..c6722dee 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -108,7 +108,15 @@ exports.ShapesController = Montage.create(CanvasController, { return this.getShapeProperty(el, p); case "strokeMaterial": case "fillMaterial": - return this.getShapeProperty(el, p).getName(); + var m = this.getShapeProperty(el, p); + if(m) + { + return this.getShapeProperty(el, p).getName(); + } + else + { + return "FlatMaterial"; + } default: return CanvasController.getProperty(el, p); } -- cgit v1.2.3 From e8e21367e59bb521801fe2e843f42ad5bca5ea9f Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Tue, 7 Feb 2012 13:52:54 -0800 Subject: Fixing some typos and undeclared variables in GLRectangle and ShapesController. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index c6722dee..e764de4e 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -82,7 +82,7 @@ exports.ShapesController = Montage.create(CanvasController, { if(fm) { el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); - el.elementModel.shapeModel.strokeMaterial = fm; + el.elementModel.shapeModel.fillMaterial = fm; el.elementModel.shapeModel.GLGeomObj.buildBuffers(); } break; -- cgit v1.2.3 From 2d68f944e93b201deb46015392e706b7a24201c9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 8 Feb 2012 14:24:48 -0800 Subject: Fixed several typos in Materials import/export code to support toggling between 2d and 3d shape modes. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index e764de4e..b9c033aa 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -63,11 +63,11 @@ exports.ShapesController = Montage.create(CanvasController, { canvas.height = el.height; this.application.ninja.elementMediator.replaceElement(el, canvas); NJevent("elementDeleted", el); - this.application.ninja.selectionController.selectElement(canvas); el = canvas; this.toggleWebGlMode(el, value); - el.elementModel.shapeModel.GLGeomObj.buildBuffers(); - break; + el.elementModel.shapeModel.GLWorld.render(); + this.application.ninja.selectionController.selectElement(el); + return; case "strokeMaterial": var sm = Object.create(MaterialsLibrary.getMaterial(value)); if(sm) @@ -338,13 +338,26 @@ exports.ShapesController = Montage.create(CanvasController, { { return; } - var world, + var sm, + fm, + world, worldData = el.elementModel.shapeModel.GLWorld.export(); if(worldData) { world = new GLWorld(el, true); el.elementModel.shapeModel.GLWorld = world; + el.elementModel.shapeModel.GLGeomObj.setWorld(world); el.elementModel.shapeModel.useWebGl = true; + sm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); + fm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); + if(sm && fm) + { + el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(sm); + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); + el.elementModel.shapeModel.strokeMaterial = sm; + el.elementModel.shapeModel.fillMaterial = fm; + el.elementModel.shapeModel.GLGeomObj.buildBuffers(); + } world.import(worldData); } @@ -365,6 +378,10 @@ exports.ShapesController = Montage.create(CanvasController, { world = new GLWorld(el, false); el.elementModel.shapeModel.GLWorld = world; el.elementModel.shapeModel.useWebGl = false; + el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(null); + el.elementModel.shapeModel.strokeMaterial = null; + el.elementModel.shapeModel.fillMaterial = null; world.import(worldData); } -- cgit v1.2.3 From 63e68c9ed57253994b7424dd03059064cc656e98 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 9 Feb 2012 15:52:45 -0800 Subject: Fixed switching between webGL and canvas 2d modes. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index b9c033aa..44723a1e 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -346,8 +346,10 @@ exports.ShapesController = Montage.create(CanvasController, { { world = new GLWorld(el, true); el.elementModel.shapeModel.GLWorld = world; - el.elementModel.shapeModel.GLGeomObj.setWorld(world); el.elementModel.shapeModel.useWebGl = true; + world.import(worldData); + el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); + sm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); fm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); if(sm && fm) @@ -356,9 +358,7 @@ exports.ShapesController = Montage.create(CanvasController, { el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); el.elementModel.shapeModel.strokeMaterial = sm; el.elementModel.shapeModel.fillMaterial = fm; - el.elementModel.shapeModel.GLGeomObj.buildBuffers(); } - world.import(worldData); } } @@ -378,13 +378,13 @@ exports.ShapesController = Montage.create(CanvasController, { world = new GLWorld(el, false); el.elementModel.shapeModel.GLWorld = world; el.elementModel.shapeModel.useWebGl = false; + world.import(worldData); + el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); el.elementModel.shapeModel.GLGeomObj.setFillMaterial(null); el.elementModel.shapeModel.strokeMaterial = null; el.elementModel.shapeModel.fillMaterial = null; - world.import(worldData); } - } } -- cgit v1.2.3 From 9e40945a5bf4330d1088b56b8011ee625b1adab9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 10 Feb 2012 10:23:48 -0800 Subject: Support export/import of GLLine data. Signed-off-by: Nivesh Rajbhandari --- js/controllers/elements/shapes-controller.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'js/controllers/elements/shapes-controller.js') diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js index 44723a1e..640119c4 100644 --- a/js/controllers/elements/shapes-controller.js +++ b/js/controllers/elements/shapes-controller.js @@ -351,12 +351,17 @@ exports.ShapesController = Montage.create(CanvasController, { el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); sm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); - fm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); - if(sm && fm) + if(sm) { el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(sm); - el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); el.elementModel.shapeModel.strokeMaterial = sm; + } + fm = Object.create(MaterialsLibrary.getMaterial("FlatMaterial")); + // TODO - Use consts after GL code is converted to object literal notation +// if( fm && (el.elementModel.shapeModel.GLGeomObj.geomType() !== GLGeomObj.GEOM_TYPE_LINE) ) + if( fm && (el.elementModel.shapeModel.GLGeomObj.geomType() !== 3) ) + { + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(fm); el.elementModel.shapeModel.fillMaterial = fm; } } @@ -381,9 +386,13 @@ exports.ShapesController = Montage.create(CanvasController, { world.import(worldData); el.elementModel.shapeModel.GLGeomObj = world.getGeomRoot(); el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(null); - el.elementModel.shapeModel.GLGeomObj.setFillMaterial(null); el.elementModel.shapeModel.strokeMaterial = null; - el.elementModel.shapeModel.fillMaterial = null; + // TODO - Use consts after GL code is converted to object literal notation + if(el.elementModel.shapeModel.GLGeomObj.geomType() !== 3) + { + el.elementModel.shapeModel.GLGeomObj.setFillMaterial(null); + el.elementModel.shapeModel.fillMaterial = null; + } } } } -- cgit v1.2.3