2020-04-30 17:12:30 +08:00
|
|
|
import { Box3, Matrix4, Mesh, Vector3 } from "three";
|
2018-05-24 17:13:23 +08:00
|
|
|
import { Dimension, GetBoxArr } from ".";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 绘制标注实体
|
2020-04-30 17:12:30 +08:00
|
|
|
*
|
2018-05-24 17:13:23 +08:00
|
|
|
* @export
|
2020-04-30 17:12:30 +08:00
|
|
|
* @param {Box3} box
|
2018-05-24 17:13:23 +08:00
|
|
|
* @returns 标注实体列表
|
|
|
|
*/
|
|
|
|
export function DrawDimension(brList: Mesh[]): Dimension[]
|
|
|
|
{
|
|
|
|
let box = GetBoxArr(brList);
|
|
|
|
let size = box.getSize(new Vector3());
|
|
|
|
|
|
|
|
let mat4 = new Matrix4();
|
|
|
|
mat4.makeBasis(
|
|
|
|
new Vector3(-1, 0, 0),
|
|
|
|
new Vector3(0, -1, 0),
|
|
|
|
new Vector3(0, 0, 1)
|
|
|
|
)
|
|
|
|
mat4.setPosition(box.min.clone().add(new Vector3(size.x, -30)));
|
|
|
|
|
|
|
|
let textHeight = 45;
|
|
|
|
let dimx = new Dimension(size.x, textHeight, true);
|
2020-04-30 17:12:30 +08:00
|
|
|
dimx.applyMatrix4(mat4);
|
2018-05-24 17:13:23 +08:00
|
|
|
|
|
|
|
let dimz = new Dimension(size.z, textHeight);
|
|
|
|
mat4.makeBasis(
|
|
|
|
new Vector3(0, 0, -1),
|
|
|
|
new Vector3(1, 0, 0),
|
|
|
|
new Vector3(0, -1, 0)
|
|
|
|
)
|
|
|
|
mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
|
2020-04-30 17:12:30 +08:00
|
|
|
dimz.applyMatrix4(mat4);
|
2018-05-24 17:13:23 +08:00
|
|
|
|
|
|
|
let dimy = new Dimension(size.y, textHeight, true, true);
|
|
|
|
mat4.makeBasis(
|
|
|
|
new Vector3(0, 1, 0),
|
|
|
|
new Vector3(-1, 0, 0),
|
|
|
|
new Vector3(0, 0, 1)
|
|
|
|
)
|
|
|
|
mat4.setPosition(box.max.clone().add(new Vector3(30, -size.y)));
|
2020-04-30 17:12:30 +08:00
|
|
|
dimy.applyMatrix4(mat4);
|
2018-05-24 17:13:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
return [dimx, dimy, dimz];
|
|
|
|
}
|