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
  }
相关推荐
2501_941802484 分钟前
面向微服务限流、熔断与降级协同的互联网系统高可用架构与多语言工程实践分享
开发语言·python
程序员爱钓鱼5 分钟前
Node.js 编程实战:Node.js + React Vue Angular 前后端协作实践
前端·后端·node.js
程序员爱钓鱼6 分钟前
Node.js 编程实战:前后端结合的 SSR 服务端渲染
前端·后端·node.js
2501_9418752810 分钟前
分布式系统中的安全权限与审计工程实践方法论经验总结与多语言示例解析分享
开发语言·rabbitmq
无限进步_17 分钟前
【C语言】堆排序:从堆构建到高效排序的完整解析
c语言·开发语言·数据结构·c++·后端·算法·visual studio
haokan_Jia18 分钟前
Java 并发编程-ScheduledFuture
java·前端·python
bst@微胖子20 分钟前
CrewAI+FastAPI实现多Agent协作项目
java·前端·fastapi
掘金酱20 分钟前
TRAE 2025 年度报告分享活动|获奖名单公示🎊
前端·人工智能·后端
雾岛听蓝22 分钟前
STL 容器适配器:stack、queue 与 priority_queue
开发语言·c++
CSDN_RTKLIB24 分钟前
【One Definition Rule】多编译单元定义同名全局变量
开发语言·c++