three.cad/src/utils/static.js

59 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-03-29 18:27:34 +08:00
import * as THREE from '../../node_modules/three/src/Three';
2021-03-31 07:20:24 +08:00
const _vec2 = new THREE.Vector2()
const _vec3 = new THREE.Vector3()
const raycaster = new THREE.Raycaster();
raycaster.params.Line.threshold = 0.8;
2021-03-31 16:07:34 +08:00
raycaster.params.Points.threshold = 0.6;
2021-03-31 07:20:24 +08:00
const color = {
hover: 0x00ff00,
2021-03-31 16:07:34 +08:00
lighting: 0xFFFFFF,
emissive: 0x072534,
Plane: 0xf5bc42,
Line: 0x555555,
Points: 0x555555,
Extrude: 0x156289,
2021-03-31 07:20:24 +08:00
}
2021-03-29 18:27:34 +08:00
const lineMaterial = new THREE.LineBasicMaterial({
linewidth: 2,
2021-03-31 16:07:34 +08:00
color: color.Line,
2021-03-29 18:27:34 +08:00
})
const pointMaterial = new THREE.PointsMaterial({
2021-03-31 16:07:34 +08:00
color: color.Points,
2021-03-29 18:27:34 +08:00
size: 4,
})
2021-03-31 16:07:34 +08:00
const ptObj = (n) => {
const ret = new THREE.Points(
new THREE.BufferGeometry().setAttribute('position',
new THREE.Float32BufferAttribute(n || 3, 3)
),
pointMaterial.clone()
);
ret.name = 'Points'
return ret
}
2021-03-29 18:27:34 +08:00
2021-03-31 16:07:34 +08:00
const lineObj = (n = 1) => {
const ret = new THREE.Line(
new THREE.BufferGeometry().setAttribute('position',
new THREE.Float32BufferAttribute(3 * (n + 1), 3)
),
lineMaterial.clone()
);
ret.name = 'Line'
return ret
}
2021-03-29 18:27:34 +08:00
2021-03-31 07:20:24 +08:00
export { lineMaterial, pointMaterial, _vec2, _vec3, raycaster, color, ptObj, lineObj }