Browse Source

性能测试渲染

master
修宁 6 months ago
parent
commit
407e3aedbc
  1. 59
      src/components/ThreePerfView.vue

59
src/components/ThreePerfView.vue

@ -26,6 +26,8 @@ import { Line2 } from 'three/examples/jsm/lines/Line2'
import MeasureRenderer from '@/modules/measure/MeasureRenderer.ts'
import { LineSegmentsGeometry } from 'three/examples/jsm/lines/LineSegmentsGeometry'
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)
let resizeObserver: ResizeObserver | null = null
@ -58,6 +60,9 @@ const lineMaterial = new LineMaterial({
linewidth: 5
})
/**
* drawLine2
*/
function test1() {
cleanupThree()
const xcount = 100
@ -85,11 +90,6 @@ function test1() {
const geometry = new LineGeometry()
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)
line.computeLineDistances()
@ -114,6 +114,9 @@ function test1() {
refreshCount()
}
/**
* LineSegments2
*/
function test2() {
cleanupThree()
const xcount = 100
@ -176,7 +179,9 @@ function test2() {
refreshCount()
}
/**
* BufferGeometry
*/
function test3() {
cleanupThree()
const xcount = 100
@ -201,6 +206,7 @@ function test3() {
}
const positions = []
const labels = []
//
for (let z = 0; z < zcount; z++) {
@ -210,6 +216,12 @@ function test3() {
const x2 = (x + 1) * spacing
const z2 = z * spacing
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 z2 = (z + 1) * spacing
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)
lineSegments.name = 'grid-lines'
scene.add(lineSegments)
labels.forEach(label => scene.add(label))
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({
targetColor: '#ff0000',
@ -349,9 +393,6 @@ function animate() {
function handleResize(entries) {
for (let entry of entries) {
// entry.contentRect
console.log('Element size changed:', entry.contentRect)
const width = entry.contentRect.width
const height = entry.contentRect.height

Loading…
Cancel
Save