Skip to content

Commit

Permalink
Merge pull request #443 from steptools/new-preview-geometry
Browse files Browse the repository at this point in the history
New preview geometry
  • Loading branch information
ian-h-chamberlain authored Aug 9, 2016
2 parents 41d2b83 + c4603ca commit 901e154
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Bugfixes:

- Disabled workplans disable all children, not just immediate
- Feedrate has proper rounding
- Previewing a tool with multiple shells loads all shells in the tool
- Workingstep transition bug fixed
- Sidebar should scroll properly on initial load
- Tool properties pane now shows/hides the correct workingsteps
Expand Down
99 changes: 63 additions & 36 deletions src/client/models/data_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ export default class DataLoader extends THREE.EventDispatcher {
let req, shell, anno;
// console.log("Worker Data: " + event.data.file);
// Find the request this message corresponds to
if (_.indexOf(["rootLoad", "shellLoad", "annotationLoad", "loadError"], event.data.type) != -1) {
if (_.indexOf(["rootLoad", "shellLoad", "annotationLoad", "loadError", "previewLoad", "previewEndLoad"], event.data.type) != -1) {
req = this._loading[event.data.workerID];
}
// Put worker back into the queue - if it is the time
if (_.indexOf(["rootLoad", "workerFinish", "loadError"], event.data.type) != -1) {
if (_.indexOf(["rootLoad", "workerFinish", "loadError", "previewLoad"], event.data.type) != -1) {
this._loading[event.data.workerID] = undefined;
this._freeWorkers.push(event.data.workerID);
this.runLoadQueue();
Expand All @@ -202,17 +202,14 @@ export default class DataLoader extends THREE.EventDispatcher {
this.dispatchEvent({ type: "annotationLoad", file: event.data.file });
}
break;
case "previewLoad":
this.buildPreviewNCJSON(event.data.data, req);
break;
case "shellLoad":
//This is the case where the shell comes in with position, normals and colors vector after ProcessShellJSON
shell = this._shells[event.data.id+".json"];

if (req.type === 'previewShell') {
this.buildPreviewNC(event.data, req);
this.dispatchEvent({
type: "shellLoad",
file: event.data.file
});
} else if (!shell) {

if (!shell) {
console.log('DataLoader.ShellLoad: invalid shell ID ' + event.data.id);
} else {
data = event.data.data;
Expand Down Expand Up @@ -258,12 +255,20 @@ export default class DataLoader extends THREE.EventDispatcher {
let newpath = (req.baseURL).split('state')[0];
if(newpath[newpath.length - 1] === '/')
newpath = newpath.substring(0 , newpath.length - 1);
data.url = newpath + '/geometry/' + req.path + '/' + req.type;

// TODO: actually figure out whether we need /shell or not
if (req.path.indexOf('mesh') >= 0) {
data.url = newpath + '/geometry/' + req.path + '/' + req.type;
} else {
data.url = newpath + '/geometry/' + req.path;
}

} else if (data.type === 'previewShell') {
data.shellSize = req.shellSize;
let newpath = req.baseURL;
if(newpath[newpath.length - 1] === '/')
newpath = newpath.substring(0 , newpath.length - 1);

data.url = newpath + '/geometry/' + req.path;
}
else if (data.type === "annotation") {
Expand All @@ -275,35 +280,57 @@ export default class DataLoader extends THREE.EventDispatcher {
worker.postMessage(data);
}

buildPreviewNC(data, req) {
buildPreviewNCJSON(data, req) {
let doc = JSON.parse(data);
let parts = req.base.split('/');
let baseUrl = parts.slice(0, 3).join('/');

let nc = new NC(null, null, null, this);

let color = DataLoader.parseColor('7d7d7d');
let transform = DataLoader.parseXform( [
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
], true);

// Is this a shell
if(data.usage === 'cutter') {
color = DataLoader.parseColor("FF530D");
}
if(data.usage === 'fixture' && this._app.services.machine.dir === '') {
return;
}
if (data.usage === undefined) {
data.usage = 'tobe';
}

let boundingBox = new THREE.Box3();
_.each(doc.geom, (geomData) => {
let color = DataLoader.parseColor('7d7d7d');
let transform = DataLoader.parseXform(geomData.xform, true);
// Is this a shell
if (_.has(geomData, 'shell')) {
if(geomData.usage === 'cutter')
{
color = DataLoader.parseColor("FF530D");
}
if(geomData.usage === 'fixture' && this._app.services.machine === null){
return;
}
if (!geomData.usage) {
geomData.usage = 'tobe';
}

let boundingBox = DataLoader.parseBoundingBox(geomData.bbox);
let shell = new Shell(geomData.id, nc, nc, geomData.size, color, boundingBox);
nc.addModel(shell, geomData.usage, 'shell', geomData.id, transform, boundingBox);
// Push the shell for later completion

let shell = new Shell(data.id, nc, nc, data.size, color, boundingBox);
this._shells[geomData.shell] = shell;
this.addRequest({
path: geomData.shell.split('.')[0],
baseURL: baseUrl,
type: 'shell',
});
// Is this a polyline
} else if (_.has(geomData, 'polyline')) {
let annotation = new Annotation(geomData.id, nc, nc);
nc.addModel(annotation, geomData.usage, 'polyline', geomData.id, transform, undefined);
// Push the annotation for later completion
let name = geomData.polyline.split('.')[0];
this._annotations[name] = annotation;
this.addRequest({
path: name,
baseURL: baseUrl,
type: 'annotation'
});
} else {
console.log('No idea what we found: ' + geomData);
}
});

nc.addModel(shell, data.usage, 'shell', data.id, transform, boundingBox);
shell.addGeometry(data.data.position, data.data.normals, data.data.color, data.data.faces);

req.callback(undefined, nc);
}

Expand Down
4 changes: 2 additions & 2 deletions src/client/models/nc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class NC extends THREE.EventDispatcher {
this._overlay3D.add(obj.overlay3D);
this._annotation3D.add(obj.annotation3D);
if (type === 'shell') {
model.addEventListener('shellEndLoad', function (event) {
model.addEventListener('shellEndLoad', (event) => {
//This is where the shell gets sent when its loaded so that the full mesh can be added to the 3D objects
let material = new THREE.ShaderMaterial(new THREE.VelvetyShader());
let mesh = new THREE.Mesh(event.shell.getGeometry(), material, false);
Expand All @@ -89,7 +89,7 @@ export default class NC extends THREE.EventDispatcher {
}
});
} else if (type === 'polyline') {
model.addEventListener('annotationEndLoad', function(event) {
model.addEventListener('annotationEndLoad', (event) => {
let lineGeometries = event.annotation.getGeometry();
let material = new THREE.LineBasicMaterial({
vertexColors: THREE.VertexColors,
Expand Down
37 changes: 17 additions & 20 deletions src/client/models/webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,16 @@ function processAssembly(url, workerID, data) {
});
}

function processPreviewJSON(url, workerID, data) {
// pass back to main thread
self.postMessage({
type: 'previewLoad',
url: url,
data: data,
workerID: workerID,
});
}

function processNCState(url, workerID, data) {
// All we really need to do is pass this back to the main thread
self.postMessage({
Expand Down Expand Up @@ -786,6 +796,13 @@ let messageHandler = function(e) {
processAnnotation(url, workerID, res.text);
break;
case "previewShell":
file = parts.slice(-1).join('/');
if (file === 'tool') {
file = parts.slice(-2).join('/');
}
file = 'preview-' + file;
processPreviewJSON(url, workerID, res.text);
break;
case "shell":
// Try to parse the JSON file
let dataJSON;
Expand All @@ -804,26 +821,6 @@ let messageHandler = function(e) {
}

file = dataJSON.id;
if (e.data.type === 'previewShell') {
file = 'preview-';
if (parts[parts.length - 1] === 'tool') {
file = file + parts[parts.length - 2] + '/tool';
}
else {
file = file + parts[parts.length - 1];
}
_.each(dataJSON, (dat) => {
if (_.has(dat, 'id'))
processShellJSON(url, workerID, dat, true);
});

self.postMessage({
type: "parseComplete",
file: parts[parts.length - 2]
});

break;
}
self.postMessage({
type: "parseComplete",
file: parts[parts.length - 2]
Expand Down
5 changes: 2 additions & 3 deletions src/client/views/responsive/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ export default class ResponsiveView extends React.Component {

if (node.type === 'tolerance') {
let workingsteps = [];
for (let i in json[node.workpiece].workingsteps) {
let ws = json[node.workpiece].workingsteps[i];
ws = this.state.workingstepCache[ws];
for (let i of json[node.workpiece].workingsteps) {
let ws = this.state.workingstepCache[i];
if (node.workpiece === ws.toBe.id) {
workingsteps.push(json[node.workpiece].workingsteps[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/views/sidebar/propertiespane/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default class PropertiesPane extends React.Component {
this.props.manager.dispatchEvent({
type: 'setModel',
viewType: 'preview',
path: prevId,
path: prevId.toString(),
baseURL: url,
modelType: 'previewShell',
});
Expand Down
8 changes: 6 additions & 2 deletions src/server/api/v3/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ function _getGeometry(req, res) {
return;
} else if (req.params.type === 'tool') {
let toolId = find.GetToolWorkpiece(Number(req.params.id));
res.status(200).send(find.GetGeometryJSON(toolId));
res.status(200).send(find.GetJSONProduct(toolId)); // toolId));
return;
} else if (!req.params.type && req.params.eid) {
res.status(200).send(find.GetGeometryJSON(Number(req.params.eid)));
if (!isNaN(Number(req.params.eid)) && isFinite(Number(req.params.eid))) {
res.status(200).send(find.GetJSONProduct(Number(req.params.eid)));
} else {
res.status(200).send(find.GetJSONGeometry(req.params.eid, 'MESH'));
}
return;
}
res.status(200).send(ms.GetGeometryJSON());
Expand Down

0 comments on commit 901e154

Please sign in to comment.