UNPKG

awv3

Version:
49 lines (39 loc) 1.5 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import * as THREE from 'three'; import BaseGraphics from './base'; import { setMaterialMeta } from './index'; var geometry = new THREE.BoxBufferGeometry(1, 1, 0); var material = new THREE.MeshBasicMaterial({ color: 0x3378a2, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: -1, polygonOffsetUnits: -5 }); var Line = /*#__PURE__*/ function (_BaseGraphics) { _inheritsLoose(Line, _BaseGraphics); function Line() { var _this; _this = _BaseGraphics.call(this) || this; _this.localMesh = new THREE.Mesh(geometry, material.clone()); _this.localMesh.type = 'SketcherMesh'; _this.localMesh.material.meta = {}; _this.localMesh.material.meta.material = setMaterialMeta(material); _this.add(_this.localMesh); return _this; } var _proto = Line.prototype; _proto.updateFromGeomParams = function updateFromGeomParams(geomParams) { _BaseGraphics.prototype.updateFromGeomParams.call(this, geomParams); var dir = geomParams.end.clone().sub(geomParams.start).normalize(); var length = geomParams.start.distanceTo(geomParams.end); this.localMesh.position.lerpVectors(geomParams.start, geomParams.end, 0.5); this.localMesh.quaternion.setFromUnitVectors(new THREE.Vector3(1, 0, 0), dir); this.localMesh.scale.set(Math.max(length, 1e-3), geomParams.scale, 1e-3); this.updateMetaBox(); }; return Line; }(BaseGraphics); export { Line as default };