bus for notifying objects

This commit is contained in:
Val Erastov 2015-08-31 01:05:29 -07:00
parent e57c0a2eb9
commit 7bb3c099b6
3 changed files with 47 additions and 7 deletions

View file

@ -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) {

View file

@ -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);
}
}
};

View file

@ -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;