修复自定义编号不显示,添加双面显示
This commit is contained in:
parent
66dbe5869e
commit
fba276362c
@ -1,7 +1,8 @@
|
|||||||
import { CylinderGeometry, LineSegments, Matrix4, Mesh, MeshBasicMaterial, Vector2, Vector3 } from "three";
|
import { CylinderGeometry, LineSegments, Matrix4, Mesh, MeshBasicMaterial, Vector2, Vector3 } from "three";
|
||||||
import { DbText, ExtrudeSolid, Polyline, RenderType, TextAligen, boardUVGenerator2 } from "webcad_ue4_api";
|
import { ExtrudeSolid, Polyline, boardUVGenerator2 } from "webcad_ue4_api";
|
||||||
import { ColorMaterial } from "./ColorPalette";
|
import { ColorMaterial } from "./ColorPalette";
|
||||||
import { edgeMaterial } from "./Material";
|
import { edgeMaterial } from "./Material";
|
||||||
|
import { DbText } from "./Text";
|
||||||
|
|
||||||
function getVec(data: object): Vector3
|
function getVec(data: object): Vector3
|
||||||
{
|
{
|
||||||
@ -32,7 +33,6 @@ export class SimpleBoard
|
|||||||
DataID: number;
|
DataID: number;
|
||||||
_BoardType: BoardType;
|
_BoardType: BoardType;
|
||||||
_CustomNumber: string;
|
_CustomNumber: string;
|
||||||
_CustomNumberTextEntity: any;
|
|
||||||
|
|
||||||
constructor(boardData: any)
|
constructor(boardData: any)
|
||||||
{
|
{
|
||||||
@ -157,32 +157,34 @@ export class SimpleBoard
|
|||||||
mesh.updateWorldMatrix(false, true);
|
mesh.updateWorldMatrix(false, true);
|
||||||
|
|
||||||
// 自定义编号
|
// 自定义编号
|
||||||
this.createCustomNo();
|
|
||||||
let o = this._CustomNumberTextEntity.GetDrawObjectFromRenderType(RenderType.Conceptual);
|
|
||||||
if (o)
|
|
||||||
{
|
|
||||||
mesh.add(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// let o = this._CustomNumberTextEntity.GetDrawObjectFromRenderType(RenderType.Conceptual);
|
||||||
|
// if (o)
|
||||||
|
// {
|
||||||
|
// mesh.add(o);
|
||||||
|
// }
|
||||||
|
if (this._CustomNumber)
|
||||||
|
{
|
||||||
|
mesh.add(this.createCustomNo());
|
||||||
|
}
|
||||||
|
|
||||||
return { mesh, edges };
|
return { mesh, edges };
|
||||||
}
|
}
|
||||||
private createCustomNo()
|
private createCustomNo()
|
||||||
{
|
{
|
||||||
if (!this._CustomNumberTextEntity)
|
let text = new DbText(this._CustomNumber?.toString(), 100);
|
||||||
{
|
let position = new Vector3(this.width * 0.5, this.height * 0.5, this.thickness * 0.5);
|
||||||
this._CustomNumberTextEntity = new DbText();
|
|
||||||
this._CustomNumberTextEntity.TextAligen = TextAligen.Mid;
|
|
||||||
this._CustomNumberTextEntity.IsDoubleMesh = true;
|
|
||||||
this._CustomNumberTextEntity.IsFsText = this._BoardType === BoardType.Layer;
|
|
||||||
|
|
||||||
this._CustomNumberTextEntity.IsEmbedEntity = true;
|
|
||||||
}
|
|
||||||
if (this._BoardType === BoardType.Layer)
|
if (this._BoardType === BoardType.Layer)
|
||||||
this._CustomNumberTextEntity.OCSNoClone.makeRotationZ(-Math.PI / 2).setPosition(this.width * 0.5, this.height * 0.5, this.thickness * 0.5);
|
{
|
||||||
|
text.applyMatrix4(new Matrix4().makeRotationZ(-Math.PI / 2).setPosition(position));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
this._CustomNumberTextEntity.OCSNoClone.identity().setPosition(this.width * 0.5, this.height * 0.5, this.thickness * 0.5);
|
{
|
||||||
|
text.applyMatrix4(new Matrix4().setPosition(position));
|
||||||
|
}
|
||||||
|
|
||||||
this._CustomNumberTextEntity.TextString = this._CustomNumber?.toString() ?? "未编号";
|
text.CreateDoubleMesh(this._BoardType === BoardType.Layer);
|
||||||
|
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
70
src/Text.ts
70
src/Text.ts
@ -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 { ColorMaterial } from "./ColorPalette";
|
||||||
import { MoveMatrix } from "./GeUtils";
|
import { MoveMatrix } from "./GeUtils";
|
||||||
|
import { XAxis, XAxisN, YAxis, YAxisN, ZAxisN } from "./Utils";
|
||||||
|
|
||||||
class FontLoaderUtil
|
class FontLoaderUtil
|
||||||
{
|
{
|
||||||
private static defFont: Font;
|
private static defFont: Font;
|
||||||
static Load(): Font
|
static Load(): Font
|
||||||
{
|
|
||||||
if (!this.defFont)
|
|
||||||
{
|
{
|
||||||
const f = require("../resources/fonts/helvetiker_regular.typeface.json");
|
if (!this.defFont)
|
||||||
let loader = new FontLoader();
|
{
|
||||||
this.defFont = loader.parse(f);
|
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
|
export class DbText extends Mesh
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 构造一个文本对象,8位点(中心点下面)在0点
|
* 构造一个文本对象,8位点(中心点下面)在0点
|
||||||
* @param {string} str 数字字符串
|
* @param {string} str 数字字符串
|
||||||
* @param {number} height 文本高度
|
* @param {number} height 文本高度
|
||||||
* @memberof DbText
|
* @memberof DbText
|
||||||
*/
|
*/
|
||||||
constructor(str: string, height: number = 5)
|
constructor(str: string, height: number = 5)
|
||||||
{
|
{
|
||||||
let font = FontLoaderUtil.Load();
|
let font = FontLoaderUtil.Load();
|
||||||
|
|
||||||
let shapes: Shape[] = font.generateShapes(str, height);
|
let shapes: Shape[] = font.generateShapes(str, height);
|
||||||
let geometry = new ShapeGeometry(shapes);
|
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());
|
let center = geometry.boundingBox.getCenter(new Vector3());
|
||||||
this.applyMatrix4(MoveMatrix(new Vector3(-center.x, 0, 0)));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
11
src/Utils.ts
11
src/Utils.ts
@ -1,5 +1,12 @@
|
|||||||
import { Object3D, Mesh } from "three";
|
import { Object3D, Vector3 } from "three";
|
||||||
import { createTemplateBoard, DrawDimension, Viewer } from ".";
|
import { DrawDimension, Viewer, createTemplateBoard } from ".";
|
||||||
|
|
||||||
|
export const XAxis = new Vector3(1, 0, 0);
|
||||||
|
export const XAxisN = new Vector3(-1, 0, 0);
|
||||||
|
export const YAxis = new Vector3(0, 1, 0);
|
||||||
|
export const YAxisN = new Vector3(0, -1, 0);
|
||||||
|
export const ZAxis = new Vector3(0, 0, 1);
|
||||||
|
export const ZAxisN = new Vector3(0, 0, -1);
|
||||||
|
|
||||||
function dispose(m: Object3D)
|
function dispose(m: Object3D)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user