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
  }
相关推荐
旺王雪饼 www15 小时前
《Express框架深度解析:从基础入门到高级实践与项目架构》
前端·node.js·express
时寒的笔记15 小时前
js7逆向案例_禁止f12打开&sojson打开
开发语言·javascript·ecmascript
stpzhf15 小时前
uniapp nvue组件多个text在一行并且高亮其中一些文字
前端·javascript·uni-app
大鹏说大话15 小时前
什么是“过早优化”?
开发语言
码云数智-园园15 小时前
RESTful API vs GraphQL:设计哲学、性能博弈与选型指南
开发语言
十一.36615 小时前
003-004 虚拟DOM的两种创建方式、虚拟DOM与真实DOM
前端·javascript·html
三声三视15 小时前
React 18 并发渲染实战:useTransition、Suspense 与自动批处理深度解析
前端·javascript·react.js
xiaotao13115 小时前
第十八章:微前端与 Module Federation
前端·vite·前端打包
每天吃饭的羊15 小时前
nest,java对比
java·开发语言
sycmancia15 小时前
Qt——登录对话框
开发语言·qt