ThreeJs鼠标经过添加边框
import {
EdgesGeometry,
Intersection,
LineBasicMaterial,
LineSegments,
Object3D
} from 'three'
const moveObject = ref()
const highlightMaterial = new LineBasicMaterial({ color: 0xffffff, linewidth: 5 })
const handleMousemove = (_event: MouseEvent, intersect: Intersection): void => {
const remove = () => {
moveObject.value?.traverse((child: Object3D) => {
if (!moveObject.value) return
if (child instanceof LineSegments) {
child.material.dispose()
child.geometry.dispose()
moveObject.value?.remove(child)
}
})
}
if (intersect) {
remove()
moveObject.value = intersect.object
const edges = new EdgesGeometry((intersect.object as Mesh).geometry)
const line = new LineSegments(edges, highlightMaterial)
intersect.object.add(line)
} else {
remove()
}
}