store coordinate system for a shell and use to derive coordinate system of its faces

This commit is contained in:
Val Erastov 2018-10-30 22:54:46 -07:00
parent 8c4b725c14
commit 12341bf26c
5 changed files with 16 additions and 9 deletions

View file

@ -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();

View file

@ -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));
}

View file

@ -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;

View file

@ -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) {

View file

@ -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);