diff --git a/scripts/testPubSub.js b/scripts/testPubSub.js index b8c06de..4184b4d 100644 --- a/scripts/testPubSub.js +++ b/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() { @@ -25,4 +25,4 @@ function serveDelta() { setTimeout(serveDelta, timeStep); } -setTimeout(serveDelta, 4000); \ No newline at end of file +setTimeout(serveDelta, 4000); diff --git a/src/client/models/data_loader.js b/src/client/models/data_loader.js index 2099c2f..1d54bcc 100644 --- a/src/client/models/data_loader.js +++ b/src/client/models/data_loader.js @@ -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])); @@ -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": @@ -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": @@ -270,10 +272,11 @@ 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({ @@ -281,9 +284,10 @@ export default class DataLoader extends THREE.EventDispatcher { 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; @@ -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); @@ -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); @@ -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 @@ -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); @@ -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"); diff --git a/src/client/models/nc.js b/src/client/models/nc.js index 23b96be..07b01e3 100644 --- a/src/client/models/nc.js +++ b/src/client/models/nc.js @@ -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(), @@ -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); @@ -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; @@ -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({ @@ -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); } }); diff --git a/src/client/models/webworker.js b/src/client/models/webworker.js index 98b4d40..a253edc 100644 --- a/src/client/models/webworker.js +++ b/src/client/models/webworker.js @@ -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] diff --git a/src/client/views/browser/index.js b/src/client/views/browser/index.js index b6ee05e..2bd9969 100644 --- a/src/client/views/browser/index.js +++ b/src/client/views/browser/index.js @@ -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 }); } diff --git a/src/server/api_server.js b/src/server/api_server.js index 7d2c47a..106ed61 100644 --- a/src/server/api_server.js +++ b/src/server/api_server.js @@ -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); }); @@ -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); });