mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 09:52:34 +01:00
fix history handling after BREP refactoring
This commit is contained in:
parent
d89ba309b8
commit
109d831b55
6 changed files with 115 additions and 22 deletions
|
|
@ -75,7 +75,7 @@ export class ParametricExtruder extends Extruder {
|
|||
|
||||
calculateLid(basePoints) {
|
||||
if (this.params.prism != 1) {
|
||||
const scale = this.params.prism < 0.001 ? 0.0001 : this.params.prism;
|
||||
const scale = this.params.prism;
|
||||
const _3Dtr = this.face.brepFace.surface.get3DTransformation();
|
||||
const _2Dtr = _3Dtr.invert();
|
||||
const poly2d = basePoints.map(p => _2Dtr.apply(p));
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export class Wizard {
|
|||
this.metadata = metadata;
|
||||
this.formFields = {};
|
||||
this.box = this.createUI(opearation, metadata);
|
||||
this.overridingHistory = false;
|
||||
if (initialState != undefined) {
|
||||
this.setFormFields(initialState);
|
||||
}
|
||||
|
|
@ -64,7 +65,7 @@ export class Wizard {
|
|||
}
|
||||
|
||||
apply() {
|
||||
this.app.craft.modify(this.createRequest(), false);
|
||||
this.app.craft.modify(this.createRequest(), this.overridingHistory);
|
||||
}
|
||||
|
||||
onUIChange() {}
|
||||
|
|
@ -109,6 +110,8 @@ export class Wizard {
|
|||
if (faceId === CURRENT_SELECTION) {
|
||||
let selection = this.app.viewer.selectionMgr.selection[0];
|
||||
return selection ? selection.id : '';
|
||||
} else {
|
||||
return faceId;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import '../../css/app3d.less'
|
|||
import * as BREPBuilder from '../brep/brep-builder'
|
||||
import * as BREPPrimitives from '../brep/brep-primitives'
|
||||
import * as BREPBool from '../brep/operations/boolean'
|
||||
import * as BREPMeshBool from './craft/mesh/mesh-boolean'
|
||||
import {BREPValidator} from '../brep/brep-validator'
|
||||
import {BREPSceneSolid} from './scene/brep-scene-object'
|
||||
import TPI from './tpi'
|
||||
|
|
@ -82,7 +83,7 @@ App.prototype.addShellOnScene = function(shell, skin) {
|
|||
};
|
||||
|
||||
App.prototype.scratchCode = function() {
|
||||
this.addShellOnScene(BREPPrimitives.box(500, 500, 500)); return;
|
||||
this.BREPMeshTestImpl(); return;
|
||||
|
||||
const boxWithHole = BREPBool.subtract(BREPPrimitives.box(500, 500, 500), BREPPrimitives.box(500, 300, 300));
|
||||
//this.addShellOnScene(boxWithHole);
|
||||
|
|
@ -247,6 +248,30 @@ App.prototype.BREPTestImpl = function() {
|
|||
|
||||
};
|
||||
|
||||
App.prototype.BREPMeshTestImpl = function() {
|
||||
const box1 = BREPPrimitives.box(500, 500, 500);
|
||||
const box2 = BREPPrimitives.box(250, 250, 750, new Matrix3().translate(25, 25, 0));
|
||||
//const box3 = BREPPrimitives.box(150, 600, 350, new Matrix3().translate(25, 25, -250));
|
||||
|
||||
BREPValidator.validateToConsole(box1);
|
||||
|
||||
//box1.faces = [box1.faces[2]];
|
||||
//box2.faces = [box2.faces[5]];
|
||||
|
||||
//addToScene(box1);
|
||||
//addToScene(box2);
|
||||
//addToScene(box3);
|
||||
|
||||
let result = BREPMeshBool.subtract(box1, box2);
|
||||
//result = BREPBool.subtract(result, box3);
|
||||
//this.addShellOnScene(result);
|
||||
//addToScene(box1);
|
||||
|
||||
this.viewer.render()
|
||||
|
||||
};
|
||||
|
||||
|
||||
App.prototype.processHints = function() {
|
||||
let id = window.location.hash.substring(1);
|
||||
if (!id) {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,12 @@
|
|||
import libtess from 'libtess'
|
||||
import {Point} from '../brep/geom/point'
|
||||
import {Vertex} from '../brep/topo/vertex'
|
||||
|
||||
function initTesselator() {
|
||||
// function called for each vertex of tesselator output
|
||||
function vertexCallback(data, polyVertArray) {
|
||||
polyVertArray.push(data);
|
||||
}
|
||||
function begincallback(type) {
|
||||
if (type !== libtess.primitiveType.GL_TRIANGLES) {
|
||||
console.log('expected TRIANGLES but got type: ' + type);
|
||||
}
|
||||
}
|
||||
function errorcallback(errno) {
|
||||
console.log('error callback');
|
||||
console.log('error number: ' + errno);
|
||||
}
|
||||
// callback for when segments intersect and must be split
|
||||
function combinecallback(coords, data, weight) {
|
||||
// console.log('combine callback');
|
||||
|
|
@ -35,6 +28,18 @@ function initTesselator() {
|
|||
return tessy;
|
||||
}
|
||||
|
||||
function begincallback(type) {
|
||||
if (type !== libtess.primitiveType.GL_TRIANGLES) {
|
||||
console.log('expected TRIANGLES but got type: ' + type);
|
||||
}
|
||||
}
|
||||
|
||||
function errorcallback(errno) {
|
||||
console.log('error callback');
|
||||
console.log('error number: ' + errno);
|
||||
}
|
||||
|
||||
|
||||
export function Triangulate(contours, normal) {
|
||||
const tessy = initTesselator();
|
||||
// libtess will take 3d verts and flatten to a plane for tesselation
|
||||
|
|
@ -58,4 +63,69 @@ export function Triangulate(contours, normal) {
|
|||
// finish polygon (and time triangulation process)
|
||||
tessy.gluTessEndPolygon();
|
||||
return triangleVerts;
|
||||
}
|
||||
|
||||
export function TriangulateFace(face) {
|
||||
function arr(v) {
|
||||
return [v.x, v.y, v.z];
|
||||
}
|
||||
|
||||
function vertexCallback(data, out) {
|
||||
out.push(data);
|
||||
}
|
||||
let edge = false;
|
||||
function combinecallback(coords, data, weight) {
|
||||
throw 'should never happen cuz brep is non-manifold'
|
||||
//const point = new Point(coords[0], coords[1], coords[2]);
|
||||
//if (edge) {
|
||||
// const vertex = new Vertex(point);
|
||||
// data.edge.split(vertex);
|
||||
// return {
|
||||
// edge: data.edge.next,
|
||||
// point
|
||||
// }
|
||||
//} else {
|
||||
// return {
|
||||
// edge: null,
|
||||
// point
|
||||
// }
|
||||
//}
|
||||
}
|
||||
function edgeCallback(flag) {
|
||||
edge = flag;
|
||||
}
|
||||
|
||||
var tessy = new libtess.GluTesselator();
|
||||
// tessy.gluTessProperty(libtess.gluEnum.GLU_TESS_WINDING_RULE, libtess.windingRule.GLU_TESS_WINDING_POSITIVE);
|
||||
tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_VERTEX_DATA, vertexCallback);
|
||||
tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_BEGIN, begincallback);
|
||||
tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_ERROR, errorcallback);
|
||||
tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_COMBINE, combinecallback);
|
||||
tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_EDGE_FLAG, edgeCallback);
|
||||
|
||||
const normal = arr(face.surface.normal);
|
||||
tessy.gluTessNormal(normal[0], normal[1], normal[2]);
|
||||
|
||||
const vertices = [];
|
||||
tessy.gluTessBeginPolygon(vertices);
|
||||
|
||||
for (let loop of face.loops) {
|
||||
tessy.gluTessBeginContour();
|
||||
for (let e of loop.halfEdges) {
|
||||
tessy.gluTessVertex(arr(e.vertexA.point), e.vertexA);
|
||||
}
|
||||
tessy.gluTessEndContour();
|
||||
}
|
||||
|
||||
tessy.gluTessEndPolygon();
|
||||
|
||||
const triangled = [];
|
||||
|
||||
for (let i = 0; i < vertices.length; i += 3 ) {
|
||||
var a = vertices[i];
|
||||
var b = vertices[i + 1];
|
||||
var c = vertices[i + 2];
|
||||
triangled.push([a, b, c]);
|
||||
}
|
||||
return triangled;
|
||||
}
|
||||
|
|
@ -60,6 +60,8 @@ export function BindArray(node, array, policy) {
|
|||
domItem = scope.nestedScopes[value.id];
|
||||
if (!domItem) {
|
||||
domItem = createFromTemplate(value.id);
|
||||
} else {
|
||||
domItem = domItem[0];
|
||||
}
|
||||
if (domPointer == 0) {
|
||||
node.prepend(domItem);
|
||||
|
|
|
|||
|
|
@ -133,15 +133,8 @@ UI.prototype.fillControlBar = function() {
|
|||
|
||||
UI.prototype.registerWizard = function(wizard, overridingHistory) {
|
||||
wizard.box.root.css({left : (this.mainBox.root.width() + this.craftToolBar.node.width() + 30) + 'px', top : 0});
|
||||
var craft = this.app.craft;
|
||||
wizard.onRequestReady = function(request) {
|
||||
if (request.invalidAndShouldBeDropped == true) {
|
||||
alert(request.message);
|
||||
} else {
|
||||
craft.modify(request, overridingHistory);
|
||||
}
|
||||
};
|
||||
|
||||
var craft = this.app.craft;
|
||||
wizard.overridingHistory = overridingHistory;
|
||||
wizard.focus();
|
||||
if (this.registeredWizard != undefined) {
|
||||
if (!this.registeredWizard.disposed) {
|
||||
|
|
@ -167,7 +160,7 @@ UI.prototype.initOperation = function(op) {
|
|||
};
|
||||
|
||||
UI.prototype.createWizardForOperation = function(op) {
|
||||
var initParams = op.protoParams;
|
||||
var initParams = op.params;
|
||||
var face = op.face !== undefined ? this.app.findFace(op.face) : null;
|
||||
if (face != null) {
|
||||
this.app.viewer.selectionMgr.select(face);
|
||||
|
|
|
|||
Loading…
Reference in a new issue