修复引用node_modules资源问题

This commit is contained in:
xf
2018-05-28 17:59:38 +08:00
parent 0f41ff6562
commit 70e20e5a58
5 changed files with 31 additions and 37 deletions

View File

@@ -2,44 +2,37 @@ import { Font, FontLoader, Mesh, ShapeGeometry, Vector3 } from "three";
import { ColorMaterial } from "./ColorPalette";
import { MoveMatrix } from "./GeUtils";
class FontLoaderUtil
{
private static defFont:Font;
static Load():Font
{
if(!this.defFont)
{
const f = require("../node_modules/three/examples/fonts/helvetiker_regular.typeface.json");
let loader = new FontLoader();
this.defFont = loader.parse(f);
}
return this.defFont;
class FontLoaderUtil {
private static defFont: Font;
static Load(): Font {
if (!this.defFont) {
const f = require("../resources/fonts/helvetiker_regular.typeface.json");
let loader = new FontLoader();
this.defFont = loader.parse(f);
}
return this.defFont;
}
}
export class DbText extends Mesh
{
/**
*
* 构造一个文本对象,8位点(中心点下面)在0点
* @param {string} str 数字字符串
* @param {number} height 文本高度
* @memberof DbText
*/
constructor(str:string,height:number = 5)
{
export class DbText extends Mesh {
/**
*
* 构造一个文本对象,8位点(中心点下面)在0点
* @param {string} str 数字字符串
* @param {number} height 文本高度
* @memberof DbText
*/
constructor(str: string, height: number = 5) {
let font = FontLoaderUtil.Load();
let font = FontLoaderUtil.Load();
let shapes: THREE.Shape[] = font.generateShapes(str, height, 0.1);
let geometry = new ShapeGeometry(shapes);
let shapes: THREE.Shape[] = font.generateShapes(str, height,0.1);
let geometry = new ShapeGeometry(shapes);
geometry.computeBoundingBox();
geometry.computeBoundingBox();
super(geometry, ColorMaterial.GetLineMaterial(5));
super(geometry,ColorMaterial.GetLineMaterial(5));
let center = geometry.boundingBox.getCenter(new Vector3());
this.applyMatrix(MoveMatrix(new Vector3(-center.x,0,0)));
}
let center = geometry.boundingBox.getCenter(new Vector3());
this.applyMatrix(MoveMatrix(new Vector3(-center.x, 0, 0)));
}
}