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
  }
相关推荐
冴羽yayujs9 分钟前
GitHub 前端热榜项目 - 日榜(2026-05-07)
前端·github
kels889911 分钟前
2026 年黄金实时价格数据 API 接口实测推荐
开发语言·笔记·python·金融·区块链
深蓝海拓11 分钟前
用HSL颜色系统改造qdarkstyle样式表库
前端·笔记·python·qt·学习
FlyWIHTSKY12 分钟前
Element Plus 中 el-row 和 el-col 的完整使用指南**
javascript·vue.js·ecmascript
摇滚侠16 分钟前
基于 Redis 实现验证码登录
javascript·redis·bootstrap
牢七18 分钟前
链条合集整理
java·开发语言
叼烟扛炮32 分钟前
C++ 知识点06 inline
开发语言·c++·inline
wuxia211842 分钟前
Web全栈开发案例教程(AI辅助版)
前端
MonkeyKing715543 分钟前
Flutter Riverpod 2.x 设计思想与最佳实践
前端·flutter
tzy2331 小时前
梳理一下前端模块化规范:CommonJS ESM AMD CMD UMD
前端·webpack·cmd·commonjs·amd·esm·umd