当前位置:网站首页>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");
常用的大概就这几个后续会慢慢补充更多调试方式
大家可以根据环境灵活调整 这个工具很有趣 建议大家尝试
边栏推荐
- EU | Horizon 2020 ENSEMBLE: D2.13 SOTIF Safety Concept (Part 2)
- hcip BGP 增强实验
- dotnet OpenXML 解析 PPT 图表 面积图入门
- Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
- MQTT X Newsletter 2022-07 | 自动更新、MQTT X CLI 支持 MQTT 5.0、新增 conn 命令…
- Four years of weight loss record
- eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑
- 浅析WSGI协议
- Happens-before rules for threads
- seata源码解析:事务状态及全局锁的存储
猜你喜欢
周报2022-8-4
Bias lock/light lock/heavy lock lock is healthier. How is locking and unlocking accomplished?
Tanabata romantic date without overtime, RPA robot helps you get the job done
Egg framework usage (2)
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
CPU的亲缘性affinity
What is CRM Decision Analysis Management?
ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...
自定义过滤器和拦截器实现ThreadLocal线程封闭
leetcode: 529. 扫雷游戏
随机推荐
seata源码解析:事务状态及全局锁的存储
STM32+ULN2003驱动28BYJ4步进电机(根据圈数正转、反转)
19. Server-side session technology Session
长达四年的减肥记录
开发常用手册链接分享
Overall design and implementation of Kubernetes-based microservice project
PHP operation mangoDb
Why are RELTABLESPACE values 0 for many tables displayed in sys_class?
无题九
js 图形操作一(兼容pc、移动端实现 draggable属性 拖放效果)
首次去中心化抢劫?近2亿美元损失:跨链桥Nomad 被攻击事件分析
偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
5. Deploy the web project to the cloud server
Why do I recommend using smart async?
PAT乙级-B1019 数字黑洞(20)
leetcode 剑指 Offer 10- I. 斐波那契数列
IDEA执行Test操作导致数据插入时出现了重复数据
MySQL advanced (twenty-seven) database index principle
Hundred lines of code launch red hearts, why programmers lose their girlfriends!
[Unity] [UGUI] [Display text on the screen]