Skip to content

Commit

Permalink
Couple of changes. Update to lodash 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghemingway committed Jan 15, 2016
1 parent d243419 commit bab6822
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 25 deletions.
4 changes: 2 additions & 2 deletions scripts/testPubSub.js
@@ -1,5 +1,5 @@
var redis = require('redis');
var client = redis.createClient(21211, '10.66.235.229');
var client = redis.createClient(32769, '192.168.99.100');
var min = -2.0, max = 2.0, time = 0, timeStep = 500, x = 0.0, y = 0.0, z = 0.0;

function serveDelta() {
Expand All @@ -25,4 +25,4 @@ function serveDelta() {
setTimeout(serveDelta, timeStep);
}

setTimeout(serveDelta, 4000);
setTimeout(serveDelta, 4000);
28 changes: 17 additions & 11 deletions src/client/models/data_loader.js
Expand Up @@ -36,7 +36,9 @@ export default class DataLoader extends THREE.EventDispatcher {
}

static parseBoundingBox(str) {
if (!str) return undefined;
if (!str) {
return new THREE.Box3();
}
let vals = str;
if (typeof str === "string") vals = DataLoader.parseFloatVec(str, 6);
return new THREE.Box3(new THREE.Vector3(vals[0], vals[1], vals[2]), new THREE.Vector3(vals[3], vals[4], vals[5]));
Expand Down Expand Up @@ -191,7 +193,7 @@ export default class DataLoader extends THREE.EventDispatcher {
console.log('DataLoader.AnnotationlLoad: invalid annotation ID' + event.data.file);
} else {
anno.addGeometry(data);
this.dispatchEvent({type: "annotationLoad", file: event.data.file});
this.dispatchEvent({ type: "annotationLoad", file: event.data.file });
}
break;
case "shellLoad":
Expand All @@ -203,7 +205,7 @@ export default class DataLoader extends THREE.EventDispatcher {
// Remove the reference to the shell
delete this._shells[event.data.id];
shell.addGeometry(data.position, data.normals, data.colors);
this.dispatchEvent({type: "shellLoad", file: event.data.file});
this.dispatchEvent({ type: "shellLoad", file: event.data.file });
}
break;
case "workerFinish":
Expand Down Expand Up @@ -270,20 +272,22 @@ export default class DataLoader extends THREE.EventDispatcher {
_.each(doc.geom, function(geomData) {
let color = DataLoader.parseColor("7d7d7d");
let transform = DataLoader.parseXform(geomData.xform, true);
if (geomData.usage === 'asis' || geomData.usage === 'tobe' || geomData.usage === 'cutter') {
// Is this a shell
if (_.has(geomData, 'shell')) {
let boundingBox = DataLoader.parseBoundingBox(geomData.bbox);
let shell = new Shell(geomData.id, nc, nc, geomData.size, color, boundingBox);
nc.addModel(shell, geomData.usage, geomData.id, transform, boundingBox);
nc.addModel(shell, geomData.usage, 'shell', geomData.id, transform, boundingBox);
// Push the shell for later completion
self._shells[geomData.shell] = shell;
self.addRequest({
path: geomData.shell.split('.')[0],
baseURL: req.base,
type: "shell"
});
} else if (geomData.usage === 'toolpath') {
// Is this a polyline
} else if (_.has(geomData, 'polyline')) {
let annotation = new Annotation(geomData.id, nc, nc);
nc.addModel(annotation, geomData.usage, geomData.id, transform, undefined);
nc.addModel(annotation, geomData.usage, 'polyline', geomData.id, transform, undefined);
// Push the annotation for later completion
let name = geomData.polyline.split('.')[0];
self._annotations[name] = annotation;
Expand All @@ -292,6 +296,8 @@ export default class DataLoader extends THREE.EventDispatcher {
baseURL: req.base,
type: "annotation"
});
} else {
console.log('No idea what we found: ' + geomData);
}
});
req.callback(undefined, nc);
Expand All @@ -300,7 +306,7 @@ export default class DataLoader extends THREE.EventDispatcher {
buildProductJSON(req, doc, assembly, id, isRoot) {
// Create the product
let self = this;
let productJSON = _.findWhere(doc.products, { id: id });
let productJSON = _.find(doc.products, { id: id });
// Have we already seen this product
if (!assembly.isChild(id)) {
let product = new Product(id, assembly, productJSON.name, productJSON.step, isRoot);
Expand All @@ -326,7 +332,7 @@ export default class DataLoader extends THREE.EventDispatcher {
if (!isRoot) return assembly.getChild(id);
// Ok, now let's really build some stuff
let self = this;
let shapeJSON = _.findWhere(doc.shapes, {id: id});
let shapeJSON = _.find(doc.shapes, {id: id});
let unit = shapeJSON.unit ? shapeJSON.unit : "unit 0.01";
let shape = new Shape(id, assembly, parent, transform, unit, isRoot);
// Load child shells
Expand All @@ -352,7 +358,7 @@ export default class DataLoader extends THREE.EventDispatcher {

buildAnnotationJSON(req, doc, id, assembly, parent) {
let alreadyLoaded = assembly.isChild(id);
let annoJSON = _.findWhere(doc.annotations, {id: id});
let annoJSON = _.find(doc.annotations, {id: id});
// Do we have to load the shell
if (annoJSON.href) {
let anno = new Annotation(id, assembly, parent);
Expand All @@ -374,7 +380,7 @@ export default class DataLoader extends THREE.EventDispatcher {

buildShellJSON(req, doc, id, assembly, parent) {
let alreadyLoaded = assembly.isChild(id);
let shellJSON = _.findWhere(doc.shells, {id: id});
let shellJSON = _.find(doc.shells, {id: id});
// Do we have to load the shell
if (shellJSON.href) {
let color = DataLoader.parseColor("7d7d7d");
Expand Down
14 changes: 8 additions & 6 deletions src/client/models/nc.js
Expand Up @@ -21,13 +21,14 @@ export default class NC extends THREE.EventDispatcher {
this._annotation3D = new THREE.Object3D();
}

addModel(model, type, id, transform, bbox) {
addModel(model, usage, type, id, transform, bbox) {
let asisOpacity = 0.15;
console.log('Add Model(' + type + '): ' + id);
console.log('Add Model(' + usage + '): ' + id);
let self = this;
// Setup 3D object holder
let obj = {
model: model,
usage: usage,
type: type,
id: id,
object3D: new THREE.Object3D(),
Expand All @@ -42,7 +43,7 @@ export default class NC extends THREE.EventDispatcher {
this._object3D.add(obj.object3D);
this._overlay3D.add(obj.overlay3D);
this._annotation3D.add(obj.annotation3D);
if (type === 'tobe' || type == 'asis' || type === 'cutter') {
if (type === 'shell') {
model.addEventListener("shellEndLoad", function (event) {
let material = new THREE.ShaderMaterial(new THREE.VelvetyShader());
let mesh = new THREE.SkinnedMesh(event.shell.getGeometry(), material, false);
Expand All @@ -51,7 +52,7 @@ export default class NC extends THREE.EventDispatcher {
mesh.userData = self;
obj.object3D.add(mesh);
// Dim the asis
if (type === 'asis' && asisOpacity !== 1.0) {
if (usage === 'asis' && asisOpacity !== 1.0) {
obj.object3D.traverse(function (object) {
if (object.material && object.material.uniforms.opacity) {
object.material.transparent = true;
Expand All @@ -61,7 +62,7 @@ export default class NC extends THREE.EventDispatcher {
});
}
});
} else if (type === 'toolpath') {
} else if (type === 'polyline') {
model.addEventListener("annotationEndLoad", function(event) {
let lineGeometries = event.annotation.getGeometry();
let material = new THREE.LineBasicMaterial({
Expand Down Expand Up @@ -109,7 +110,8 @@ export default class NC extends THREE.EventDispatcher {
let keys = _.keys(this._objects);
_.each(keys, function(key) {
let object = self._objects[key];
if (object.type !== 'toolpath') {
if (object.type !== 'polyline') {
console.log(object);
self.boundingBox.union(object.bbox);
}
});
Expand Down
17 changes: 15 additions & 2 deletions src/client/models/webworker.js
Expand Up @@ -763,8 +763,21 @@ self.addEventListener("message", function(e) {
processAnnotation(url, workerID, xhr.responseText);
break;
case "shell":
// Parse the JSON file
var dataJSON = JSON.parse(xhr.responseText);
// Try to parse the JSON file
let dataJSON;
try {
dataJSON = JSON.parse(xhr.responseText);
} catch(ex) {
console.log(ex);
console.log(xhr.responseText);
dataJSON = {
precision: 2,
pointsIndex: [],
normalsIndex: [],
colorsData: [],
values: []
};
}
self.postMessage({
type: "parseComplete",
file: parts[parts.length - 1]
Expand Down
2 changes: 1 addition & 1 deletion src/client/views/browser/index.js
Expand Up @@ -55,7 +55,7 @@ export default class BrowserView extends React.Component {
}

handleClick(event) {
let file = _.findWhere(this.state.files, { name: event.target.id });
let file = _.find(this.state.files, { name: event.target.id });
this.props.router.navigate(file.name + '?type=' + file.types[0], { trigger: true });
}

Expand Down
4 changes: 1 addition & 3 deletions src/server/api_server.js
Expand Up @@ -85,6 +85,7 @@ APIServer.prototype._setSocket = function() {

// Wait on the redis pubSub and relay to clients
redisPubSubClient.on('message', function (channel, message) {
console.log('nc:delta: ' + message);
var msg = JSON.parse(message);
self.ioServer.emit('nc:delta', msg);
});
Expand Down Expand Up @@ -134,9 +135,6 @@ APIServer.prototype._setSite = function() {
*/
APIServer.prototype.run = function() {
var self = this;
//this.express.listen(this.config.port, function() {
// self.logger.info('\tCAD.js API Server listening on: ' + self.config.port);
//});
this.server.listen(this.config.port, function () {
self.logger.info('CAD.js API Server listening on: ' + self.config.port);
});
Expand Down

0 comments on commit bab6822

Please sign in to comment.