diff --git a/src/DatabaseServices/Text/FontExt.ts b/src/DatabaseServices/Text/FontExt.ts index a22d91f78..349ea15e1 100644 --- a/src/DatabaseServices/Text/FontExt.ts +++ b/src/DatabaseServices/Text/FontExt.ts @@ -4,9 +4,8 @@ import { Font, ShapePath } from "three"; export class FontExt extends Font { - generateShapes(text: string, size: number) + generateShapes(text: string, size: number = 100) { - if (size === undefined) size = 100; let shapes = []; let paths = createPaths(text, size, this.data); for (let p = 0, pl = paths.length; p < pl; p++) diff --git a/src/DatabaseServices/Text/Text.ts b/src/DatabaseServices/Text/Text.ts index 5b7f090f0..fedfe66e1 100644 --- a/src/DatabaseServices/Text/Text.ts +++ b/src/DatabaseServices/Text/Text.ts @@ -1,7 +1,7 @@ import { MathUtils, Object3D, Vector3, Matrix4, Mesh, ShapeGeometry, Box3 } from 'three'; import { ColorMaterial } from '../../Common/ColorPalette'; import { setRotationOnAxis } from '../../Common/Matrix4Utils'; -import { MoveMatrix } from '../../Geometry/GeUtils'; +import { GetBox, MoveMatrix } from '../../Geometry/GeUtils'; import { RenderType } from '../../GraphicsSystem/RenderType'; import { Factory } from '../CADFactory'; import { CADFiler } from '../CADFiler'; @@ -130,6 +130,7 @@ export class Text extends Entity let alllen = (this.TextString.length + (this.TextString.match('/[\u4e00-\u9fa5]/g')?.length ?? 0)) / 2; return alllen * this._Height; } + get BoundingBox() { if (!this.box) @@ -151,7 +152,6 @@ export class Text extends Entity let mesh = obj.children[0] as Mesh; let box = mesh.geometry.boundingBox; - this.box = box.clone().applyMatrix4(this.OCS); let p = new Vector3(); if (this._Align & TextAligen.LeftMid) @@ -173,9 +173,19 @@ export class Text extends Entity ); obj.updateMatrixWorld(true); + + this.box = GetBox(obj); } } } + + ApplyMatrix(m: Matrix4): this + { + super.ApplyMatrix(m); + this.box?.applyMatrix4(m); + return this; + } + protected ApplyScaleMatrix(m: Matrix4): this { this.WriteAllObjectRecord(); @@ -184,6 +194,8 @@ export class Text extends Entity [p1, p2].forEach(p => p.applyMatrix4(m)); this.Position = p1; this.Height = p1.distanceTo(p2); + + this.box?.applyMatrix4(m); return this; }