mirror of https://gitee.com/cf-fz/WebCAD.git
!1718 增强:灯源可开关,底部工具栏增加一键开关
parent
e3006337a8
commit
3ac03e0d0a
@ -0,0 +1,96 @@
|
|||||||
|
|
||||||
|
import { BufferGeometry, Color, CylinderBufferGeometry, Float32BufferAttribute, LineBasicMaterial, LineSegments, MathUtils, Matrix4, Mesh, MeshBasicMaterial, Object3D, PointLight, SphereBufferGeometry, Vector3 } from 'three';
|
||||||
|
|
||||||
|
export class PointLightHelper extends Object3D
|
||||||
|
{
|
||||||
|
light: PointLight;
|
||||||
|
color: Color | string | number;
|
||||||
|
material: LineBasicMaterial;
|
||||||
|
cone: LineSegments[];
|
||||||
|
mesh: Mesh[];
|
||||||
|
constructor(distance: number, color?: Color | string | number)
|
||||||
|
{
|
||||||
|
|
||||||
|
const geometry = new BufferGeometry();
|
||||||
|
const positions = [];
|
||||||
|
for (let i = 0, j = 1, l = 32; i < l; i++, j++)
|
||||||
|
{
|
||||||
|
|
||||||
|
const p1 = (i / l) * Math.PI * 2;
|
||||||
|
const p2 = (j / l) * Math.PI * 2;
|
||||||
|
|
||||||
|
positions.push(
|
||||||
|
Math.cos(p1) * distance, Math.sin(p1) * distance, 0,
|
||||||
|
Math.cos(p2) * distance, Math.sin(p2) * distance, 0
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
geometry.setAttribute('position', new Float32BufferAttribute(positions, 3));
|
||||||
|
|
||||||
|
super();
|
||||||
|
this.color = color;
|
||||||
|
this.matrixAutoUpdate = false;
|
||||||
|
this.material = new LineBasicMaterial({ fog: false });;
|
||||||
|
|
||||||
|
this.cone = [];
|
||||||
|
this.mesh = [];
|
||||||
|
|
||||||
|
this.cone[0] = new LineSegments(geometry, this.material[0]);
|
||||||
|
this.cone[1] = this.cone[0].clone();
|
||||||
|
|
||||||
|
let moveMatInv = new Matrix4().getInverse(this.matrix);
|
||||||
|
let roMat = new Matrix4().makeRotationAxis(new Vector3(0, 1, 0), MathUtils.degToRad(60));
|
||||||
|
let mtx = this.matrix.clone().multiply(roMat).multiply(moveMatInv);
|
||||||
|
|
||||||
|
this.cone[1].applyMatrix4(mtx);
|
||||||
|
this.cone[2] = this.cone[1].clone();
|
||||||
|
this.cone[2].applyMatrix4(mtx);
|
||||||
|
|
||||||
|
let cylinderRoMat = new Matrix4().makeRotationAxis(new Vector3(1, 0, 0), MathUtils.degToRad(90));
|
||||||
|
let cylinderMtx = this.matrix.clone().multiply(cylinderRoMat).multiply(moveMatInv);
|
||||||
|
|
||||||
|
let cylinderGeometry = new CylinderBufferGeometry(40, 40, 80, 32); //灯泡圆柱
|
||||||
|
this.mesh[0] = new Mesh(cylinderGeometry, new MeshBasicMaterial({ color: 0xFFEAAD }));
|
||||||
|
this.mesh[0].applyMatrix4(cylinderMtx);
|
||||||
|
this.mesh[0].position.add(new Vector3(0, 0, 50));
|
||||||
|
this.mesh[0].updateMatrix();
|
||||||
|
|
||||||
|
let sphereBufferGeometry = new SphereBufferGeometry(75, 32, 32); //灯泡球体
|
||||||
|
this.mesh[1] = new Mesh(sphereBufferGeometry, this.material);
|
||||||
|
this.mesh[1].position.sub(new Vector3(0, 0, 30));
|
||||||
|
this.mesh[1].updateMatrix();
|
||||||
|
|
||||||
|
this.add(this.cone[0], this.cone[1], this.cone[2], this.mesh[0], this.mesh[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
dispose()
|
||||||
|
{
|
||||||
|
this.material.dispose();
|
||||||
|
|
||||||
|
this.cone[0].geometry.dispose();
|
||||||
|
//@ts-ignore
|
||||||
|
this.cone[0].material.dispose();
|
||||||
|
|
||||||
|
this.cone[1].geometry.dispose();
|
||||||
|
//@ts-ignore
|
||||||
|
this.cone[1].material.dispose();
|
||||||
|
|
||||||
|
this.cone[2].geometry.dispose();
|
||||||
|
//@ts-ignore
|
||||||
|
this.cone[2].material.dispose();
|
||||||
|
|
||||||
|
this.mesh[0].geometry.dispose();
|
||||||
|
//@ts-ignore
|
||||||
|
this.mesh[0].material.dispose();
|
||||||
|
|
||||||
|
this.mesh[1].geometry.dispose();
|
||||||
|
//@ts-ignore
|
||||||
|
this.mesh[1].material.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
update()
|
||||||
|
{
|
||||||
|
//@ts-ignore
|
||||||
|
this.mesh[1].material.color.set(this.color).multiplyScalar(0.9);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue