diff --git a/web/app/brep/brep-builder.js b/web/app/brep/brep-builder.js index be0f1e63..e43f17f8 100644 --- a/web/app/brep/brep-builder.js +++ b/web/app/brep/brep-builder.js @@ -102,10 +102,26 @@ export function createBoundingSurface(points, plane) { return createBoundingSurfaceFrom2DPoints(points2d, plane); } -export function createBoundingSurfaceFrom2DPoints(points2d, plane) { +export function createBoundingSurfaceFrom2DPoints(points2d, plane, minWidth, minHeight, offset = 0, ) { let bBox = new BBox(); points2d.forEach(p => bBox.checkPoint(p)); + if (minWidth && bBox.width() < minWidth) { + bBox.checkBounds( minWidth * 0.5, 0); + bBox.checkBounds(- minWidth * 0.5, 0); + } + if (minHeight && bBox.height() < minHeight) { + bBox.checkBounds(0, minHeight * 0.5); + bBox.checkBounds(0, - minHeight * 0.5); + } + + if (offset !== 0) { + bBox.maxX += offset * 0.5; + bBox.minX -= offset * 0.5; + bBox.maxY += offset * 0.5; + bBox.minY -= offset * 0.5; + } + let to3D = plane.get3DTransformation(); let polygon = bBox.toPolygon(); polygon = polygon.map(p => to3D._apply(p).data()); diff --git a/web/app/cad/craft/primitives/planeOperation.js b/web/app/cad/craft/primitives/planeOperation.js index 9f958f83..38ed152d 100644 --- a/web/app/cad/craft/primitives/planeOperation.js +++ b/web/app/cad/craft/primitives/planeOperation.js @@ -4,8 +4,8 @@ import {Plane} from '../../../brep/geom/impl/plane'; import Vector from 'math/vector'; import PlaneWizard from './PlaneWizard'; import {MOpenFaceShell} from '../../model/mopenFace'; -import {createBoundingSurfaceFrom2DPoints} from '../../../brep/brep-builder'; import schema from './planeOpSchema'; +import {PlaneSurfacePrototype} from '../../model/surfacePrototype'; function paramsToPlane({orientation, parallelTo, depth}, cadRegistry) { let face = null; @@ -23,25 +23,22 @@ function paramsToPlane({orientation, parallelTo, depth}, cadRegistry) { } function createPlane(params, {cadRegistry}) { - let surface = createBoundingSurfaceFrom2DPoints([ - new Vector(0,0,0), new Vector(0,100,0), new Vector(100,100,0), new Vector(100,0,0) - ], paramsToPlane(params, cadRegistry)); return { outdated: [], - created: [new MOpenFaceShell(surface)] + created: [new MOpenFaceShell(new PlaneSurfacePrototype(paramsToPlane(params, cadRegistry)))] } } function previewGeomProvider(params, {cadRegistry}) { let plane = paramsToPlane(params, cadRegistry); - let _3DTransformation = plane.get3DTransformation(); + let tr = plane.get3DTransformation(); const w = 375, h = 375; - const a = new Vector(-w, -h, 0); - const b = new Vector( w, -h, 0); - const c = new Vector( w, h, 0); - const d = new Vector(-w, h, 0); + const a = tr._apply(new Vector(-w, -h, 0)); + const b = tr._apply(new Vector( w, -h, 0)); + const c = tr._apply(new Vector( w, h, 0)); + const d = tr._apply(new Vector(-w, h, 0)); + let trs = [[a, b, c], [a, c, d]]; - trs.forEach(tr => tr.forEach(p => _3DTransformation._apply(p))); return createMeshGeometry(trs); } diff --git a/web/app/cad/model/mface.js b/web/app/cad/model/mface.js index c6161ade..963bde71 100644 --- a/web/app/cad/model/mface.js +++ b/web/app/cad/model/mface.js @@ -3,6 +3,8 @@ import Vector from 'math/vector'; import {BasisForPlane} from '../../math/l3space'; import {MSketchObject} from './msketchObject'; import {EMPTY_ARRAY} from 'gems/iterables'; +import {PointOnSurface} from '../../brep/geom/pointOnSurface'; +import CSys from '../../math/csys'; export class MFace extends MObject { diff --git a/web/app/cad/model/mopenFace.js b/web/app/cad/model/mopenFace.js index eb8bcec3..d61226da 100644 --- a/web/app/cad/model/mopenFace.js +++ b/web/app/cad/model/mopenFace.js @@ -3,9 +3,11 @@ import {MFace} from './mface'; export class MOpenFaceShell extends MShell { - constructor(surface) { + constructor(surfacePrototype) { super(); - this.faces.push(new MFace(this.id + '/SURFACE', this, surface)) + this.surfacePrototype = surfacePrototype; + this.faces.push(new MFace(this.id + '/SURFACE', this, + surfacePrototype.boundTo([], 100, 100))); } get face() { diff --git a/web/app/cad/model/surfacePrototype.js b/web/app/cad/model/surfacePrototype.js new file mode 100644 index 00000000..c6ec0d5d --- /dev/null +++ b/web/app/cad/model/surfacePrototype.js @@ -0,0 +1,21 @@ +import {createBoundingSurfaceFrom2DPoints} from '../../brep/brep-builder'; + +export class SurfacePrototype { + + boundTo(points2dOnSurface, minWidth, minHeight, offset) { + throw 'abstract'; + } + +} + +export class PlaneSurfacePrototype extends SurfacePrototype { + + constructor(plane) { + super(); + this.plane = plane; + } + + boundTo(points2dOnSurface, minWidth, minHeight, offset) { + return createBoundingSurfaceFrom2DPoints(points2dOnSurface, this.plane, minWidth, minHeight, offset); + } +} \ No newline at end of file diff --git a/web/app/cad/scene/views/openFaceView.js b/web/app/cad/scene/views/openFaceView.js index d5bde424..06ddd230 100644 --- a/web/app/cad/scene/views/openFaceView.js +++ b/web/app/cad/scene/views/openFaceView.js @@ -1,20 +1,8 @@ -import Vector from '../../../../../modules/math/vector'; import {setAttribute} from '../../../../../modules/scene/objectData'; import {FACE, SHELL} from '../entites'; import {SELECTION_COLOR, setFacesColor, SketchingView} from './faceView'; import {View} from './view'; -const INIT_WIDTH_H = 750 * 0.5; -const INIT_HEIGHT_H = 750 * 0.5; - -export const INIT_BOUNDS = [ - new Vector(-INIT_WIDTH_H, -INIT_HEIGHT_H, 0), - new Vector( INIT_WIDTH_H, -INIT_HEIGHT_H, 0), - new Vector( INIT_WIDTH_H, INIT_HEIGHT_H, 0), - new Vector(-INIT_WIDTH_H, INIT_HEIGHT_H, 0) -]; - - export class OpenFaceShellView extends View { constructor(shell) { @@ -47,7 +35,7 @@ export class OpenFaceView extends SketchingView { transparent: true, opacity: 0.5 }); - this.updateBounds(INIT_BOUNDS); + this.updateBounds(); } dropGeometry() { @@ -69,20 +57,24 @@ export class OpenFaceView extends SketchingView { this.rootGroup.add(this.mesh); } - updateBounds(bounds2d) { + updateBounds() { this.dropGeometry(); - const tr = this.model.sketchToWorldTransformation; - this.bounds = bounds2d.map(v => tr.apply(v)); + + + let bounds2d = []; + for (let mSketchObject of this.model.sketchObjects) { + mSketchObject.sketchPrimitive.tessellate().forEach(p => bounds2d.push(p)); + } + let surface = this.model.shell.surfacePrototype.boundTo(bounds2d, 750, 750, 50); + this.bounds = [surface.southWestPoint(), surface.southEastPoint(), + surface.northEastPoint(), surface.northWestPoint()]; + this.createGeometry(); } updateSketch() { super.updateSketch(); - // let bounds2d = ... - // for (let mSketchObject of this.model.sketchObjects) { - // mSketchObject.sketchPrimitive.tessellate(...to bounds2d) - // } - // this.updateBounds(bounds2d) + this.updateBounds(); } mark(color) {