mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-15 04:45:06 +01:00
solid transformation controls
This commit is contained in:
parent
54db6f81d6
commit
16028b60f4
3 changed files with 74 additions and 13 deletions
|
|
@ -3,6 +3,7 @@ import * as cad_utils from './cad-utils'
|
|||
import * as math from '../math/math'
|
||||
import * as workbench from './workbench'
|
||||
import {ExtrudeWizard, PlaneWizard} from './wizards/wizards'
|
||||
import {TransformWizard} from './wizards/transform'
|
||||
import {IO} from '../sketcher/io'
|
||||
|
||||
function UI(app) {
|
||||
|
|
@ -149,7 +150,10 @@ function UI(app) {
|
|||
}));
|
||||
var stl = CSG.fromPolygons(allPolygons).toStlString();
|
||||
IO.exportTextData(stl.data[0], app.id + ".stl");
|
||||
})
|
||||
});
|
||||
app.bus.subscribe("solid-pick", function(solid) {
|
||||
new TransformWizard(app.viewer, solid).createUI(mainBox);
|
||||
});
|
||||
}
|
||||
|
||||
UI.prototype.getInfoForOp = function(op) {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,11 @@ function Viewer(bus) {
|
|||
};
|
||||
|
||||
function onClick(e) {
|
||||
viewer.selectionMgr.handlePick(e);
|
||||
if (e.button != 0) {
|
||||
viewer.handleSolidPick(e);
|
||||
} else {
|
||||
viewer.selectionMgr.handlePick(e);
|
||||
}
|
||||
}
|
||||
|
||||
var mouseState = {
|
||||
|
|
@ -143,6 +147,29 @@ function Viewer(bus) {
|
|||
animate();
|
||||
}
|
||||
|
||||
Viewer.prototype.handleSolidPick = function(e) {
|
||||
this.raycastFaces(event, this, function(sketchFace) {
|
||||
this.selectionMgr.clear();
|
||||
this.bus.notify("solid-pick", sketchFace.solid);
|
||||
this.render();
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Viewer.prototype.raycastFaces = function(event, scope, visitor) {
|
||||
var pickResults = this.raycast(event);
|
||||
for (var i = 0; i < pickResults.length; i++) {
|
||||
var pickResult = pickResults[i];
|
||||
if (!!pickResult.face && pickResult.face.__TCAD_polyFace !== undefined) {
|
||||
var sketchFace = pickResult.face.__TCAD_polyFace;
|
||||
if (!visitor.call(scope, sketchFace)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Viewer.setFacesColor = function(faces, color) {
|
||||
for (var i = 0; i < faces.length; ++i) {
|
||||
var face = faces[i];
|
||||
|
|
@ -200,18 +227,13 @@ SelectionManager.prototype.updateBasis = function(basis, depth) {
|
|||
};
|
||||
|
||||
SelectionManager.prototype.handlePick = function(event) {
|
||||
|
||||
var pickResults = this.viewer.raycast(event);
|
||||
for (var i = 0; i < pickResults.length; i++) {
|
||||
var pickResult = pickResults[i];
|
||||
if (!!pickResult.face && pickResult.face.__TCAD_polyFace !== undefined) {
|
||||
var sketchFace = pickResult.face.__TCAD_polyFace;
|
||||
if (!this.contains(sketchFace)) {
|
||||
this.select(sketchFace);
|
||||
break;
|
||||
}
|
||||
this.viewer.raycastFaces(event, this, function(sketchFace) {
|
||||
if (!this.contains(sketchFace)) {
|
||||
this.select(sketchFace);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
SelectionManager.prototype.select = function(sketchFace) {
|
||||
|
|
|
|||
35
web/app/3d/wizards/transform.js
Normal file
35
web/app/3d/wizards/transform.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import * as tk from '../../ui/toolkit'
|
||||
|
||||
export function TransformWizard(viewer, solid) {
|
||||
this.viewer = viewer;
|
||||
this.solid = solid;
|
||||
}
|
||||
|
||||
TransformWizard.prototype.createUI = function(alignComponent) {
|
||||
this.viewer.transformControls.attach(this.solid.cadGroup);
|
||||
this.viewer.render();
|
||||
var box = new tk.Box();
|
||||
box.root.css({left : (alignComponent.root.width() + 10) + 'px', top : 0});
|
||||
var folder = new tk.Folder("Transformation");
|
||||
tk.add(box, folder);
|
||||
var wizard = this;
|
||||
function close() {
|
||||
box.close();
|
||||
wizard.dispose();
|
||||
}
|
||||
function apply() {
|
||||
//app.craft.modify({
|
||||
// type: 'PLANE',
|
||||
// solids : [],
|
||||
// params : wizard.operationParams,
|
||||
// protoParams : protoParams()
|
||||
//}, overiding);
|
||||
close();
|
||||
}
|
||||
tk.add(folder, new tk.ButtonRow(["Cancel", "Apply"], [close, apply]));
|
||||
};
|
||||
|
||||
TransformWizard.prototype.dispose = function() {
|
||||
this.viewer.transformControls.detach(this.solid.cadGroup);
|
||||
this.viewer.render();
|
||||
};
|
||||
Loading…
Reference in a new issue