From 109d831b55c7bb5739d400aca2f33dbe13c520d3 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Thu, 16 Mar 2017 00:34:08 -0700 Subject: [PATCH] fix history handling after BREP refactoring --- web/app/3d/craft/brep/cut-extrude.js | 2 +- web/app/3d/craft/brep/wizards/wizard.js | 5 +- web/app/3d/modeler-app.js | 27 +++++++- web/app/3d/triangulation.js | 88 ++++++++++++++++++++++--- web/app/3d/ui/bind.js | 2 + web/app/3d/ui/ctrl.js | 13 +--- 6 files changed, 115 insertions(+), 22 deletions(-) diff --git a/web/app/3d/craft/brep/cut-extrude.js b/web/app/3d/craft/brep/cut-extrude.js index c99f9f70..241c13dc 100644 --- a/web/app/3d/craft/brep/cut-extrude.js +++ b/web/app/3d/craft/brep/cut-extrude.js @@ -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)); diff --git a/web/app/3d/craft/brep/wizards/wizard.js b/web/app/3d/craft/brep/wizards/wizard.js index 02040488..4769c6d9 100644 --- a/web/app/3d/craft/brep/wizards/wizard.js +++ b/web/app/3d/craft/brep/wizards/wizard.js @@ -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; } }); } diff --git a/web/app/3d/modeler-app.js b/web/app/3d/modeler-app.js index 45d22383..aae543e7 100644 --- a/web/app/3d/modeler-app.js +++ b/web/app/3d/modeler-app.js @@ -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) { diff --git a/web/app/3d/triangulation.js b/web/app/3d/triangulation.js index 001aac43..52961c91 100644 --- a/web/app/3d/triangulation.js +++ b/web/app/3d/triangulation.js @@ -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; } \ No newline at end of file diff --git a/web/app/3d/ui/bind.js b/web/app/3d/ui/bind.js index 7d8ac6ae..36d5774e 100644 --- a/web/app/3d/ui/bind.js +++ b/web/app/3d/ui/bind.js @@ -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); diff --git a/web/app/3d/ui/ctrl.js b/web/app/3d/ui/ctrl.js index 29478455..52fff4bc 100644 --- a/web/app/3d/ui/ctrl.js +++ b/web/app/3d/ui/ctrl.js @@ -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);