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
  }
相关推荐
FungLeo11 分钟前
成为全栈·Vue管理后台篇·仪表盘不是几张卡片:组合统计接口与角色视图
前端·javascript·vue.js·rbac·仪表盘·管理后台·tanstack query
程序员大阳13 分钟前
HTML+CSS+JS对话式实战(7)-学生端活动报名功能开发
javascript·css·html·活动报名
SameX20 分钟前
HarmonyOS 做桌面卡片 onAddForm 要同步返回但数据在数据库里的解法
前端
SomeOtherTime23 分钟前
Rust 面向对象介绍(AI回答)
开发语言·python·rust
deli00728 分钟前
手机夜景模式为什么要举 3 秒?8 帧 RAW 堆栈 SNR 实测
前端
松仔log39 分钟前
Kotlin中级——callbackFlow
java·前端·kotlin
三小河39 分钟前
SWC 凭什么比 Babel 快 ?项目优化迁移踩坑记录
前端·后端
zh_xuan42 分钟前
kotlin常见面试题
开发语言·kotlin·面试题
再吃一根胡萝卜1 小时前
不改一行官方源码:用一个插件把 DeepSeek Harness 换成「平安one」
前端
西安小哥1 小时前
做 Agent 写到第三个小时,我开始给它算账
javascript