awv3
Version:
⚡ AWV3 embedded CAD
86 lines (75 loc) • 2.92 kB
JavaScript
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import * as THREE from 'three';
var Workplane =
/*#__PURE__*/
function (_THREE$Object3D) {
_inheritsLoose(Workplane, _THREE$Object3D);
function Workplane(plugin) {
var _this;
_this = _THREE$Object3D.call(this) || this;
_this.type = 'Workplane';
_this.plugin = plugin;
var session = plugin.session;
var geometry = new THREE.PlaneBufferGeometry(1, 1);
var material = new THREE.MeshBasicMaterial({
side: THREE.DoubleSide,
transparent: true,
color: new THREE.Color(0x808080),
opacity: 0.1
});
var plane = new THREE.Mesh(geometry, material);
plane.material.meta = {
id: plugin.feature,
material: {
color: plane.material.color.clone(),
opacity: plane.material.opacity
}
};
plane.userData.meta = {};
plane.renderOrder = 1000;
var lineMaterial = new THREE.LineBasicMaterial({
color: 0x373737,
transparent: true,
opacity: 0.3
});
var lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, 0));
lineGeometry.vertices.push(new THREE.Vector3(0.5, -0.5, 0));
lineGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, 0));
lineGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, 0));
lineGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, 0));
var outlines = new THREE.Line(lineGeometry, lineMaterial);
outlines.renderOrder = 1000;
_this.add(plane);
_this.add(outlines);
plugin.addSubscription(session.observe(function (state) {
return state.globals.day;
}, function (day) {
lineMaterial.color = new THREE.Color(day ? 0x373737 : 0x979797);
plugin.pool.view && plugin.pool.view.invalidate();
}, {
fireOnStart: true
})); //this.measurable = true;
return _this;
}
var _proto = Workplane.prototype;
_proto.updateFromState = function updateFromState(state) {
this.children[0].userData.meta.id = state.id;
this.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, 1), new THREE.Vector3().fromArray(state.members.Normal.value));
this.position.fromArray(state.members.curPosition.value);
var bounds = state.members.Size.value;
this.scale.setScalar(bounds);
var csys = state.coordinateSystem.map(function (row) {
return new THREE.Vector3().fromArray(row);
});
this.matrix.makeBasis(csys[1], csys[2], csys[3]).setPosition(csys[0]);
this.matrix.multiply(new THREE.Matrix4().compose(this.position, this.quaternion, this.scale));
this.matrix.decompose(this.position, this.quaternion, this.scale);
this.matrixWorldNeedsUpdate = true;
this.updateMatrixWorld();
this.plugin.pool.view && this.plugin.pool.view.invalidate();
this.plugin.connection.updateView();
};
return Workplane;
}(THREE.Object3D);
export { Workplane as default };