ThreeJs鼠标经过添加边框

ThreeJs鼠标经过添加边框

import {
  EdgesGeometry,
  Intersection,
  LineBasicMaterial,
  LineSegments,
  Object3D
} from 'three'

// 画布移动选中模型
const moveObject = ref()

// 定义了一个名为highlightMaterial的变量,它是一个LineBasicMaterial对象,用于给选中的模型添加红色边框。颜色为红色(0x1890ff),线宽为5。
const highlightMaterial = new LineBasicMaterial({ color: 0xffffff, linewidth: 5 })

/**
 * @description: 鼠标移动事件
 * @return {*}
 */
const handleMousemove = (_event: MouseEvent, intersect: Intersection): void => {
  const remove = () => {
    moveObject.value?.traverse((child: Object3D) => {
      if (!moveObject.value) return
      if (child instanceof LineSegments) {
        // 处理材质。材质的纹理不会被处理。需要通过Texture处理
        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()
  }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

细心细心细心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值