mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 18:02:50 +01:00
restore wizards from history
This commit is contained in:
parent
f77083e415
commit
17ba1f0c1b
10 changed files with 288 additions and 164 deletions
|
|
@ -8,11 +8,10 @@ TCAD.UI = function(app) {
|
|||
mainBox.root.css({height : '100%'});
|
||||
var propFolder = new tk.Folder("Solid's Properties");
|
||||
var debugFolder = new tk.Folder("Debug");
|
||||
var cameraFolder = new tk.Folder("Camera");
|
||||
var objectsFolder = new tk.Folder("Objects");
|
||||
var modificationsFolder = new tk.Folder("Modifications");
|
||||
var extrude, cut, edit, addPlane, save,
|
||||
refreshSketches, showSketches, printSolids, printFace, printFaceId;
|
||||
refreshSketches, showSketches, printSolids, printFace, printFaceId, finishHistory;
|
||||
tk.add(mainBox, propFolder);
|
||||
tk.add(propFolder, extrude = new tk.Button("Extrude"));
|
||||
tk.add(propFolder, cut = new tk.Button("Cut"));
|
||||
|
|
@ -25,87 +24,65 @@ TCAD.UI = function(app) {
|
|||
tk.add(debugFolder, printSolids = new tk.Button("Print Solids"));
|
||||
tk.add(debugFolder, printFace = new tk.Button("Print Face"));
|
||||
tk.add(debugFolder, printFaceId = new tk.Button("Print Face ID"));
|
||||
tk.add(mainBox, cameraFolder);
|
||||
tk.add(cameraFolder, new tk.Number("x"));
|
||||
tk.add(cameraFolder, new tk.Number("y"));
|
||||
tk.add(cameraFolder, new tk.Number("z"));
|
||||
tk.add(mainBox, objectsFolder);
|
||||
tk.add(mainBox, modificationsFolder);
|
||||
var modificationsListComp = new tk.List();
|
||||
tk.add(modificationsFolder, modificationsListComp);
|
||||
|
||||
var ui = this;
|
||||
|
||||
|
||||
function setHistory() {
|
||||
ui.app.craft.finishHistoryEditing();
|
||||
}
|
||||
finishHistory = new tk.ButtonRow(["Finish History Editing"], [setHistory]);
|
||||
finishHistory.root.hide();
|
||||
tk.add(modificationsFolder, finishHistory);
|
||||
var historyWizard = null;
|
||||
function updateHistoryPointer() {
|
||||
if (historyWizard != null) {
|
||||
historyWizard.close();
|
||||
historyWizard = null;
|
||||
}
|
||||
|
||||
var craft = ui.app.craft;
|
||||
var historyEditMode = craft.historyPointer != craft.history.length;
|
||||
if (historyEditMode) {
|
||||
var rows = modificationsListComp.root.find('.tc-row');
|
||||
rows.removeClass('history-selected');
|
||||
rows.eq(craft.historyPointer).addClass('history-selected');
|
||||
var op = craft.history[craft.historyPointer];
|
||||
historyWizard = TCAD.UI.createWizard(op, app, mainBox);
|
||||
finishHistory.root.show();
|
||||
} else {
|
||||
finishHistory.root.hide();
|
||||
}
|
||||
}
|
||||
|
||||
this.app.bus.subscribe("craft", function() {
|
||||
modificationsListComp.root.empty();
|
||||
for (var i = 0; i < app.craft.history.length; i++) {
|
||||
var op = app.craft.history[i];
|
||||
modificationsListComp.addRow(ui.getInfoForOp(op));
|
||||
var row = modificationsListComp.addRow(ui.getInfoForOp(op));
|
||||
(function(i) {
|
||||
row.click(function () {
|
||||
ui.app.craft.historyPointer = i;
|
||||
})
|
||||
})(i);
|
||||
}
|
||||
updateHistoryPointer();
|
||||
});
|
||||
|
||||
this.app.bus.subscribe("historyPointer", function() {
|
||||
//updateHistoryPointer();
|
||||
});
|
||||
|
||||
|
||||
function cutExtrude(isCut) {
|
||||
return function() {
|
||||
if (app.viewer.selectionMgr.selection.length == 0) {
|
||||
return;
|
||||
}
|
||||
var face = app.viewer.selectionMgr.selection[0];
|
||||
var normal = TCAD.utils.vec(face.csgGroup.plane.normal);
|
||||
var polygons = TCAD.craft.getSketchedPolygons3D(app, face);
|
||||
|
||||
var box = new tk.Box();
|
||||
box.root.css({left : (mainBox.root.width() + 10) + 'px', top : 0});
|
||||
var folder = new tk.Folder(isCut ? "Cut Options" : "Extrude Options");
|
||||
tk.add(box, folder);
|
||||
var theValue = new tk.Number(isCut ? "Depth" : "Height", 50);
|
||||
var scale = new tk.Number("Expansion", 1, 0.1);
|
||||
var deflection = new tk.Number("Deflection", 0, 1);
|
||||
var angle = new tk.Number("Angle", 0, 5);
|
||||
var wizard = new TCAD.wizards.ExtrudeWizard(app.viewer, polygons);
|
||||
function onChange() {
|
||||
var depthValue = theValue.input.val();
|
||||
var scaleValue = scale.input.val();
|
||||
var deflectionValue = deflection.input.val();
|
||||
var angleValue = angle.input.val();
|
||||
if (isCut) depthValue *= -1;
|
||||
wizard.update(face._basis, normal, depthValue, scaleValue, deflectionValue, angleValue);
|
||||
app.viewer.render()
|
||||
}
|
||||
theValue.input.on('t-change', onChange);
|
||||
scale.input.on('t-change', onChange);
|
||||
deflection.input.on('t-change', onChange);
|
||||
angle.input.on('t-change', onChange);
|
||||
onChange();
|
||||
tk.add(folder, theValue);
|
||||
tk.add(folder, scale);
|
||||
tk.add(folder, deflection);
|
||||
tk.add(folder, angle);
|
||||
function close() {
|
||||
box.close();
|
||||
wizard.dispose();
|
||||
}
|
||||
function applyCut() {
|
||||
var depthValue = theValue.input.val();
|
||||
app.craft.modify({
|
||||
type: 'CUT',
|
||||
solids : [face.solid],
|
||||
face : face,
|
||||
params : wizard.operationParams
|
||||
});
|
||||
close();
|
||||
}
|
||||
function applyExtrude() {
|
||||
var heightValue = theValue.input.val();
|
||||
app.craft.modify({
|
||||
type: 'PAD',
|
||||
solids : [face.solid],
|
||||
face : face,
|
||||
params : wizard.operationParams
|
||||
});
|
||||
close();
|
||||
}
|
||||
|
||||
tk.add(folder, new tk.ButtonRow(["Cancel", "OK"], [close, isCut ? applyCut : applyExtrude]));
|
||||
TCAD.UI.createCutExtrudeWizard(isCut, ui.app, app.viewer.selectionMgr.selection[0], mainBox);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,36 +91,7 @@ TCAD.UI = function(app) {
|
|||
edit.root.click(tk.methodRef(app, "sketchFace"));
|
||||
refreshSketches.root.click(tk.methodRef(app, "refreshSketches"));
|
||||
addPlane.root.click(function() {
|
||||
var box = new tk.Box();
|
||||
box.root.css({left : (mainBox.root.width() + 10) + 'px', top : 0});
|
||||
var folder = new tk.Folder("Add a Plane");
|
||||
tk.add(box, folder);
|
||||
var choice = ['XY', 'XZ', 'ZY'];
|
||||
var orientation = new tk.InlineRadio(choice, choice, 0);
|
||||
var depth = new tk.Number("Depth", 0);
|
||||
|
||||
tk.add(folder, orientation);
|
||||
tk.add(folder, depth);
|
||||
var wizard = new TCAD.wizards.PlaneWizard(app.viewer);
|
||||
function onChange() {
|
||||
wizard.update(orientation.getValue(), depth.input.val());
|
||||
}
|
||||
function close() {
|
||||
box.close();
|
||||
wizard.dispose();
|
||||
}
|
||||
function ok() {
|
||||
app.craft.modify({
|
||||
type: 'PLANE',
|
||||
solids : [],
|
||||
params : wizard.operationParams
|
||||
});
|
||||
close();
|
||||
}
|
||||
orientation.root.find('input:radio').change(onChange);
|
||||
depth.input.on('t-change', onChange);
|
||||
onChange();
|
||||
tk.add(folder, new tk.ButtonRow(["Cancel", "OK"], [close, ok]));
|
||||
TCAD.UI.createPlaneWizard(app, mainBox);
|
||||
});
|
||||
printSolids.root.click(function () {
|
||||
app.findAllSolids().map(function(o) {
|
||||
|
|
@ -175,8 +123,6 @@ TCAD.UI = function(app) {
|
|||
save.root.click(function() {
|
||||
app.save();
|
||||
});
|
||||
|
||||
this.solidFolder = null;
|
||||
};
|
||||
|
||||
TCAD.UI.prototype.getInfoForOp = function(op) {
|
||||
|
|
@ -194,10 +140,131 @@ TCAD.UI.prototype.getInfoForOp = function(op) {
|
|||
return op.type;
|
||||
};
|
||||
|
||||
TCAD.UI.prototype.setSolid = function(solid) {
|
||||
if (this.solidFolder !== null) {
|
||||
this.solidFolder.remove();
|
||||
TCAD.UI.createWizard = function(op, app, alignComponent) {
|
||||
var initParams = op.protoParams;
|
||||
var face = op.face !== undefined ? app.findFace(op.face) : null;
|
||||
if (face != null) {
|
||||
app.viewer.selectionMgr.select(face);
|
||||
}
|
||||
this.solidFolder = this.dat.addFolder("Solid Properties");
|
||||
this.solidFolder.add(solid.wireframeGroup, 'visible').listen()
|
||||
if ('CUT' === op.type) {
|
||||
return TCAD.UI.createCutExtrudeWizard(true, app, face, alignComponent, initParams, true);
|
||||
} else if ('PAD' === op.type) {
|
||||
return TCAD.UI.createCutExtrudeWizard(false, app, face, alignComponent, initParams, true);
|
||||
} else if ('PLANE' === op.type) {
|
||||
return TCAD.UI.createPlaneWizard(app, alignComponent, initParams, true);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
TCAD.UI.createCutExtrudeWizard = function (isCut, app, face, alignComponent, initParams, overriding) {
|
||||
var tk = TCAD.toolkit;
|
||||
function def(index, fallback) {
|
||||
return !!initParams ? initParams[index] : fallback;
|
||||
}
|
||||
|
||||
var normal = TCAD.utils.vec(face.csgGroup.plane.normal);
|
||||
var polygons = TCAD.craft.getSketchedPolygons3D(app, face);
|
||||
|
||||
var box = new tk.Box();
|
||||
box.root.css({left : (alignComponent.root.width() + 10) + 'px', top : 0});
|
||||
var folder = new tk.Folder(isCut ? "Cut Options" : "Extrude Options");
|
||||
tk.add(box, folder);
|
||||
var theValue = new tk.Number(isCut ? "Depth" : "Height", def(0, 50));
|
||||
var scale = new tk.Number("Expansion", def(1, 1), 0.1);
|
||||
var deflection = new tk.Number("Deflection", def(2, 0), 1);
|
||||
var angle = new tk.Number("Angle", def(3, 0), 5);
|
||||
var wizard = new TCAD.wizards.ExtrudeWizard(app.viewer, polygons);
|
||||
var depthValue, scaleValue, deflectionValue, angleValue;
|
||||
function onChange() {
|
||||
depthValue = theValue.input.val();
|
||||
scaleValue = scale.input.val();
|
||||
deflectionValue = deflection.input.val();
|
||||
angleValue = angle.input.val();
|
||||
if (isCut) depthValue *= -1;
|
||||
wizard.update(face._basis, normal, depthValue, scaleValue, deflectionValue, angleValue);
|
||||
app.viewer.render()
|
||||
}
|
||||
theValue.input.on('t-change', onChange);
|
||||
scale.input.on('t-change', onChange);
|
||||
deflection.input.on('t-change', onChange);
|
||||
angle.input.on('t-change', onChange);
|
||||
onChange();
|
||||
tk.add(folder, theValue);
|
||||
tk.add(folder, scale);
|
||||
tk.add(folder, deflection);
|
||||
tk.add(folder, angle);
|
||||
function close() {
|
||||
box.close();
|
||||
wizard.dispose();
|
||||
}
|
||||
function applyCut() {
|
||||
var depthValue = theValue.input.val();
|
||||
app.craft.modify({
|
||||
type: 'CUT',
|
||||
solids : [app.findSolid(face.solid.tCadId)],
|
||||
face : app.findFace(face.id),
|
||||
params : wizard.operationParams,
|
||||
protoParams : [depthValue, scaleValue, deflectionValue, angleValue]
|
||||
}, overriding);
|
||||
close();
|
||||
}
|
||||
function applyExtrude() {
|
||||
var heightValue = theValue.input.val();
|
||||
app.craft.modify({
|
||||
type: 'PAD',
|
||||
solids : [app.findSolid(face.solid.tCadId)],
|
||||
face : app.findFace(face.id),
|
||||
params : wizard.operationParams,
|
||||
protoParams : [depthValue, scaleValue, deflectionValue, angleValue]
|
||||
}, overriding);
|
||||
close();
|
||||
}
|
||||
|
||||
tk.add(folder, new tk.ButtonRow(["Cancel", "OK"], [close, isCut ? applyCut : applyExtrude]));
|
||||
return new TCAD.UI.WizardRef(wizard, box, close);
|
||||
};
|
||||
|
||||
TCAD.UI.createPlaneWizard = function (app, alignComponent, initParams, overiding) {
|
||||
var tk = TCAD.toolkit;
|
||||
|
||||
var box = new tk.Box();
|
||||
box.root.css({left : (alignComponent.root.width() + 10) + 'px', top : 0});
|
||||
var folder = new tk.Folder("Add a Plane");
|
||||
tk.add(box, folder);
|
||||
var choice = ['XY', 'XZ', 'ZY'];
|
||||
var orientation = new tk.InlineRadio(choice, choice, !initParams ? 0 : choice.indexOf(initParams[0]));
|
||||
var depth = new tk.Number("Depth", !initParams ? 0 : initParams[1]);
|
||||
|
||||
tk.add(folder, orientation);
|
||||
tk.add(folder, depth);
|
||||
var wizard = new TCAD.wizards.PlaneWizard(app.viewer);
|
||||
var orientationValue, w;
|
||||
function onChange() {
|
||||
wizard.update(orientationValue = orientation.getValue(), w = depth.input.val());
|
||||
}
|
||||
function close() {
|
||||
box.close();
|
||||
wizard.dispose();
|
||||
}
|
||||
function ok() {
|
||||
app.craft.modify({
|
||||
type: 'PLANE',
|
||||
solids : [],
|
||||
params : wizard.operationParams,
|
||||
protoParams : [orientationValue, w]
|
||||
}, overiding);
|
||||
close();
|
||||
}
|
||||
orientation.root.find('input:radio').change(onChange);
|
||||
depth.input.on('t-change', onChange);
|
||||
onChange();
|
||||
tk.add(folder, new tk.ButtonRow(["Cancel", "OK"], [close, ok]));
|
||||
return new TCAD.UI.WizardRef(wizard, box, close);
|
||||
};
|
||||
|
||||
TCAD.UI.WizardRef = function(wizard, box, close) {
|
||||
this.wizard = wizard;
|
||||
this.box = box;
|
||||
this.close = close;
|
||||
};
|
||||
|
|
@ -57,8 +57,8 @@ TCAD.App = function() {
|
|||
|
||||
TCAD.App.prototype.findAllSolids = function() {
|
||||
return this.viewer.workGroup.children
|
||||
.filter(function(obj) {return !!obj.geometry && obj.geometry.tCadId !== undefined} )
|
||||
.map(function(obj) {return obj.geometry} )
|
||||
.filter(function(obj) {return obj.__tcad_solid !== undefined} )
|
||||
.map(function(obj) {return obj.__tcad_solid} )
|
||||
};
|
||||
|
||||
TCAD.App.prototype.findFace = function(faceId) {
|
||||
|
|
@ -75,6 +75,17 @@ TCAD.App.prototype.findFace = function(faceId) {
|
|||
return null;
|
||||
};
|
||||
|
||||
TCAD.App.prototype.findSolid = function(solidId) {
|
||||
var solids = this.findAllSolids();
|
||||
for (var i = 0; i < solids.length; i++) {
|
||||
var solid = solids[i];
|
||||
if (solid.tCadId == solidId) {
|
||||
return solid;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
TCAD.App.prototype.indexEntities = function() {
|
||||
var out = {solids : {}, faces : {}};
|
||||
var solids = this.findAllSolids();
|
||||
|
|
@ -317,7 +328,8 @@ TCAD.App.prototype.load = function() {
|
|||
var project = localStorage.getItem(this.projectStorageKey());
|
||||
if (!!project) {
|
||||
var data = JSON.parse(project);
|
||||
this.craft.loadHistory(data.history);
|
||||
|
||||
if (!!data.history) {
|
||||
this.craft.loadHistory(data.history);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -172,9 +172,6 @@ TCAD.SelectionManager.prototype.handlePick = function(event) {
|
|||
var sketchFace = pickResult.face.__TCAD_polyFace;
|
||||
if (!this.contains(sketchFace)) {
|
||||
this.select(sketchFace);
|
||||
pickResult.object.geometry.colorsNeedUpdate = true;
|
||||
this.viewer.bus.notify('selection', sketchFace);
|
||||
this.viewer.render();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -193,6 +190,9 @@ TCAD.SelectionManager.prototype.select = function(sketchFace) {
|
|||
this.selection.push(sketchFace);
|
||||
TCAD.view.setFacesColor(sketchFace.faces, this.selectionColor);
|
||||
}
|
||||
sketchFace.solid.mesh.geometry.colorsNeedUpdate = true;
|
||||
this.viewer.bus.notify('selection', sketchFace);
|
||||
this.viewer.render();
|
||||
};
|
||||
|
||||
TCAD.SelectionManager.prototype.contains = function(face) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ TCAD.utils.createBox = function(width) {
|
|||
|
||||
TCAD.utils.createCSGBox = function(width) {
|
||||
var csg = CSG.fromPolygons(TCAD.utils.createBox(width));
|
||||
return TCAD.utils.createSolidMesh(csg);
|
||||
return TCAD.utils.createSolid(csg);
|
||||
};
|
||||
|
||||
TCAD.utils.toCsgGroups = function(polygons) {
|
||||
|
|
@ -127,10 +127,9 @@ TCAD.utils.createSolidMaterial = function() {
|
|||
});
|
||||
};
|
||||
|
||||
TCAD.utils.createSolidMesh = function(csg) {
|
||||
TCAD.utils.createSolid = function(csg) {
|
||||
var material = TCAD.utils.createSolidMaterial();
|
||||
var geometry = new TCAD.Solid(csg, material);
|
||||
return geometry.meshObject;
|
||||
return new TCAD.Solid(csg, material);
|
||||
};
|
||||
|
||||
TCAD.utils.intercept = function(obj, methodName, aspect) {
|
||||
|
|
@ -141,11 +140,17 @@ TCAD.utils.intercept = function(obj, methodName, aspect) {
|
|||
}
|
||||
};
|
||||
|
||||
TCAD.utils.createPlane = function(basis, depth, boundingPolygon, shared) {
|
||||
TCAD.utils.createPlane = function(basis, depth) {
|
||||
var tu = TCAD.utils;
|
||||
|
||||
boundingPolygon = boundingPolygon || TCAD.utils.createSquare(800);
|
||||
shared = shared || tu.createShared();
|
||||
var initWidth = 1;
|
||||
var boundingPolygon = [
|
||||
new TCAD.Vector(0, 0, 0),
|
||||
new TCAD.Vector(initWidth, 0, 0),
|
||||
new TCAD.Vector(initWidth, initWidth, 0),
|
||||
new TCAD.Vector(0, initWidth, 0)
|
||||
];
|
||||
var shared = tu.createShared();
|
||||
|
||||
var material = tu.createSolidMaterial();
|
||||
material.transparent = true;
|
||||
|
|
@ -153,18 +158,27 @@ TCAD.utils.createPlane = function(basis, depth, boundingPolygon, shared) {
|
|||
material.side = THREE.DoubleSide;
|
||||
|
||||
var tr = new TCAD.Matrix().setBasis(basis);
|
||||
var shift = basis[2].multiply(depth);
|
||||
tr.tx = shift.x;
|
||||
tr.ty = shift.y;
|
||||
tr.tz = shift.z;
|
||||
|
||||
var currentBounds = new TCAD.BBox();
|
||||
var points = boundingPolygon.map(function(p) { currentBounds.checkBounds(p.x, p.y); return tr._apply(p); });
|
||||
var points = boundingPolygon.map(function(p) { p.z = depth; return tr._apply(p); });
|
||||
var polygon = new CSG.Polygon(points.map(function(p){return new CSG.Vertex(TCAD.utils.csgVec(p))}), shared);
|
||||
var plane = new TCAD.Solid(CSG.fromPolygons([polygon]), material, 'PLANE');
|
||||
plane.wireframeGroup.visible = false;
|
||||
plane.mergeable = false;
|
||||
|
||||
function setBounds(bbox) {
|
||||
var corner = new TCAD.Vector(bbox.minX, bbox.minY, 0);
|
||||
var size = new TCAD.Vector(bbox.width(), bbox.height(), 1);
|
||||
tr.invert()._apply(size);
|
||||
tr.invert()._apply(corner);
|
||||
plane.mesh.scale.set(size.x, size.y, size.z);
|
||||
plane.mesh.position.set(corner.x, corner.y, corner.z);
|
||||
currentBounds = bbox;
|
||||
}
|
||||
var bb = new TCAD.BBox();
|
||||
bb.checkBounds(-400, -400);
|
||||
bb.checkBounds( 400, 400);
|
||||
setBounds(bb);
|
||||
|
||||
var sketchFace = plane.polyFaces[0];
|
||||
tu.intercept(sketchFace, 'syncSketches', function(invocation, args) {
|
||||
var geom = args[0];
|
||||
|
|
@ -177,17 +191,12 @@ TCAD.utils.createPlane = function(basis, depth, boundingPolygon, shared) {
|
|||
bbox.checkBounds(l.b.x, l.b.y);
|
||||
}
|
||||
if (bbox.maxX > currentBounds.maxX || bbox.maxY > currentBounds.maxY || bbox.minX < currentBounds.minX || bbox.minY < currentBounds.minY) {
|
||||
var parent = plane.meshObject.parent;
|
||||
plane.vanish();
|
||||
bbox.expand(20);
|
||||
var newPlane = TCAD.utils.createPlane(basis, depth, bbox.toPolygon(), sketchFace.csgGroup.shared);
|
||||
newPlane.geometry.tCadId = plane.tCadId;
|
||||
TCAD.SketchFace.prototype.syncSketches.call(newPlane.geometry.polyFaces[0], geom);
|
||||
parent.add(newPlane);
|
||||
bbox.expand(50);
|
||||
setBounds(bbox);
|
||||
}
|
||||
});
|
||||
|
||||
return plane.meshObject;
|
||||
return plane;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -605,29 +614,38 @@ TCAD.utils.getDerivedFrom = function(shared) {
|
|||
|
||||
/** @constructor */
|
||||
TCAD.Solid = function(csg, material, type) {
|
||||
THREE.Geometry.call( this );
|
||||
csg = csg.reTesselated().canonicalized();
|
||||
this.tCadType = type || 'SOLID';
|
||||
this.csg = csg;
|
||||
this.dynamic = true; //true by default
|
||||
|
||||
this.meshObject = new THREE.Mesh(this, material);
|
||||
this.cadGroup = new THREE.Object3D();
|
||||
this.cadGroup.__tcad_solid = this;
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
geometry.dynamic = true;
|
||||
this.mesh = new THREE.Mesh(geometry, material);
|
||||
this.cadGroup.add(this.mesh);
|
||||
|
||||
this.tCadId = TCAD.geom.SOLID_COUNTER ++;
|
||||
this.faceCounter = 0;
|
||||
|
||||
this.wireframeGroup = new THREE.Object3D();
|
||||
this.meshObject.add(this.wireframeGroup);
|
||||
this.cadGroup.add(this.wireframeGroup);
|
||||
|
||||
this.polyFaces = [];
|
||||
this.wires = TCAD.struct.hashTable.forEdge();
|
||||
this.curvedSurfaces = {};
|
||||
this.mergeable = true;
|
||||
var scope = this;
|
||||
|
||||
this.setupGeometry();
|
||||
};
|
||||
|
||||
TCAD.Solid.prototype.setupGeometry = function() {
|
||||
function threeV(v) {return new THREE.Vector3( v.x, v.y, v.z )}
|
||||
|
||||
var off = 0;
|
||||
var groups = TCAD.utils.groupCSG(csg);
|
||||
var groups = TCAD.utils.groupCSG(this.csg);
|
||||
var geom = this.mesh.geometry;
|
||||
for (var gIdx in groups) {
|
||||
var group = groups[gIdx];
|
||||
if (group.shared.__tcad === undefined) group.shared.__tcad = {};
|
||||
|
|
@ -638,11 +656,11 @@ TCAD.Solid = function(csg, material, type) {
|
|||
var vLength = poly.vertices.length;
|
||||
if (vLength < 3) continue;
|
||||
var firstVertex = poly.vertices[0];
|
||||
this.vertices.push(threeV(firstVertex.pos));
|
||||
this.vertices.push(threeV(poly.vertices[1].pos));
|
||||
geom.vertices.push(threeV(firstVertex.pos));
|
||||
geom.vertices.push(threeV(poly.vertices[1].pos));
|
||||
var normal = threeV(poly.plane.normal);
|
||||
for (var i = 2; i < vLength; i++) {
|
||||
this.vertices.push(threeV(poly.vertices[i].pos));
|
||||
geom.vertices.push(threeV(poly.vertices[i].pos));
|
||||
|
||||
var a = off;
|
||||
var b = i - 1 + off;
|
||||
|
|
@ -652,29 +670,25 @@ TCAD.Solid = function(csg, material, type) {
|
|||
face.__TCAD_polyFace = polyFace;
|
||||
face.normal = normal;
|
||||
face.materialIndex = gIdx;
|
||||
this.faces.push(face);
|
||||
geom.faces.push(face);
|
||||
//face.color.set(new THREE.Color().setRGB( Math.random(), Math.random(), Math.random()));
|
||||
}
|
||||
//TCAD.view.setFaceColor(polyFace, TCAD.utils.isSmoothPiece(group.shared) ? 0xFF0000 : null);
|
||||
off = this.vertices.length;
|
||||
off = geom.vertices.length;
|
||||
}
|
||||
this.collectCurvedSurface(polyFace);
|
||||
this.collectWires(polyFace);
|
||||
}
|
||||
|
||||
this.mergeVertices();
|
||||
geom.mergeVertices();
|
||||
|
||||
this.processWires();
|
||||
};
|
||||
|
||||
if (typeof THREE !== "undefined") {
|
||||
TCAD.Solid.prototype = Object.create( THREE.Geometry.prototype );
|
||||
}
|
||||
|
||||
TCAD.Solid.prototype.vanish = function() {
|
||||
this.meshObject.parent.remove( this.meshObject );
|
||||
this.meshObject.material.dispose();
|
||||
this.dispose();
|
||||
this.cadGroup.parent.remove( this.cadGroup );
|
||||
this.mesh.material.dispose();
|
||||
this.mesh.geometry.dispose();
|
||||
};
|
||||
|
||||
TCAD.Solid.prototype.collectCurvedSurface = function(face) {
|
||||
|
|
@ -818,7 +832,7 @@ TCAD.SketchFace.prototype.syncSketches = function(geom) {
|
|||
}
|
||||
} else {
|
||||
this.sketch3DGroup = new THREE.Object3D();
|
||||
this.solid.meshObject.add(this.sketch3DGroup);
|
||||
this.solid.cadGroup.add(this.sketch3DGroup);
|
||||
}
|
||||
|
||||
var basis = this.basis();
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ TCAD.App2D.prototype.exportTextData = function(data, ext) {
|
|||
link.download = this.getSketchId() + "." + ext;
|
||||
link.click();
|
||||
//console.log(app.viewer.io.svgExport());
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.App2D.prototype.loadFromLocalStorage = function() {
|
||||
var sketchId = this.getSketchId();
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ TCAD.craft.extrude = function(app, request) {
|
|||
}
|
||||
|
||||
face.csgGroup.shared.__tcad.faceId += '$';
|
||||
return [TCAD.utils.createSolidMesh(meld).geometry];
|
||||
return [TCAD.utils.createSolid(meld)];
|
||||
};
|
||||
|
||||
TCAD.craft._pointOnLine = function(p, a, b) {
|
||||
|
|
@ -799,8 +799,8 @@ TCAD.craft.cut = function(app, request) {
|
|||
for (var si = 0; si < request.solids.length; si++) {
|
||||
var work = request.solids[si].csg;
|
||||
var cut = work.subtract(cutterCSG);
|
||||
var solidMesh = TCAD.utils.createSolidMesh(cut);
|
||||
outSolids.push(solidMesh.geometry);
|
||||
var solidMesh = TCAD.utils.createSolid(cut);
|
||||
outSolids.push(solidMesh);
|
||||
}
|
||||
return outSolids;
|
||||
};
|
||||
|
|
@ -808,26 +808,43 @@ TCAD.craft.cut = function(app, request) {
|
|||
TCAD.Craft = function(app) {
|
||||
this.app = app;
|
||||
this.history = [];
|
||||
this.historyPointer = -1;
|
||||
this._historyPointer = 0;
|
||||
Object.defineProperty(this, "historyPointer", {
|
||||
get: function() {return this._historyPointer},
|
||||
set: function(value) {
|
||||
if (this._historyPointer === value) return;
|
||||
this._historyPointer = value;
|
||||
this.reset(this.history.slice(0, this._historyPointer));
|
||||
this.app.bus.notify('craft');
|
||||
this.app.bus.notify('historyPointer');
|
||||
this.app.viewer.render();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
TCAD.Craft.prototype.loadHistory = function(history) {
|
||||
this.history = -1;
|
||||
this.history = history;
|
||||
this._historyPointer = history.length;
|
||||
this.reset(history);
|
||||
this.app.bus.notify('craft');
|
||||
this.app.bus.notify('historyPointer');
|
||||
this.app.viewer.render();
|
||||
};
|
||||
|
||||
TCAD.Craft.prototype.reset = function(modifications) {
|
||||
TCAD.utils.SOLID_COUNTER = 0;
|
||||
TCAD.geom.SOLID_COUNTER = 0;
|
||||
TCAD.utils.SHARED_COUNTER = 0;
|
||||
this.app.findAllSolids().forEach(function(s) {s.vanish()})
|
||||
for (var i = 0; i < modifications.length; i++) {
|
||||
var request = TCAD.craft.materialize(this.app.indexEntities(), modifications[i]);
|
||||
this.modifyInternal(request);
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.Craft.prototype.finishHistoryEditing = function() {
|
||||
this.loadHistory(this.history);
|
||||
};
|
||||
|
||||
TCAD.Craft.prototype.current = function() {
|
||||
return this.history[this.history.length - 1];
|
||||
};
|
||||
|
|
@ -894,14 +911,20 @@ TCAD.Craft.prototype.modifyInternal = function(request) {
|
|||
request.solids[i].vanish();
|
||||
}
|
||||
for (i = 0; i < newSolids.length; i++) {
|
||||
this.app.viewer.workGroup.add(newSolids[i].meshObject);
|
||||
this.app.viewer.workGroup.add(newSolids[i].cadGroup);
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.Craft.prototype.modify = function(request) {
|
||||
TCAD.Craft.prototype.modify = function(request, overriding) {
|
||||
this.modifyInternal(request);
|
||||
this.history.push(TCAD.craft.detach(request));
|
||||
var detachedRequest = TCAD.craft.detach(request);
|
||||
if (!overriding && this._historyPointer != this.history.length) {
|
||||
this.history.splice(this._historyPointer + 1, 0, null);
|
||||
}
|
||||
this.history[this._historyPointer] = detachedRequest;
|
||||
this._historyPointer ++;
|
||||
this.app.bus.notify('craft');
|
||||
this.app.bus.notify('historyPointer');
|
||||
this.app.viewer.render();
|
||||
};
|
||||
|
||||
|
|
@ -909,9 +932,9 @@ TCAD.craft.OPS = {
|
|||
CUT : TCAD.craft.cut,
|
||||
PAD : TCAD.craft.extrude,
|
||||
PLANE : function(app, request) {
|
||||
return [TCAD.utils.createPlane(request.params.basis, request.params.depth).geometry];
|
||||
return [TCAD.utils.createPlane(request.params.basis, request.params.depth)];
|
||||
},
|
||||
BOX : function(app, request) {
|
||||
return [TCAD.utils.createCSGBox(request.size).geometry];
|
||||
return [TCAD.utils.createCSGBox(request.size)];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
3
web/css/app3d.css
Normal file
3
web/css/app3d.css
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
.history-selected, .history-selected:hover {
|
||||
background-color: #780000;
|
||||
}
|
||||
|
|
@ -123,6 +123,10 @@
|
|||
border-radius: 0 5px 5px 0;
|
||||
}
|
||||
|
||||
.tc-buttons-block-item:last-child:first-child {
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.tc-buttons-block {
|
||||
text-align: right;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="css/toolkit.css">
|
||||
<link rel="stylesheet" href="css/app3d.css">
|
||||
|
||||
|
||||
<script src="lib/jquery-2.1.0.min.js"></script>
|
||||
|
|
|
|||
|
|
@ -106,9 +106,9 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="sketchManager" class="scroll win" style="display: none; min-width: 100px;">
|
||||
<div id="sketchManager" class="win" style="display: none; min-width: 100px;">
|
||||
<div class="tool-caption" >SKETCHES<div class="rm pseudo-btn" style="float: right;">✘</div></div>
|
||||
<div class="content panel" style="padding: 0;">
|
||||
<div class="content panel scroll" style="padding: 0;max-height: 500px;">
|
||||
<ul class="tlist" id='sketchList'>
|
||||
<li>$name$<span class="rm" style="float: right;"><input class="btn sbtn ui-rm" style="" type="submit" value="✘"></span></li>
|
||||
</ul>
|
||||
|
|
|
|||
Loading…
Reference in a new issue