diff --git a/web/app/3d/ctrl.js b/web/app/3d/ctrl.js
index 112ad226..a38537ef 100644
--- a/web/app/3d/ctrl.js
+++ b/web/app/3d/ctrl.js
@@ -9,9 +9,10 @@ TCAD.UI = function(app) {
var cameraFolder = new TCAD.toolkit.Folder("Camera");
var objectsFolder = new TCAD.toolkit.Folder("Objects");
var modificationsFolder = new TCAD.toolkit.Folder("Modifications");
+ var extrude, cut, edit;
TCAD.toolkit.add(box, propFolder);
- TCAD.toolkit.add(propFolder, new TCAD.toolkit.Button("Extrude"));
- TCAD.toolkit.add(propFolder, new TCAD.toolkit.Button("Cut"));
+ TCAD.toolkit.add(propFolder, extrude = new TCAD.toolkit.Button("Extrude"));
+ TCAD.toolkit.add(propFolder, cut = new TCAD.toolkit.Button("Cut"));
TCAD.toolkit.add(propFolder, new TCAD.toolkit.Button("Edit"));
TCAD.toolkit.add(propFolder, new TCAD.toolkit.Button("Refresh Sketches"));
TCAD.toolkit.add(propFolder, new TCAD.toolkit.Text("Message"));
@@ -35,6 +36,32 @@ TCAD.UI = function(app) {
modificationsTreeComp.set(data);
});
+ cut.root.click(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 tk = TCAD.toolkit;
+ var ops = new tk.Box();
+ ops.root.css({left : (box.root.width() + 10) + 'px', top : 0});
+ var folder = new tk.Folder("Cut Options");
+ tk.add(ops, folder);
+ var depth = new tk.Number("Depth", 50);
+ var wizard = new TCAD.wizards.ExtrudeWizard(app.viewer, polygons);
+ depth.input.on('t-change', function() {
+ var depthValue = $(this).val();
+ var target = normal.negate().multiply(depthValue);
+ wizard.update(target);
+ app.viewer.render()
+ });
+ depth.input.trigger('t-change');
+ tk.add(folder, depth);
+ tk.add(folder, new tk.ButtonRow(["Cancel", "OK"], [tk.methodRef(folder, "close"), ]));
+ });
+
this.dat = new dat.GUI();
var gui = this.dat;
diff --git a/web/app/3d/wizards/wizards.js b/web/app/3d/wizards/wizards.js
new file mode 100644
index 00000000..60f38dcd
--- /dev/null
+++ b/web/app/3d/wizards/wizards.js
@@ -0,0 +1,49 @@
+TCAD.wizards = {};
+
+TCAD.wizards.OpWizard = function(viewer) {
+ this.previewGroup = new THREE.Object3D();
+ this.previewGroup.renderDepth = 1e20;
+ viewer.scene.add(this.previewGroup);
+ this.lines = [];
+};
+
+TCAD.wizards.OpWizard.prototype.setupLine = function(lineId, a, b) {
+ var line = this.lines[lineId];
+ if (line === undefined) {
+ var lg = new THREE.Geometry();
+ lg.vertices.push(new THREE.Vector3().copy(a));
+ lg.vertices.push(new THREE.Vector3().copy(b));
+ TCAD.SketchFace.prototype.WIREFRAME_MATERIAL.depthWrite = false;
+ line = new THREE.Segment(lg, TCAD.SketchFace.prototype.WIREFRAME_MATERIAL);
+ line.renderDepth = 0;
+ this.previewGroup.add(line);
+ this.lines[lineId] = line;
+ } else {
+ line.geometry.vertices[0] = new THREE.Vector3().copy(a);
+ line.geometry.vertices[1] = new THREE.Vector3().copy(b);
+ line.geometry.verticesNeedUpdate = true;
+ }
+};
+
+TCAD.wizards.ExtrudeWizard = function(viewer, polygons) {
+ TCAD.wizards.OpWizard.call(this, viewer);
+ this.polygons = polygons;
+};
+
+TCAD.wizards.ExtrudeWizard.prototype = Object.create( TCAD.wizards.OpWizard.prototype );
+
+TCAD.wizards.ExtrudeWizard.prototype.update = function(target) {
+ var linesCounter = 0;
+ for (var i = 0; i < this.polygons.length; i++) {
+ var poly = this.polygons[i];
+ var lid = TCAD.geom.calculateExtrudedLid(poly, target, 1);
+ var p, q, n = poly.length;
+ for (p = n - 1, q = 0; q < n; p = q++) {
+ this.setupLine(linesCounter ++, poly[p], poly[q]);
+ this.setupLine(linesCounter ++, lid[p], lid[q]);
+ }
+ for (q = 0; q < n; q++) {
+ this.setupLine(linesCounter ++, poly[q], lid[q]);
+ }
+ }
+};
diff --git a/web/app/engine.js b/web/app/engine.js
index 89279568..dee46239 100644
--- a/web/app/engine.js
+++ b/web/app/engine.js
@@ -336,6 +336,15 @@ TCAD.geom.isCCW = function(path2D) {
return TCAD.geom.area(path2D) >= 0;
};
+
+TCAD.geom.calculateExtrudedLid = function(sourcePolygon, direction, lateralExpansionFactor) {
+ var lid = [];
+ for (var si = 0; si < sourcePolygon.length; ++si) {
+ lid[si] = sourcePolygon[si].plus(direction);
+ }
+ return lid;
+};
+
TCAD.geom.extrude = function(source, target, sourceNormal) {
var extrudeDistance = target.normalize().dot(sourceNormal);
@@ -345,10 +354,7 @@ TCAD.geom.extrude = function(source, target, sourceNormal) {
var negate = extrudeDistance < 0;
var poly = [null, null];
- var lid = [];
- for (var si = 0; si < source.length; ++si) {
- lid[si] = source[si].plus(target);
- }
+ var lid = TCAD.geom.calculateExtrudedLid(source, target, 1);
var bottom, top;
if (negate) {
@@ -536,9 +542,9 @@ TCAD.SketchFace = function(solid, csgGroup) {
if (typeof THREE !== "undefined") {
TCAD.SketchFace.prototype.SKETCH_MATERIAL = new THREE.LineBasicMaterial({
- color: 0xFFFFFF, linewidth: 3});
+ color: 0xFFFFFF, linewidth: 3/TCAD.DPR});
TCAD.SketchFace.prototype.WIREFRAME_MATERIAL = new THREE.LineBasicMaterial({
- color: 0x2B3856, linewidth: 3});
+ color: 0x2B3856, linewidth: 3/TCAD.DPR});
}
TCAD.SketchFace.prototype.calcBasis = function() {
diff --git a/web/index.html b/web/index.html
index 17119553..57f1f3cf 100644
--- a/web/index.html
+++ b/web/index.html
@@ -13,7 +13,8 @@
-
+
+
@@ -30,6 +31,7 @@
+