From 02eb8b0662d3eedf4773f7282c6eec4ca8939ad4 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Tue, 30 Oct 2018 22:56:59 -0700 Subject: [PATCH] make coordinate system widget use coordinate system instead of basis --- modules/scene/objects/transform.js | 19 +++++++++++++++++++ web/app/cad/scene/cadScene.js | 15 +++++++++------ .../cad/scene/controls/pickControlPlugin.js | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/scene/objects/transform.js b/modules/scene/objects/transform.js index 674cb82d..51967986 100644 --- a/modules/scene/objects/transform.js +++ b/modules/scene/objects/transform.js @@ -9,6 +9,25 @@ export function setBasisToObject3D(obj, basis, depth) { obj.applyMatrix(mx); } +export function setCadToViewMatrix(cadMatrix, threeMatrix) { + let cm = cadMatrix; + threeMatrix.set( + cm.mxx, cm.mxy, cm.mxz, cm.tx, + cm.myx, cm.myy, cm.myz, cm.ty, + cm.mzx, cm.mzy, cm.mzz, cm.tz, + 0, 0, 0, 1 + ); +} + +export function setCsysToViewMatrix(csys, threeMatrix) { + threeMatrix.set( + csys.x.x, csys.y.x, csys.z.x, csys.origin.x, + csys.x.y, csys.y.y, csys.z.y, csys.origin.y, + csys.x.z, csys.y.z, csys.z.z, csys.origin.z, + 0, 0, 0, 1 + ); +} + export function moveObject3D(obj, dir) { obj.position.add(dir) } diff --git a/web/app/cad/scene/cadScene.js b/web/app/cad/scene/cadScene.js index 46d92181..a2604f38 100644 --- a/web/app/cad/scene/cadScene.js +++ b/web/app/cad/scene/cadScene.js @@ -5,6 +5,7 @@ import {OnTopOfAll} from 'scene/materialMixins'; import {moveObject3D, setBasisToObject3D} from 'scene/objects/transform'; import * as SceneGraph from 'scene/sceneGraph'; +import {setCsysToViewMatrix} from '../../../../modules/scene/objects/transform'; export default class CadScene { @@ -44,25 +45,27 @@ export default class CadScene { } this.basisGroup = SceneGraph.createGroup(); + this.basisGroup.matrixAutoUpdate = false; let xAxis = createBasisArrow(new Vector(1, 0, 0), 0xFF0000); let yAxis = createBasisArrow(new Vector(0, 1, 0), 0x00FF00); SceneGraph.addToGroup(this.basisGroup, xAxis); SceneGraph.addToGroup(this.basisGroup, yAxis); SceneGraph.addToGroup(this.workGroup, this.basisGroup, yAxis); - this.hideBasis(); + this.hideGlobalCsys(); } - updateBasis(basis, depth) { - setBasisToObject3D(this.basisGroup, basis, depth); + updateGlobalCsys(csys) { + setCsysToViewMatrix(csys, this.basisGroup.matrix); + this.basisGroup.matrixWorldNeedsUpdate = true; } - showBasis(basis, depth) { - this.updateBasis(basis, depth); + showGlobalCsys(csys) { + this.updateGlobalCsys(csys); this.basisGroup.visible = true; } - hideBasis() { + hideGlobalCsys() { this.basisGroup.visible = false; } } \ No newline at end of file diff --git a/web/app/cad/scene/controls/pickControlPlugin.js b/web/app/cad/scene/controls/pickControlPlugin.js index a840c2ee..b88b919a 100644 --- a/web/app/cad/scene/controls/pickControlPlugin.js +++ b/web/app/cad/scene/controls/pickControlPlugin.js @@ -51,7 +51,7 @@ export function activate(context) { let modelId = view.model.id; if (kind === PICK_KIND.FACE) { if (dispatchSelection(streams.selection.face, modelId, event)) { - services.cadScene.showBasis(view.model.basis(), view.model.depth()); + services.cadScene.showGlobalCsys(view.model.csys); return false; } } else if (kind === PICK_KIND.SKETCH) {