mirror of https://gitee.com/cf-fz/WebCAD.git
!1756 增强:世界坐标XY正轴添加网格助手
parent
5950b448c5
commit
db18812dac
@ -0,0 +1,52 @@
|
||||
import { BufferGeometry, Color, Group, Line, LineBasicMaterial, Vector3 } from "three";
|
||||
|
||||
export default class GridHelper2 extends Group
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param size 网格大小
|
||||
* @param divisions 网格内一行/列有几个格子
|
||||
* @param color1 //外边框颜色
|
||||
* @param color2 //内线颜色
|
||||
*/
|
||||
constructor(size: number, divisions: number, color1: Color, color2: Color)
|
||||
{
|
||||
super();
|
||||
const material1 = new LineBasicMaterial({
|
||||
color: color1,
|
||||
});
|
||||
const material2 = new LineBasicMaterial({
|
||||
color: color2,
|
||||
});
|
||||
|
||||
const points = [];
|
||||
points.push(new Vector3(0, 0, 0));
|
||||
points.push(new Vector3(0, 0, size));
|
||||
points.push(new Vector3(size, 0, size));
|
||||
points.push(new Vector3(size, 0, 0));
|
||||
points.push(new Vector3(0, 0, 0));
|
||||
|
||||
const geometry = new BufferGeometry().setFromPoints(points);
|
||||
|
||||
const line = new Line(geometry, material1);
|
||||
line.updateMatrix();
|
||||
this.add(line);
|
||||
|
||||
const divisionsDistance = size / divisions;
|
||||
const row = [new Vector3(0, 0, 0), new Vector3(size, 0, 0)];
|
||||
const column = [new Vector3(0, 0, 0), new Vector3(0, 0, size)];
|
||||
|
||||
const centerNum = divisions / 2;
|
||||
for (let i = 1; i < divisions; i++)
|
||||
{
|
||||
const innerLineRow = new Line(new BufferGeometry().setFromPoints(row), i === centerNum ? material1 : material2);
|
||||
innerLineRow.position.set(line.position.x, line.position.y, line.position.z + divisionsDistance * i);
|
||||
innerLineRow.updateMatrix();
|
||||
this.add(innerLineRow);
|
||||
const innerLineColumn = new Line(new BufferGeometry().setFromPoints(column), i === centerNum ? material1 : material2);
|
||||
innerLineColumn.position.set(line.position.x + divisionsDistance * i, line.position.y, line.position.z);
|
||||
innerLineColumn.updateMatrix();
|
||||
this.add(innerLineColumn);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue