修复自定义编号不显示,添加双面显示

This commit is contained in:
xief
2023-07-14 10:41:41 +08:00
parent 66dbe5869e
commit fba276362c
3 changed files with 74 additions and 49 deletions

View File

@@ -1,43 +1,59 @@
import { Font, FontLoader, Mesh, ShapeGeometry, Vector3, Shape } from "three";
import { Font, FontLoader, Matrix4, Mesh, Shape, ShapeGeometry, Vector3 } from "three";
import { ColorMaterial } from "./ColorPalette";
import { MoveMatrix } from "./GeUtils";
import { XAxis, XAxisN, YAxis, YAxisN, ZAxisN } from "./Utils";
class FontLoaderUtil
{
private static defFont: Font;
static Load(): Font
{
if (!this.defFont)
private static defFont: Font;
static Load(): Font
{
const f = require("../resources/fonts/helvetiker_regular.typeface.json");
let loader = new FontLoader();
this.defFont = loader.parse(f);
if (!this.defFont)
{
const f = require("../resources/fonts/helvetiker_regular.typeface.json");
let loader = new FontLoader();
this.defFont = loader.parse(f);
}
return this.defFont;
}
return this.defFont;
}
}
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();
/**
*
* 构造一个文本对象,8位点(中心点下面)在0点
* @param {string} str 数字字符串
* @param {number} height 文本高度
* @memberof DbText
*/
constructor(str: string, height: number = 5)
{
let font = FontLoaderUtil.Load();
let shapes: Shape[] = font.generateShapes(str, height);
let geometry = new ShapeGeometry(shapes);
let shapes: Shape[] = font.generateShapes(str, height);
let geometry = new ShapeGeometry(shapes);
geometry.computeBoundingBox();
geometry.computeBoundingBox();
super(geometry, ColorMaterial.GetBasicMaterial(5));
super(geometry, ColorMaterial.GetBasicMaterial(5));
let center = geometry.boundingBox.getCenter(new Vector3());
this.applyMatrix4(MoveMatrix(new Vector3(-center.x, 0, 0)));
}
let center = geometry.boundingBox.getCenter(new Vector3());
this.applyMatrix4(MoveMatrix(new Vector3(-center.x, 0, 0)));
}
CreateDoubleMesh(IsFsText: boolean)
{
let mesh2 = new Mesh(this.geometry, ColorMaterial.GetBasicMaterial(5));
//左右视图时应该这样,俯视图是X,-Y,-Z(y+=(xxx)
if (IsFsText)
{
mesh2.applyMatrix4(new Matrix4().makeBasis(XAxis, YAxisN, ZAxisN));
}
else
{
mesh2.applyMatrix4(new Matrix4().makeBasis(XAxisN, YAxis, ZAxisN));
}
this.add(mesh2);
}
}