|
|
@ -26,6 +26,8 @@ import { Line2 } from 'three/examples/jsm/lines/Line2' |
|
|
import MeasureRenderer from '@/modules/measure/MeasureRenderer.ts' |
|
|
import MeasureRenderer from '@/modules/measure/MeasureRenderer.ts' |
|
|
import { LineSegmentsGeometry } from 'three/examples/jsm/lines/LineSegmentsGeometry' |
|
|
import { LineSegmentsGeometry } from 'three/examples/jsm/lines/LineSegmentsGeometry' |
|
|
import { LineSegments2 } from 'three/examples/jsm/lines/LineSegments2' |
|
|
import { LineSegments2 } from 'three/examples/jsm/lines/LineSegments2' |
|
|
|
|
|
import { Text } from 'troika-three-text' |
|
|
|
|
|
import SimSunTTF from '@/assets/fonts/simsunb.ttf' |
|
|
|
|
|
|
|
|
const canvasContainer = ref(null) |
|
|
const canvasContainer = ref(null) |
|
|
let resizeObserver: ResizeObserver | null = null |
|
|
let resizeObserver: ResizeObserver | null = null |
|
|
@ -58,6 +60,9 @@ const lineMaterial = new LineMaterial({ |
|
|
linewidth: 5 |
|
|
linewidth: 5 |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* drawLine2 |
|
|
|
|
|
*/ |
|
|
function test1() { |
|
|
function test1() { |
|
|
cleanupThree() |
|
|
cleanupThree() |
|
|
const xcount = 100 |
|
|
const xcount = 100 |
|
|
@ -85,11 +90,6 @@ function test1() { |
|
|
const geometry = new LineGeometry() |
|
|
const geometry = new LineGeometry() |
|
|
geometry.setPositions([p1.x, p1.y, p1.z, p2.x, p2.y, p2.z]) |
|
|
geometry.setPositions([p1.x, p1.y, p1.z, p2.x, p2.y, p2.z]) |
|
|
|
|
|
|
|
|
// const material = new LineMaterial({ |
|
|
|
|
|
// color: 0xFF8C00, |
|
|
|
|
|
// linewidth: 5 |
|
|
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
|
|
const line = new Line2(geometry, lineMaterial) |
|
|
const line = new Line2(geometry, lineMaterial) |
|
|
line.computeLineDistances() |
|
|
line.computeLineDistances() |
|
|
|
|
|
|
|
|
@ -114,6 +114,9 @@ function test1() { |
|
|
refreshCount() |
|
|
refreshCount() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* LineSegments2 |
|
|
|
|
|
*/ |
|
|
function test2() { |
|
|
function test2() { |
|
|
cleanupThree() |
|
|
cleanupThree() |
|
|
const xcount = 100 |
|
|
const xcount = 100 |
|
|
@ -176,7 +179,9 @@ function test2() { |
|
|
refreshCount() |
|
|
refreshCount() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* BufferGeometry |
|
|
|
|
|
*/ |
|
|
function test3() { |
|
|
function test3() { |
|
|
cleanupThree() |
|
|
cleanupThree() |
|
|
const xcount = 100 |
|
|
const xcount = 100 |
|
|
@ -201,6 +206,7 @@ function test3() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const positions = [] |
|
|
const positions = [] |
|
|
|
|
|
const labels = [] |
|
|
|
|
|
|
|
|
// 横向连接(右) |
|
|
// 横向连接(右) |
|
|
for (let z = 0; z < zcount; z++) { |
|
|
for (let z = 0; z < zcount; z++) { |
|
|
@ -210,6 +216,12 @@ function test3() { |
|
|
const x2 = (x + 1) * spacing |
|
|
const x2 = (x + 1) * spacing |
|
|
const z2 = z * spacing |
|
|
const z2 = z * spacing |
|
|
positions.push(x1, y, z1, x2, y, z2) |
|
|
positions.push(x1, y, z1, x2, y, z2) |
|
|
|
|
|
|
|
|
|
|
|
// 计算中点和长度 |
|
|
|
|
|
const midPoint = new THREE.Vector3((x1 + x2) / 2, y + 0.5, (z1 + z2) / 2) |
|
|
|
|
|
const length = Math.hypot(x2 - x1, y - y, z2 - z1) |
|
|
|
|
|
const label = createTextLabel(length.toFixed(2) + 'm', midPoint) |
|
|
|
|
|
labels.push(label) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -221,6 +233,12 @@ function test3() { |
|
|
const x2 = x * spacing |
|
|
const x2 = x * spacing |
|
|
const z2 = (z + 1) * spacing |
|
|
const z2 = (z + 1) * spacing |
|
|
positions.push(x1, y, z1, x2, y, z2) |
|
|
positions.push(x1, y, z1, x2, y, z2) |
|
|
|
|
|
|
|
|
|
|
|
// 计算中点和长度 |
|
|
|
|
|
const midPoint = new THREE.Vector3((x1 + x2) / 2, y + 0.5, (z1 + z2) / 2) |
|
|
|
|
|
const length = Math.hypot(x2 - x1, y - y, z2 - z1) |
|
|
|
|
|
const label = createTextLabel(length.toFixed(2) + 'm', midPoint) |
|
|
|
|
|
labels.push(label) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -231,9 +249,35 @@ function test3() { |
|
|
const lineSegments = new THREE.LineSegments(geometry, material) |
|
|
const lineSegments = new THREE.LineSegments(geometry, material) |
|
|
lineSegments.name = 'grid-lines' |
|
|
lineSegments.name = 'grid-lines' |
|
|
scene.add(lineSegments) |
|
|
scene.add(lineSegments) |
|
|
|
|
|
|
|
|
|
|
|
labels.forEach(label => scene.add(label)) |
|
|
|
|
|
|
|
|
refreshCount() |
|
|
refreshCount() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function createTextLabel(text, position) { |
|
|
|
|
|
const label = new Text() |
|
|
|
|
|
label.text = text |
|
|
|
|
|
label.font = SimSunTTF |
|
|
|
|
|
label.fontSize = 0.2 |
|
|
|
|
|
label.color = '#333333' |
|
|
|
|
|
label.opacity = 0.8 |
|
|
|
|
|
label.padding = 0.2 |
|
|
|
|
|
label.anchorX = 'center' |
|
|
|
|
|
label.anchorY = 'middle' |
|
|
|
|
|
label.depthOffset = 1 |
|
|
|
|
|
label.backgroundColor = '#000000' |
|
|
|
|
|
label.backgroundOpacity = 0.6 |
|
|
|
|
|
label.material.depthTest = false |
|
|
|
|
|
label.position.copy(position) |
|
|
|
|
|
label.name = MeasureRenderer.LABEL_NAME |
|
|
|
|
|
|
|
|
|
|
|
label.position.set(position.x, position.y + 0.3, position.z - 0.2) |
|
|
|
|
|
label.quaternion.copy(camera.quaternion) |
|
|
|
|
|
label.sync() |
|
|
|
|
|
|
|
|
|
|
|
return label |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const restate = reactive({ |
|
|
const restate = reactive({ |
|
|
targetColor: '#ff0000', |
|
|
targetColor: '#ff0000', |
|
|
@ -349,9 +393,6 @@ function animate() { |
|
|
|
|
|
|
|
|
function handleResize(entries) { |
|
|
function handleResize(entries) { |
|
|
for (let entry of entries) { |
|
|
for (let entry of entries) { |
|
|
// entry.contentRect包含了元素的尺寸信息 |
|
|
|
|
|
console.log('Element size changed:', entry.contentRect) |
|
|
|
|
|
|
|
|
|
|
|
const width = entry.contentRect.width |
|
|
const width = entry.contentRect.width |
|
|
const height = entry.contentRect.height |
|
|
const height = entry.contentRect.height |
|
|
|
|
|
|
|
|
|