📅  最后修改于: 2023-12-03 15:41:49.932000             🧑  作者: Mango
本项目是一个基于资质的3D测量工具,用于在3D场景中测量任意物体的大小、角度和距离。
// 计算两个点的距离
function calculateDistance(point1, point2) {
const diffX = Math.abs(point1.x - point2.x);
const diffY = Math.abs(point1.y - point2.y);
const diffZ = Math.abs(point1.z - point2.z);
const distance = Math.sqrt(diffX ** 2 + diffY ** 2 + diffZ ** 2);
return distance;
}
// 在3D场景中选取物体并测量大小
function measureSize(object) {
const geometry = object.geometry;
const box = new THREE.Box3().setFromObject(object);
const size = {
x: box.max.x - box.min.x,
y: box.max.y - box.min.y,
z: box.max.z - box.min.z,
};
return size;
}
// 在3D场景中选取角度并测量
function measureAngle(angleVertex, point1, point2) {
const v1 = new THREE.Vector3(point1.x - angleVertex.x, point1.y - angleVertex.y, point1.z - angleVertex.z);
const v2 = new THREE.Vector3(point2.x - angleVertex.x, point2.y - angleVertex.y, point2.z - angleVertex.z);
const angle = v1.angleTo(v2);
return angle;
}
以上是测量工具中常用的几个函数的代码实现,可以结合具体需求进行拓展和调整。