1、引入gui文件
// 导入gui
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
// 导入tween
import * as TWEEN from 'three/examples/jsm/libs/tween.module.js'
2、使用(场景scene创建在上一篇)
// 创建gui
const gui = new GUI()
// 创建1个球
const sphere1 = new THREE.Mesh(
new THREE.SphereGeometry(1),
new THREE.MeshBasicMaterial({ color: '#f00' })
)
sphere1.position.x = -4
scene.add(sphere1)
// 创建补间动画
const tween = new TWEEN.Tween(sphere1.position)
// 一秒后移动到4
tween.to({ x: 4 }, 2000)
// 设置循环
tween.repeat(Infinity)
// 设置往复
tween.yoyo(true)
// 设置延迟
tween.delay(1000)
// 设置缓动函数
tween.easing(TWEEN.Easing.Quadratic.InOut)
// 启动补间动画
tween.start()
let params = {
stop: () => {
tween.stop()
}
}
gui.add(params, 'stop')