当前位置:网站首页>three.js调试工具dat.gui使用
three.js调试工具dat.gui使用
2022-08-05 09:54:00 【Jedi Hongbin】
在three.js 观察物体变化不如网页方便 往往一次不能达到我们想要的位置 需要微调 而每次加载模型还需要一些时间 调试的时间就被加长了 相应的three.js的作者写了这个调试工具 方便three.js中调试。
安装
yarn add dat.gui
or
npm install --save dat.gui
导出
// CommonJS:
const dat = require('dat.gui');
// ES6:
import * as dat from 'dat.gui';
创建一个实例
const gui = new dat.GUI();
我更喜欢这样使用
import {
GUI } from "dat.gui";
const gui = new GUI();
总之选择你喜欢的方式创建一个gui实例开启调试吧
gui的工作方式
传入一个对象,对象中的键的值的类型决定调试工具的形式
比如 值是一个boolean值 对应的调试工具就展现一个复选框 该展现值的状态
如果 值是一个函数 对应就是一个按钮 点击按钮触发这个函数

以此来作为调试的格式 接下来 根据场景介绍常用的几种调试方式
修改物体的位置
物体的posiiton属性中的x,y,z决定位置

gui.add(mesh.position,'x')
把被修改的对象传进第一个参数 被修改的属性名(字符串形式)作为第二个参数 这样就是修改x轴坐标
gui.add(mesh.position,'x',0,100)
后面两个参数是最小值和最大值
这是类型定义 剩下的一个参数是一次变化多少
针对位置的修改可以封装一个函数 省的一行一行写
typescript
const positionkeys: ["x", "y", "z"] = ["x", "y", "z"];
export const guiPosiiton = (mesh: Object3D, range: number = 20, name?: string) => {
const {
name: meshName, type, uuid, position } = mesh;
// 新建一个文件夹
const fidld = gui.addFolder(name || meshName || type + uuid.substring(0, 5));
for (const key of positionkeys) {
fidld.add(position, key, position[key] - range, position[key] + range);
}
};
javascript
const positionkeys = ["x", "y", "z"];
export const guiPosiiton = (mesh, range = 20, name) => {
const {
name: meshName, type, uuid, position } = mesh;
// 新建一个文件夹
const fidld = gui.addFolder(name || meshName || type + uuid.substring(0, 5));
for (const key of positionkeys) {
fidld.add(position, key, position[key] - range, position[key] + range);
}
};
监听值的改变
gui.add({
count:0},'count',-10,10).onChange(val => {
xxx.xxx = val;
})
在onChange中获得当前的value
按钮
gui.add({
fn:() => console.log(123) },'fn')
点击 fn 调用fn这个函数 如果名字不想用属性名可以主动设置
gui.add({
fn:() => console.log(123) },'fn').name('打印')

修改纹理颜色
const material = new MeshPhongMaterial();
const params = {
color: 0xffffff
};
gui.addColor(params, "color").onChange((color) => {
material.color = color;
});


模式选择 – 选择器
const options = [1, 2, 3, 4];
gui.add({
难度: 1 }, "难度")
.options(options)
.onChange((val) => {
console.log("select", val);
});


字符串修改
gui.add({
name: "hongbin" }, "name");
常用的大概就这几个后续会慢慢补充更多调试方式
大家可以根据环境灵活调整 这个工具很有趣 建议大家尝试
边栏推荐
- Handwriting Currying - toString Comprehension
- Seata source code analysis: initialization process of TM RM client
- 汇编语言(8)x86内联汇编
- 无题十一
- Wei Dongshan Digital Photo Frame Project Learning (6) Transplantation of tslib
- 科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
- NowCoderTOP35-40——持续更新ing
- 【Unity】【UGUI】【在屏幕上显示文本】
- PAT Class B-B1019 Digital Black Hole (20)
- The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf
猜你喜欢

leetcode: 529. Minesweeper Game

Open Source Summer | How OpenHarmony Query Device Type (eTS)

Oracle temporary table space role

Tanabata romantic date without overtime, RPA robot helps you get the job done

js graphics operation one (compatible with pc, mobile terminal to achieve draggable attribute drag and drop effect)

seata源码解析:事务状态及全局锁的存储

手把手教你纯c实现异常捕获try-catch组件

Custom filters and interceptors implement ThreadLocal thread closure

【AGC】增长服务1-远程配置示例

egg框架使用(二)
随机推荐
欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(上)
Oracle temporary table space role
Four years of weight loss record
What is the function of the regular expression replaceAll() method?
mysql进阶(二十七)数据库索引原理
Why do I recommend using smart async?
CPU的亲缘性affinity
Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
seata源码解析:事务状态及全局锁的存储
【AGC】增长服务1-远程配置示例
C语言的高级用法
Microservice Technology Stack
2022-08-01 Review the basic binary tree and operations
Custom filters and interceptors implement ThreadLocal thread closure
Overall design and implementation of Kubernetes-based microservice project
Tanabata romantic date without overtime, RPA robot helps you get the job done
my journal link
无题一
偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
Why are RELTABLESPACE values 0 for many tables displayed in sys_class?