• three图形控制页面


    安装

    npm i dat.gui

    引入 

    import * as dat from 'dat.gui'

     实例化

    this.gui = new dat.GUI()

    使用代码

    1. this.gui.add(this.camera.position, 'x', -5, 5, 0.1).name('相机位置x')
    2. this.gui.add(this.camera.position, 'y', -5, 5, 0.1).name('相机位置y')
    3. this.gui.add(this.camera.position, 'z', -5, 5, 0.1).name('相机位置z')

    使用参数说明 

    参数一: 控制的对象(注意第一个参数只能放对象 )

    参数二:控制对象里面的属性

    参数三: 属性的最低取值

    参数四: 属性的最高取值

    参数五: 属性每次增加(减少)的值

    .name(a): a是控制属性的名吧

    效果如图 

    上面可以把相机都放到一个文件下 

    1. const folder1 = this.gui.addFolder('相机位置')
    2. folder1.add(this.camera.position, 'x', -5, 5).name('相机位置x')
    3. folder1.add(this.camera.position, 'y', -5, 5).name('相机位置y')
    4. folder1.add(this.camera.position, 'z', -5, 5).name('相机位置z')

    效果如图 

    如果this.gui.add()只给两个参数 就会显示一个选框    选中为true  反之false

    1. const geometry1 = new THREE.BoxGeometry(1, 1, 1, 1, 1, 1)
    2. const material1 = new THREE.MeshBasicMaterial({ color: 0xff00ff})
    3. material1.wireframe = true
    4. this.cube1 = new THREE.Mesh(geometry1, material1)
    5. this.gui.add(this.cube1.position, 'x', -5, 5).name('物体位置-x')
    6. this.gui.add(this.cube1.position, 'y', -5, 5).name('物体位置-y')
    7. this.gui.add(this.cube1.position, 'z', -5, 5).name('物体位置-z')
    8. this.gui.add(material1, 'wireframe')

    图片

    给物体选择颜色this.gui.addColor()

    1. // 物体
    2. const cubeControls = { color: 0xff0000 }
    3. const geometry1 = new THREE.BoxGeometry(1, 1, 1, 1, 1, 1)
    4. const material1 = new THREE.MeshBasicMaterial({ color: cubeControls.color})
    5. material1.wireframe = true
    6. this.cube1 = new THREE.Mesh(geometry1, material1)
    7. this.gui.addColor(cubeControls, 'color').onChange(() => {
    8. material1 = cubeControls.color
    9. })

    效果如图所示

     按钮操作

     

  • 相关阅读:
    国内某知名半导体公司:实现虚拟化环境下的文件跨网安全交换
    【C#】vs2022 .net8
    探索云原生技术之容器编排引擎-Kubernetes/K8S详解(8)
    CompletableFuture详解-初遇者-很细
    基于SSM的学生信息管理系统
    Nexus3 安装 及 配置 docker 私有、代理 仓库
    SRT服务端的搭建
    微信小程序开发---页面导航
    [GitLab CI/CD]记录基于Docker的环境搭建实践
    前端实战|React18极客园——项目打包与优化
  • 原文地址:https://blog.csdn.net/qq_52421092/article/details/126867750