mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +01:00
introducing wizards
This commit is contained in:
parent
dd3dceaaab
commit
503d86c362
4 changed files with 93 additions and 9 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
49
web/app/3d/wizards/wizards.js
Normal file
49
web/app/3d/wizards/wizards.js
Normal file
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
<script src="lib/jquery-2.1.0.min.js"></script>
|
||||
<script src="lib/three/three.js"></script>
|
||||
<script> THREE.Line = THREE.Segment </script><!-- Intelij renamed all THREE.Line to THREE.Segment by mistake. It will not be needed after updating three.js-->
|
||||
|
||||
<script> THREE.Segment = THREE.Line </script><!-- Intelij renamed all THREE.Line to THREE.Segment by mistake. It will not be needed after updating three.js-->
|
||||
<script src="lib/three/TrackballControls.js"></script>
|
||||
<script src="lib/three/OrbitControls.js"></script>
|
||||
<script src="lib/three/TransformControls.js"></script>
|
||||
|
|
@ -30,6 +31,7 @@
|
|||
<script src="app/math/graph.js"></script>
|
||||
<script src="app/3d/hashmap.js"></script>
|
||||
<script src="app/ui/toolkit.js"></script>
|
||||
<script src="app/3d/wizards/wizards.js"></script>
|
||||
|
||||
<script>window.onload = function() {
|
||||
window._TCAD_APP = new TCAD.App();
|
||||
|
|
|
|||
Loading…
Reference in a new issue