diff --git a/web/app/3d/ctrl.js b/web/app/3d/ctrl.js index d1636710..4aa5d931 100644 --- a/web/app/3d/ctrl.js +++ b/web/app/3d/ctrl.js @@ -3,8 +3,13 @@ TCAD.UI = function(app) { this.app = app; this.viewer = app.viewer; this.dat = new dat.GUI(); + var ui = this; var gui = this.dat; + app.bus.subscribe('selection', function (polyFace) { + ui.setSolid(polyFace.solid) + }); + var actionsF = gui.addFolder('Add Object'); var actions = new TCAD.UI.Actions(this); actionsF.add(actions.tools, 'extrude'); @@ -20,8 +25,15 @@ TCAD.UI = function(app) { camera.add(app.viewer.camera.position, 'z').listen(); camera.open(); -// var propsF = gui.addFolder('Properties'); -// propsF.add(object3DProto.position, 'x'); + this.solidFolder = null; +}; + +TCAD.UI.prototype.setSolid = function(solid) { + if (this.solidFolder !== null) { + this.solidFolder.remove(); + } + this.solidFolder = this.dat.addFolder("Solid Properties"); + this.solidFolder.add(solid.wireframeGroup, 'visible').listen() }; TCAD.UI.Actions = function(scope) { diff --git a/web/app/3d/main.js b/web/app/3d/main.js index c93f498f..d527df48 100644 --- a/web/app/3d/main.js +++ b/web/app/3d/main.js @@ -3,11 +3,11 @@ TCAD = {}; TCAD.App = function() { this.id = "DEFAULT"; - this.viewer = new TCAD.Viewer(); + this.bus = new TCAD.Bus(); + this.viewer = new TCAD.Viewer(this.bus); this.ui = new TCAD.UI(this); this.craft = new TCAD.Craft(this); - var box = TCAD.utils.createSolidMesh(TCAD.utils.createBox(500)); this.viewer.scene.add( box ); this._refreshSketches(); @@ -204,4 +204,27 @@ TCAD.App.prototype.save = function() { var polyFace = this.viewer.selectionMgr.selection[0]; var height = prompt("Height", "50"); +}; + +TCAD.Bus = function() { + this.listeners = {}; +}; + +TCAD.Bus.prototype.subscribe = function(event, callback) { + var listenerList = this.listeners[event]; + if (listenerList === undefined) { + listenerList = []; + this.listeners[event] = listenerList; + } + listenerList.push(callback); +}; + +TCAD.Bus.prototype.notify = function(event, data) { + var listenerList = this.listeners[event]; + if (listenerList !== undefined) { + for (var i = 0; i < listenerList.length; i++) { + listenerList[i](data); + } + } + }; \ No newline at end of file diff --git a/web/app/3d/viewer.js b/web/app/3d/viewer.js index 6a4e9def..8198f9dc 100644 --- a/web/app/3d/viewer.js +++ b/web/app/3d/viewer.js @@ -12,8 +12,8 @@ TCAD.view.setFaceColor = function(polyFace, color) { } }; TCAD.view.FACE_COLOR = 0xB0C4DE; -TCAD.Viewer = function() { - +TCAD.Viewer = function(bus) { + this.bus = bus; function aspect() { return window.innerWidth / window.innerHeight; } @@ -110,7 +110,7 @@ TCAD.Viewer = function() { if (scope.selectionMgr.contains(poly)) { scope.toolMgr.handleClick(poly, pickResult); } else { - scope.selectionMgr.select(poly); + scope.select(poly); pickResult.object.geometry.colorsNeedUpdate = true; } } @@ -155,6 +155,11 @@ TCAD.Viewer = function() { animate(); }; +TCAD.Viewer.prototype.select = function(polyFace) { + this.selectionMgr.select(polyFace); + this.bus.notify('selection', polyFace); +}; + TCAD.FaceSelectionManager = function(selectionColor, defaultColor) { this.selectionColor = selectionColor; this.defaultColor = defaultColor;