make extruding from plane work

This commit is contained in:
Val Erastov 2017-03-24 17:00:11 -07:00
parent 37306ea789
commit 95c69ec101
6 changed files with 38 additions and 26 deletions

View file

@ -23,19 +23,28 @@ export function Cut(app, params) {
export function doOperation(app, params, cut) {
const face = app.findFace(params.face);
const solid = face.solid;
const sketch = ReadSketchFromFace(app, face);
const reverseNormal = !cut;
let normal = face.normal();
if (reverseNormal) normal = normal.negate();
const sketch = ReadSketchFromFace(app, face, reverseNormal);
const extruder = new ParametricExtruder(params);
let normal = face.brepFace.surface.normal;
if (!cut) normal = normal.negate();
const operand = combineShells(sketch.map(s => extruder.extrude(s, normal)));
BREPValidator.validateToConsole(operand);
const op = cut ? subtract : union;
const result = op(solid.shell, operand);
for (let newFace of result.faces) {
if (newFace.id == face.id) {
newFace.id = undefined;
let result;
if (solid instanceof BREPSceneSolid) {
const op = cut ? subtract : union;
result = op(solid.shell, operand);
for (let newFace of result.faces) {
if (newFace.id == face.id) {
newFace.id = undefined;
}
}
} else {
if (cut) throw 'unable to cut plane';
result = operand;
}
approx.update(result);
const newSolid = new BREPSceneSolid(result);

View file

@ -4,6 +4,6 @@ import {sortPolygons, getSketchedPolygons3D} from '../mesh/workbench'
// here will be function of conversion sketch objects to brep DS
export function ReadSketchFromFace(app, face) {
return getSketchedPolygons3D(app, face);
export function ReadSketchFromFace(app, face, reverseGeom) {
return getSketchedPolygons3D(app, face, reverseGeom);
}

View file

@ -50,9 +50,9 @@ export class ExtrudePreviewer extends SketchBasedPreviewer {
createImpl(app, params, sketch, face) {
const parametricExtruder = new ParametricExtruder(params);
const surface = face.brepFace.surface;
const baseNormal = this.inversed ? surface.normal : surface.normal.negate();
const lidNormal = this.inversed ? baseNormal.negate() : surface.normal;
const normal = face.normal();
const baseNormal = this.inversed ? normal : normal.negate();
const lidNormal = this.inversed ? baseNormal.negate() : normal;
parametricExtruder.prepareLidCalculation(baseNormal, lidNormal);

View file

@ -65,7 +65,7 @@ PreviewWizard.createMesh = function(triangles) {
export class SketchBasedPreviewer {
constructor() {
this.fixToCCW = true;
//this.fixToCCW = true;
}
createImpl(app, params, sketch, face) {
@ -78,11 +78,11 @@ export class SketchBasedPreviewer {
const needSketchRead = !this.sketch || params.face != this.face;
if (needSketchRead) {
this.sketch = ReadSketchFromFace(app, face);
for (let polygon of this.sketch) {
if (!Loop.isPolygonCCWOnSurface(polygon, face.brepFace.surface) && this.fixToCCW) {
polygon.reverse();
}
}
//for (let polygon of this.sketch) {
//if (!Loop.isPolygonCCWOnSurface(polygon, face.brepFace.surface) && this.fixToCCW) {
// polygon.reverse();
//}
//}
this.face = params.face;
}
const triangles = this.createImpl(app, params, this.sketch, face);

View file

@ -162,15 +162,16 @@ export function approxBezierCurve(a, b, cp1, cp2, resolution) {
return LUT(a, b, cp1, cp2, 10);
}
export function getSketchedPolygons3D(app, face) {
export function getSketchedPolygons3D(app, face, reverseGeom) {
var savedFace = localStorage.getItem(app.faceStorageKey(face.id));
if (savedFace == null) return null;
var geom = readSketchGeom(JSON.parse(savedFace), face.id, false);
var polygons2D = cad_utils.sketchToPolygons(geom);
var normal = face.normal();
if (reverseGeom) {
polygons2D.forEach(p => p.reverse());
}
var depth = null;
var sketchedPolygons = [];
for (var i = 0; i < polygons2D.length; i++) {

View file

@ -157,9 +157,11 @@ export class SelectionManager extends AbstractSelectionManager {
if (sceneFace.curvedSurfaces) {
return sceneFace.curvedSurfaces;
}
const approxFace = sceneFace.brepFace.data[approx.FACE_CHUNK];
if (approxFace) {
return approxFace.faces.map(f => f.data['scene.face']);
if (sceneFace.brepFace) {
const approxFace = sceneFace.brepFace.data[approx.FACE_CHUNK];
if (approxFace) {
return approxFace.faces.map(f => f.data['scene.face']);
}
}
return undefined;
}