CADViewComponent/dist/Text.js

35 lines
1.2 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const three_1 = require("three");
const ColorPalette_1 = require("./ColorPalette");
const GeUtils_1 = require("./GeUtils");
class FontLoaderUtil {
static Load() {
if (!this.defFont) {
const f = require("../resources/fonts/helvetiker_regular.typeface.json");
let loader = new three_1.FontLoader();
this.defFont = loader.parse(f);
}
return this.defFont;
}
}
class DbText extends three_1.Mesh {
/**
*
* 构造一个文本对象,8位点(中心点下面)在0点
* @param {string} str 数字字符串
* @param {number} height 文本高度
* @memberof DbText
*/
constructor(str, height = 5) {
let font = FontLoaderUtil.Load();
let shapes = font.generateShapes(str, height, 0.1);
let geometry = new three_1.ShapeGeometry(shapes);
geometry.computeBoundingBox();
super(geometry, ColorPalette_1.ColorMaterial.GetLineMaterial(5));
let center = geometry.boundingBox.getCenter(new three_1.Vector3());
this.applyMatrix(GeUtils_1.MoveMatrix(new three_1.Vector3(-center.x, 0, 0)));
}
}
exports.DbText = DbText;
//# sourceMappingURL=Text.js.map