|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import * as THREE from 'three';
|
|
|
|
|
import { Math, Object3D, Vector3, Matrix4 } from 'three';
|
|
|
|
|
import { Math, Object3D, Vector3, Matrix4, Mesh, Shape, ShapeGeometry } from 'three';
|
|
|
|
|
import { ColorMaterial } from '../../Common/ColorPalette';
|
|
|
|
|
import { setRotationOnAxis } from '../../Common/Matrix4Utils';
|
|
|
|
|
import { MoveMatrix } from '../../Geometry/GeUtils';
|
|
|
|
@ -17,11 +16,7 @@ export enum TextAligen
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 字体实体
|
|
|
|
|
*
|
|
|
|
|
* @export
|
|
|
|
|
* @class Text
|
|
|
|
|
* @extends {Entity}
|
|
|
|
|
* 单行文字实体
|
|
|
|
|
*/
|
|
|
|
|
@Factory
|
|
|
|
|
export class Text extends Entity
|
|
|
|
@ -80,35 +75,31 @@ export class Text extends Entity
|
|
|
|
|
this.Update();
|
|
|
|
|
}
|
|
|
|
|
//创建字体对象
|
|
|
|
|
async AsyncUpdateDrawObject(obj: THREE.Object3D)
|
|
|
|
|
async AsyncUpdateDrawObject(obj: Object3D)
|
|
|
|
|
{
|
|
|
|
|
let mesh = obj.children[0] as THREE.Mesh;
|
|
|
|
|
let mesh = obj.children[0] as Mesh;
|
|
|
|
|
if (mesh)
|
|
|
|
|
{
|
|
|
|
|
if (mesh.geometry)
|
|
|
|
|
mesh.geometry.dispose();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
mesh = new THREE.Mesh();
|
|
|
|
|
mesh = new Mesh();
|
|
|
|
|
|
|
|
|
|
let f = FontLoader.GetLoader(this.m_FontName);
|
|
|
|
|
await f.LoadGlyphs(this.TextString);
|
|
|
|
|
await f.AwaitLoaded();
|
|
|
|
|
let shapes: THREE.Shape[] = f.Font.generateShapes(this.m_TextString, this.Height);
|
|
|
|
|
let geometry = new THREE.ShapeGeometry(shapes);
|
|
|
|
|
let shapes: Shape[] = f.Font.generateShapes(this.m_TextString, this.Height);
|
|
|
|
|
let geometry = new ShapeGeometry(shapes);
|
|
|
|
|
geometry.computeBoundingBox();
|
|
|
|
|
|
|
|
|
|
mesh.geometry = geometry;
|
|
|
|
|
|
|
|
|
|
mesh.material = ColorMaterial.GetBasicMaterial(this.ColorIndex);
|
|
|
|
|
|
|
|
|
|
mesh.matrixAutoUpdate = false;
|
|
|
|
|
|
|
|
|
|
if (obj.children.length === 0)
|
|
|
|
|
obj.add(mesh);
|
|
|
|
|
|
|
|
|
|
this.UpdateTranslate();
|
|
|
|
|
|
|
|
|
|
this.AsyncUpdated();
|
|
|
|
|
}
|
|
|
|
|
//TODO: FIXME 应该避免一直重载这个迭代.
|
|
|
|
@ -118,7 +109,7 @@ export class Text extends Entity
|
|
|
|
|
{
|
|
|
|
|
if (obj.children.length === 1)
|
|
|
|
|
{
|
|
|
|
|
let mesh = obj.children[0] as THREE.Mesh;
|
|
|
|
|
let mesh = obj.children[0] as Mesh;
|
|
|
|
|
|
|
|
|
|
let box = mesh.geometry.boundingBox;
|
|
|
|
|
|
|
|
|
@ -140,12 +131,14 @@ export class Text extends Entity
|
|
|
|
|
mesh.matrix = new Matrix4().makeRotationZ(this.TextRotation).multiply(
|
|
|
|
|
new Matrix4().setPosition(p.negate())
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
obj.updateMatrixWorld(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
InitDrawObject(renderType: RenderType = RenderType.Wireframe): Object3D
|
|
|
|
|
{
|
|
|
|
|
let g = new THREE.Object3D();
|
|
|
|
|
let g = new Object3D();
|
|
|
|
|
this.AsyncUpdateDrawObject(g);
|
|
|
|
|
return g;
|
|
|
|
|
}
|
|
|
|
@ -156,7 +149,7 @@ export class Text extends Entity
|
|
|
|
|
UpdateDrawObjectMaterial(type: RenderType, en: Object3D)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
GetGripPoints(): Array<THREE.Vector3>
|
|
|
|
|
GetGripPoints(): Array<Vector3>
|
|
|
|
|
{
|
|
|
|
|
return [this.Position];
|
|
|
|
|
}
|
|
|
|
@ -166,11 +159,11 @@ export class Text extends Entity
|
|
|
|
|
this.Position = this.Position.add(vec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GetStretchPoints(): Array<THREE.Vector3>
|
|
|
|
|
GetStretchPoints(): Array<Vector3>
|
|
|
|
|
{
|
|
|
|
|
return [this.Position];
|
|
|
|
|
}
|
|
|
|
|
MoveStretchPoints(indexList: Array<number>, vec: THREE.Vector3)
|
|
|
|
|
MoveStretchPoints(indexList: Array<number>, vec: Vector3)
|
|
|
|
|
{
|
|
|
|
|
this.ApplyMatrix(MoveMatrix(vec));
|
|
|
|
|
}
|
|
|
|
|