修复自定义编号不显示,添加双面显示
This commit is contained in:
		@@ -1,7 +1,8 @@
 | 
			
		||||
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 { edgeMaterial } from "./Material";
 | 
			
		||||
import { DbText } from "./Text";
 | 
			
		||||
 | 
			
		||||
function getVec(data: object): Vector3
 | 
			
		||||
{
 | 
			
		||||
@@ -32,7 +33,6 @@ export class SimpleBoard
 | 
			
		||||
    DataID: number;
 | 
			
		||||
    _BoardType: BoardType;
 | 
			
		||||
    _CustomNumber: string;
 | 
			
		||||
    _CustomNumberTextEntity: any;
 | 
			
		||||
 | 
			
		||||
    constructor(boardData: any)
 | 
			
		||||
    {
 | 
			
		||||
@@ -157,32 +157,34 @@ export class SimpleBoard
 | 
			
		||||
        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 };
 | 
			
		||||
    }
 | 
			
		||||
    private createCustomNo()
 | 
			
		||||
    {
 | 
			
		||||
        if (!this._CustomNumberTextEntity)
 | 
			
		||||
        {
 | 
			
		||||
            this._CustomNumberTextEntity = new DbText();
 | 
			
		||||
            this._CustomNumberTextEntity.TextAligen = TextAligen.Mid;
 | 
			
		||||
            this._CustomNumberTextEntity.IsDoubleMesh = true;
 | 
			
		||||
            this._CustomNumberTextEntity.IsFsText = this._BoardType === BoardType.Layer;
 | 
			
		||||
 | 
			
		||||
            this._CustomNumberTextEntity.IsEmbedEntity = true;
 | 
			
		||||
        }
 | 
			
		||||
        let text = new DbText(this._CustomNumber?.toString(), 100);
 | 
			
		||||
        let position = new Vector3(this.width * 0.5, this.height * 0.5, this.thickness * 0.5);
 | 
			
		||||
        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
 | 
			
		||||
            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 { 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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								src/Utils.ts
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/Utils.ts
									
									
									
									
									
								
							@@ -1,5 +1,12 @@
 | 
			
		||||
import { Object3D, Mesh } from "three";
 | 
			
		||||
import { createTemplateBoard, DrawDimension, Viewer } from ".";
 | 
			
		||||
import { Object3D, Vector3 } from "three";
 | 
			
		||||
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)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user