1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import * as TWEEN from "three/examples/jsm/libs/tween.module.js"
const gui = new GUI()
const sphere1 = new THREE.Mesh( new THREE.SphereGeometry(1, 32, 32), new THREE.MeshBasicMaterial({color:0x00ff00}) ) sphere1.position.x = -4 scene.add(sphere1)
const tween = new TWEEN.Tween(sphere1.position)
tween.to({x:4},1000).onUpdate(() => { console.log(sphere1.position.x) })
tween.easing(TWEEN.Easing.Quadratic.InOut)
const tween2 = new TWEEN.Tween(sphere1.position) tween2.to({y:4},1000)
tween.chain(tween2)
tween2.chain(tween)
tween.start()
tween.onStart(()=>{ console.log("开始")})
tween.onComplete(()=>{console.log("完成")})
tween.onStop(()=>{console.log("停止")})
tween.onUpdate(()=>{console.log("更新")}) let params = { stop : () => { tween.stop() } } gui.add(params, "stop").name("暂停") const animate = () => { requestAnimationFrame(animate) renderer.render(scene, camera) TWEEN.update() } animate()
|