allow negative values for extrude

This commit is contained in:
Val Erastov 2017-03-24 17:43:26 -07:00
parent 3cecd933da
commit 65117c184c
5 changed files with 29 additions and 12 deletions

View file

@ -23,9 +23,14 @@ export function Cut(app, params) {
export function doOperation(app, params, cut) {
const face = app.findFace(params.face);
const solid = face.solid;
const reverseNormal = !cut;
let reverseNormal = !cut;
let normal = face.normal();
if (params.value < 0) {
params = fixNegativeValue(params);
reverseNormal = !reverseNormal;
}
if (reverseNormal) normal = normal.negate();
const sketch = ReadSketchFromFace(app, face, reverseNormal);
@ -54,6 +59,14 @@ export function doOperation(app, params, cut) {
}
}
export function fixNegativeValue(params) {
if (params.value < 0) {
params = Object.assign({}, params);
params.value *= -1;
}
return params;
}
function combineShells(shells) {
if (shells.length == 1) {
return shells[0];

View file

@ -1,9 +1,9 @@
import {CURRENT_SELECTION as S} from './wizard'
import {PreviewWizard, SketchBasedPreviewer} from './preview-wizard'
import {ParametricExtruder} from '../cut-extrude'
import {ParametricExtruder, fixNegativeValue} from '../cut-extrude'
const METADATA = [
['value' , 'number', 50, {min: 0}],
['value' , 'number', 50],
['prism' , 'number', 1 , {min: 0, step: 0.1, round: 1}],
['angle' , 'number', 0 , {}],
['rotation', 'number', 0 , {step: 5}],
@ -48,11 +48,15 @@ export class ExtrudePreviewer extends SketchBasedPreviewer {
}
createImpl(app, params, sketch, face) {
const parametricExtruder = new ParametricExtruder(params);
const normal = face.normal();
const baseNormal = this.inversed ? normal : normal.negate();
const lidNormal = this.inversed ? baseNormal.negate() : normal;
let reverseNormal = this.inversed;
if (params.value < 0) {
params = fixNegativeValue(params);
reverseNormal = !reverseNormal;
}
const parametricExtruder = new ParametricExtruder(params);
const baseNormal = reverseNormal ? normal : normal.negate();
const lidNormal = reverseNormal ? baseNormal.negate() : normal;
parametricExtruder.prepareLidCalculation(baseNormal, lidNormal);

View file

@ -17,8 +17,8 @@ export class PlaneWizard extends PreviewWizard {
createPreviewObject(app, params) {
let face = null;
if (params.face) {
face = this.app.findFace(params.face);
if (params.parallelTo) {
face = this.app.findFace(params.parallelTo);
}
let basis;
let depth = params.depth;

View file

@ -52,7 +52,7 @@ export const PLANE = {
action: (app, request) => {
return {
outdated: [],
created: [PlaneSceneObject.create(request)]
created: [PlaneSceneObject.create(request, (f) => app.findFace(f))]
}
}
};

View file

@ -56,8 +56,8 @@ export class PlaneSceneObject extends SceneSolid {
static create(params, faceResolver) {
let face = null;
if (params.face) {
face = faceResolver(params.face);
if (params.parallelTo) {
face = faceResolver(params.parallelTo);
}
let plane = null;
if (face == null) {