Three 之 Animation 初印象
2021-10-10 13:28
155 查看
Animation 初印象
动画效果
播放动画需要基本元素
AnimationMixer
一个对象所有动作的管理者
用于场景中特定对象的动画的播放器。一个对象可能有多个动作,Mixer 是用来管理所有动作的,它可以调度出对象的某个动作进行操控,如
mixer = new THREE.AnimationMixer(obj);mixer 就能管理 obj 对象的所有动画了。拥有 mixer 后,在 animate 函数中进行更新操作,用于更新该对象目前的状态。 mixer 可以让这个对象同时播放多个动作,因此需要在每帧中执行 update 方法
AnimationClip
一个对象的一个动作
动画剪辑(AnimationClip)是一个可重用的关键帧轨道集,它代表动画。
AnimationAction
用来管理单个动作,让这个动作开始暂停等等
AnimationActions 用来调度存储在 AnimationClips 中的动画。说明: AnimationAction的大多数方法都可以链式调用
使用方法
- 加载一个对象,加载这个对象对应的 mixer 用于管理所有动作
mixer = new THREE.AnimationMixer(obj);
- 加载出一个 action,用于处理单个(clip)动画集,并进行播放
mixer.clipAction(obj.animations[0]).play();
上文提到过 action 是可以链式操作了,clipAction 方法返回一个 action 对象
- 在每一帧中更新对象的状态
mixer.update(delta);
实际代码
export function AnimationCommin() { const content = useRef(); const scene = new THREE.Scene(); scene.background = new THREE.Color(0xbfe3dd); const pointLight = new THREE.PointLight(0xffffff, 0.6); pointLight.position.set(150, 150, 150); scene.add(pointLight); scene.add(new THREE.AmbientLight(0xffffff, 2)); const clock = new THREE.Clock(); let mixer; useEffect(() => { const canvas = content.current; const renderer = new THREE.WebGLRenderer({ antialias: true, canvas }); renderer.setPixelRatio(window.devicePixelRatio); renderer.setSize(canvas.clientWidth, canvas.clientHeight); const stats = new Stats(); canvas.appendChild(stats.dom); const camera = new THREE.PerspectiveCamera( 40, canvas.clientWidth / canvas.clientHeight, 1, 1000 ); camera.position.set(200, 200, 200); const controls = new OrbitControls(camera, canvas); controls.update(); const loader = new FBXLoader(); loader.load("/RumbaDancing.fbx", (obj) => { scene.add(obj); mixer = new THREE.AnimationMixer(obj); mixer.clipAction(obj.animations[0]).play(); }); animate(); function animate() { requestAnimationFrame(animate); const delta = clock.getDelta(); if (mixer) mixer.update(delta); controls.update(); stats.update(); renderer.render(scene, camera); } }); return <canvas ref={content} />; }
相关文章推荐
- creating-skeletal-animation-in-blender-and-exporting-it-to-three-js
- 系列博文-Three.js入门指南(张雯莉)-网格 setInterval方法 requestAnimationFrame方法 使用stat.js记录FPS
- Three 之 Animation 体验一
- Blender Export Animation (Blender 导出 动画 THREE.js)
- 20个令人印象深刻的例子学习Three.js实现WebGL
- Geodesic-based robust blind watermarking method for three-dimensional mesh animation by using mesh segmentation and vertex trajectory
- 动画(Animation) 之 (闪烁、左右摇摆、上下晃动等效果)
- Core Animation初识之CABasicAnimation
- 动画效果 --Animation 总汇(动画专题研究二)
- CSS3 Transitions, Transforms和Animation的使用
- Android各种切换特效资料收集(3D, Launcher, viewanimator,animation...) 持续更新
- Animation的二种使用方法一种是JavaCode一种是xml文件配置
- 开发者印象:用PhoneGap开发混搭Web应用
- animation
- Django的第一印象
- iOS CoreAnimation专题——原理篇(三) CALayer的模型层与展示层
- Detailed Manual of Hongxing Hammer Crusher Three
- iOS 动画效果:Core Animation & Facebook's pop
- Android: ListView添加animation后,在animation播放过程中背景变为黑色背景的解决方法
- [Cocos2d-x开发问题-3] cocos2dx动画Animation介绍