jsketcher/web/app/cad/craft/datum/csysObject.js
Val Erastov (xibyte) f24a3f45a5 imports grooming
2020-07-19 23:09:46 -07:00

61 lines
1.4 KiB
JavaScript

import {MeshLambertMaterial, Object3D} from 'three';
import {MeshArrow} from 'scene/objects/auxiliary';
import {viewScaleFactor} from 'scene/scaleHelper';
import {AXIS} from "math/vector";
export default class CSysObject3D extends Object3D {
constructor(csys, sceneSetup, arrowParams) {
super();
this.csys = csys;
this.sceneSetup = sceneSetup;
function createBasisArrow(axis, color) {
let meshArrow = new MeshArrow({
dir: axis,
color,
length: CSYS_SIZE_MODEL,
headLength: 30,
headWidth: 15,
lineWidth: 2,
materialCreate: p => new MeshLambertMaterial(p),
...arrowParams
});
return meshArrow;
}
this.xAxis = createBasisArrow(AXIS.X, 0xFF0000);
this.yAxis = createBasisArrow(AXIS.Y, 0x00FF00);
this.zAxis = createBasisArrow(AXIS.Z, 0x0000FF);
this.add(this.xAxis);
this.add(this.yAxis);
this.add(this.zAxis);
}
updateMatrix() {
let {origin: o, x, y, z} = this.csys;
let k = viewScaleFactor(this.sceneSetup, this.csys.origin, SIZE_PX, CSYS_SIZE_MODEL);
this.matrix.set(
k*x.x, k*y.x, k*z.x, o.x,
k*x.y, k*y.y, k*z.y, o.y,
k*x.z, k*y.z, k*z.z, o.z,
0, 0, 0, 1
);
// this.scale.set(k, k, k);
// super.updateMatrix();
}
dispose() {
this.xAxis.dispose();
this.yAxis.dispose();
this.zAxis.dispose();
}
}
export const CSYS_SIZE_MODEL = 100;
const SIZE_PX = 50;