WebGL BabylonJS GUI 如何创建连接模型的按钮

如图所示:

方法:

javascript 复制代码
 createGUI(mesh: BABYLON.Mesh, title: string, index: number) {
    const advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI('UI')

    const rect = new Rectangle()
    rect.width = '100px'
    rect.height = '40px'
    rect.thickness = 0
    advancedTexture.addControl(rect)
    rect.linkWithMesh(mesh)
    rect.linkOffsetY = -120

    const backgroundImage = createImage('backgroundImage', 'texture/area-btn-bg.png', 1, 0.9)
    backgroundImage.verticalAlignment = Control.VERTICAL_ALIGNMENT_TOP
    rect.addControl(backgroundImage)

    const button = Button.CreateSimpleButton(`area-button-${index}`, title)
    button.thickness = 0
    button.fontSize = '16px'
    // button.background = 'rgb(45,149,251)'
    button.cornerRadius = 80
    button.color = 'white'
    button.onPointerClickObservable.add(() => {
      if (this._isAnimation) return
      const { x, z } = areaPointList[index].position
      this._isAnimation = true
      moveTarget(this._camera, {
        position: new BABYLON.Vector3(x, 2, z),
        radius: 100,
        speed: 60,
      }).then(() => {
        this._isAnimation = false
      })
    })
    rect.addControl(button)

    const line = new Line()
    line.lineWidth = 1
    line.color = 'rgb(45,149,251)'
    line.y2 = 20
    line.linkOffsetY = -20
    advancedTexture.addControl(line)
    line.linkWithMesh(mesh)
    line.connectedControl = rect
  }
相关推荐
涛涛ing8 分钟前
用了三年微前端,我们终于把它拆成了单体应用
前端
听情歌落俗1 小时前
嵌入式学习1-C语言基础语法与STM32实践
c语言·开发语言
去伪存真1 小时前
《最终版》《打死不改版》全传一遍?RAG 系统文件去重实战
前端
anyup1 小时前
【全端支持】 uni-app x 专用请求库:axios 写法,多实例、拦截器、可中断、上传下载
前端·uni-app·unix
小飞在努力1 小时前
【实现负载均匀在线判题⑤】MVC 架构搭建与 Model 题目数据模块实现
c语言·开发语言·c++·笔记·后端
费曼学习法1 小时前
6 个 MCP Server 传输层重写实录:超时率 12% → 0.3%
前端·后端
htzyl2061 小时前
金额计算:为什么前端不该用浮点数存钱
前端·javascript·算法
Iseeyore1 小时前
Vue3 Vs React
前端·vue.js
verohh2 小时前
第二篇:模块解耦与边界治理——清理长期迭代积累的模块耦合问题
前端
律宏阔2 小时前
微信小程序 + Taro + TanStack Query 缓存与页面返回刷新踩坑实录
前端·微信小程序·taro