|
|
@ -120,7 +120,7 @@ const onDialogOpened = () => {
|
|
|
|
// 加载完成,设置加载状态为 false
|
|
|
|
// 加载完成,设置加载状态为 false
|
|
|
|
loading.value = false;
|
|
|
|
loading.value = false;
|
|
|
|
// 调整点云的位置到原点
|
|
|
|
// 调整点云的位置到原点
|
|
|
|
pointCloud.position.set(0, 300, 0);
|
|
|
|
pointCloud.position.set(0, 100, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取点云的几何体
|
|
|
|
// 获取点云的几何体
|
|
|
|
const geometry = pointCloud.geometry;
|
|
|
|
const geometry = pointCloud.geometry;
|
|
|
@ -131,39 +131,43 @@ const onDialogOpened = () => {
|
|
|
|
const numPoints = positions.length / 3;
|
|
|
|
const numPoints = positions.length / 3;
|
|
|
|
|
|
|
|
|
|
|
|
// 定义起始颜色和结束颜色
|
|
|
|
// 定义起始颜色和结束颜色
|
|
|
|
const startColor = new THREE.Color(0x00ff00); // 绿色
|
|
|
|
const startColor = new THREE.Color(0x0000ff); // 蓝色
|
|
|
|
const midColor = new THREE.Color(0xffff00); // 黄色
|
|
|
|
const midColor1 = new THREE.Color(0x00ff00); // 绿色
|
|
|
|
|
|
|
|
const midColor2 = new THREE.Color(0xffff00); // 黄色
|
|
|
|
const endColor = new THREE.Color(0xff0000); // 红色
|
|
|
|
const endColor = new THREE.Color(0xff0000); // 红色
|
|
|
|
|
|
|
|
|
|
|
|
// 计算点云在 z 轴上的最小值和最大值
|
|
|
|
// 计算点云在 z 轴上的最小值和最大值
|
|
|
|
let minZ = Infinity;
|
|
|
|
let minZ = Infinity;
|
|
|
|
let maxZ = -Infinity;
|
|
|
|
let maxZ = -Infinity;
|
|
|
|
for (let i = 0; i < numPoints; i++) {
|
|
|
|
for (let i = 0; i < numPoints; i++) {
|
|
|
|
const z = positions[i * 3 + 2];
|
|
|
|
const z = positions[i * 3 + 2];
|
|
|
|
if (z < minZ) minZ = z;
|
|
|
|
if (z < minZ) minZ = z;
|
|
|
|
if (z > maxZ) maxZ = z;
|
|
|
|
if (z > maxZ) maxZ = z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < numPoints; i++) {
|
|
|
|
for (let i = 0; i < numPoints; i++) {
|
|
|
|
const z = positions[i * 3 + 2];
|
|
|
|
const z = positions[i * 3 + 2];
|
|
|
|
// 计算颜色渐变因子
|
|
|
|
// 计算颜色渐变因子
|
|
|
|
const factor = (z - minZ) / (maxZ - minZ);
|
|
|
|
const factor = (z - minZ) / (maxZ - minZ);
|
|
|
|
|
|
|
|
|
|
|
|
let color;
|
|
|
|
let color;
|
|
|
|
if (factor < 0.5) {
|
|
|
|
if (factor < 0.33) {
|
|
|
|
// 从绿到黄的渐变
|
|
|
|
// 从蓝到绿的渐变
|
|
|
|
const subFactor = factor * 2;
|
|
|
|
const subFactor = factor / 0.33;
|
|
|
|
color = startColor.clone().lerp(midColor, subFactor);
|
|
|
|
color = startColor.clone().lerp(midColor1, subFactor);
|
|
|
|
} else {
|
|
|
|
} else if (factor < 0.66) {
|
|
|
|
// 从黄到红的渐变
|
|
|
|
// 从绿到黄的渐变
|
|
|
|
const subFactor = (factor - 0.5) * 2;
|
|
|
|
const subFactor = (factor - 0.33) / 0.33;
|
|
|
|
color = midColor.clone().lerp(endColor, subFactor);
|
|
|
|
color = midColor1.clone().lerp(midColor2, subFactor);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 从黄到红的渐变
|
|
|
|
// 将颜色添加到颜色数组中
|
|
|
|
const subFactor = (factor - 0.66) / 0.34;
|
|
|
|
colors.push(color.r, color.g, color.b);
|
|
|
|
color = midColor2.clone().lerp(endColor, subFactor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 将颜色添加到颜色数组中
|
|
|
|
|
|
|
|
colors.push(color.r, color.g, color.b);
|
|
|
|
|
|
|
|
}
|
|
|
|
// 创建颜色属性
|
|
|
|
// 创建颜色属性
|
|
|
|
const colorAttribute = new THREE.Float32BufferAttribute(colors, 3);
|
|
|
|
const colorAttribute = new THREE.Float32BufferAttribute(colors, 3);
|
|
|
|
geometry.setAttribute('color', colorAttribute);
|
|
|
|
geometry.setAttribute('color', colorAttribute);
|
|
|
|