From 12341bf26c962eec2cd6ff683c11bf9fc2ad826c Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Tue, 30 Oct 2018 22:54:46 -0700 Subject: [PATCH] store coordinate system for a shell and use to derive coordinate system of its faces --- web/app/cad/model/mface.js | 7 +++++-- web/app/cad/model/mopenFace.js | 1 + web/app/cad/model/mshell.js | 4 +++- web/app/cad/scene/wrappers/entityIO.js | 5 +++-- web/app/math/l3space.js | 8 ++++---- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/web/app/cad/model/mface.js b/web/app/cad/model/mface.js index 69a3ce79..595f68fc 100644 --- a/web/app/cad/model/mface.js +++ b/web/app/cad/model/mface.js @@ -47,8 +47,11 @@ export class MFace extends MObject { evalCSys() { if (!this._csys) { if (this.isPlaneBased) { - let [x, y, z] = this.surface.simpleSurface.basis(); - let origin = z.multiply(this.surface.simpleSurface.w); + let alignCsys = (this.shell && this.shell.csys) || CSys.ORIGIN; + let [x, y, z] = BasisForPlane(this.surface.simpleSurface.normal, alignCsys.y, alignCsys.z); + let proj = z.dot(alignCsys.origin); + proj -= this.surface.simpleSurface.w; + let origin = alignCsys.origin.minus(z.multiply(proj)); this._csys = new CSys(origin, x, y, z); } else { let origin = this.surface.southWestPoint(); diff --git a/web/app/cad/model/mopenFace.js b/web/app/cad/model/mopenFace.js index 07ed97d7..5a1fe3c0 100644 --- a/web/app/cad/model/mopenFace.js +++ b/web/app/cad/model/mopenFace.js @@ -6,6 +6,7 @@ export class MOpenFaceShell extends MShell { constructor(surfacePrototype, csys) { super(); this.surfacePrototype = surfacePrototype; + this.csys = csys; this.faces.push(new MFace(this.id + '/SURFACE', this, surfacePrototype.boundTo([], 100, 100), csys)); } diff --git a/web/app/cad/model/mshell.js b/web/app/cad/model/mshell.js index 7a29ceff..021283c4 100644 --- a/web/app/cad/model/mshell.js +++ b/web/app/cad/model/mshell.js @@ -2,6 +2,7 @@ import {MObject} from './mobject'; import {MBrepFace, MFace} from './mface'; import {MEdge} from './medge'; import {MVertex} from './mvertex'; +import CSys from '../../math/csys'; export class MShell extends MObject { @@ -18,9 +19,10 @@ export class MShell extends MObject { export class MBrepShell extends MShell { - constructor(shell) { + constructor(shell, csys) { super(); this.brepShell = shell; + this.csys = csys || CSys.ORIGIN; let faceCounter = 0; let edgeCounter = 0; diff --git a/web/app/cad/scene/wrappers/entityIO.js b/web/app/cad/scene/wrappers/entityIO.js index a6e4c2d7..314e1d9d 100644 --- a/web/app/cad/scene/wrappers/entityIO.js +++ b/web/app/cad/scene/wrappers/entityIO.js @@ -1,7 +1,8 @@ import {readBrep} from '../../../brep/io/brepIO'; import {MBrepShell} from '../../model/mshell'; +import CSys from '../../../math/csys'; -export function readShellEntityFromJson(data, consumed) { +export function readShellEntityFromJson(data, consumed, csys) { let refIndex = indexFacesByRef(consumed); @@ -15,7 +16,7 @@ export function readShellEntityFromJson(data, consumed) { } } } - return new MBrepShell(shell); + return new MBrepShell(shell, csys); } function indexFacesByRef(shells) { diff --git a/web/app/math/l3space.js b/web/app/math/l3space.js index 50aa930e..78e20e1e 100644 --- a/web/app/math/l3space.js +++ b/web/app/math/l3space.js @@ -262,12 +262,12 @@ Matrix3.rotateMatrix = function(angle, axis, pivot, matrix) { return m; }; -function BasisForPlane(normal) { +function BasisForPlane(normal, alignY = AXIS.Y, alignZ = AXIS.Z) { let alignPlane, x, y; - if (Math.abs(normal.dot(AXIS.Y)) < 0.5) { - alignPlane = normal.cross(AXIS.Y); + if (Math.abs(normal.dot(alignY)) < 0.5) { + alignPlane = normal.cross(alignY); } else { - alignPlane = normal.cross(AXIS.Z); + alignPlane = normal.cross(alignZ); } y = alignPlane.cross(normal); x = y.cross(normal);