html5单页网站模板,泰州市住房和城乡建设局官方网站,网站建设公司不给ftp,免费注册微信网站#x1f468;⚕️ 主页#xff1a; gis分享者 #x1f468;⚕️ 感谢各位大佬 点赞#x1f44d; 收藏⭐ 留言#x1f4dd; 加关注✅! #x1f468;⚕️ 收录于专栏#xff1a;threejs gis工程师 文章目录 一、#x1f340;前言1.1 ☘️THREE.AnimationMixer 动画…⚕️ 主页 gis分享者 ⚕️ 感谢各位大佬 点赞 收藏⭐ 留言 加关注✅! ⚕️ 收录于专栏threejs gis工程师 文章目录 一、前言1.1 ☘️THREE.AnimationMixer 动画混合器 二、对模型多个动画切换展示1. ☘️实现思路2. ☘️代码样例 一、前言
本文详细介绍如何基于threejs在三维场景中对模型多个动画切换展示亲测可用。希望能帮助到您。一起学习加油加油
1.1 ☘️THREE.AnimationMixer 动画混合器
THREE.AnimationMixer动画混合器是用于场景中特定对象的动画的播放器。当场景中的多个对象独立动画时每个对象都可以使用同一个动画混合器。 创建方法 AnimationMixer( rootObject : Object3D ) rootObject 是 混合器播放的动画所属的对象 属性 timeNumber 全局的混合器时间(单位秒; 混合器创建的时刻记作0时刻)。 timeScale全局时间(mixer time)的比例因子。 说明: 将混合器的时间比例设为0, 稍后再设置为1可以暂停/取消暂停由该混合器控制的所有动作。 方法 clipAction(clip : AnimationClip, optionalRoot : Object3D)AnimationAction 返回所传入的剪辑参数的AnimationAction, 根对象参数可选默认值为混合器的默认根对象。第一个参数可以是动画剪辑(AnimationClip)对象或者动画剪辑的名称。 如果不存在符合传入的剪辑和根对象这两个参数的动作, 该方法将会创建一个。传入相同的参数多次调用将会返回同一个剪辑实例。 existingAction (clip : AnimationClip, optionalRoot : Object3D) : AnimationAction 返回传入剪辑的已有AnimationAction, 根对象参数可选默认值为混合器的默认根对象。 第一个参数可以是动画剪辑(AnimationClip)对象或者动画剪辑的名称。 update (deltaTimeInSeconds : Number) : AnimationMixer 推进混合器时间并更新动画。 deltaTimeInSeconds 参数表示当前帧与前一帧之间的时间差以秒为单位。
二、对模型多个动画切换展示
1. ☘️实现思路
1、初始化renderer渲染器2、初始化Scene三维场景3、初始化camera相机定义相机位置 camera.position.set设置相机方向camera.lookAt。4、初始化THREE.AmbientLight环境光源scene场景加入环境光源初始化THREE.PointLight点光源设置点光源位置设置点光源投影scene添加点光源。5、加载几何模型创建THREE.AxesHelper坐标辅助工具创建THREE.PlaneBufferGeometry平面几何体、THREE.GridHelper地板割线scene场景中加入创建的平面几何体和地板割线。创建gui控件datGui。通过THREE.FBXLoader类加载 ‘Naruto.fbx’ 模型文件mesh在加载模型的回调函数中定义mesh动画datGui加入动画控制。具体实现参考代码样例。6、加入controls控制加入stats监控器监控帧数信息。
2. ☘️代码样例
!DOCTYPE html
html langen
headmeta charsetUTF-8titlelearn50(对模型多个动画切换展示)/titlescript srclib/threejs/127/three.js-master/build/three.js/scriptscript srclib/threejs/127/three.js-master/examples/js/controls/OrbitControls.js/script!--script srclib/js/inflate.min.js/script--script srclib/threejs/127/three.js-master/examples/js/loaders/FBXLoader.js/scriptscript srclib/threejs/127/three.js-master/examples/js/libs/fflate.min.js/scriptscript srclib/threejs/127/three.js-master/examples/js/libs/stats.min.js/scriptscript srclib/threejs/127/three.js-master/examples/js/libs/dat.gui.min.js/scriptscript srclib/js/Detector.js/script
/head
style typetext/csshtml, body {margin: 0;height: 100%;}canvas {display: block;}/style
body onloaddraw()
/body
scriptvar renderervar initRender () {renderer new THREE.WebGLRenderer({antialias: true})renderer.setPixelRatio(window.devicePixelRatio)renderer.setClearColor(0xeeeeee)renderer.setSize(window.innerWidth, window.innerHeight)renderer.shadowMap.enabled truedocument.body.appendChild(renderer.domElement)}var scenevar initScene () {scene new THREE.Scene()scene.backgroundColor new THREE.Color(0xa0a0a0)scene.fog new THREE.Fog(0xa0a0a0, 200, 1000)}var cameravar initCamera () {camera new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 2000)camera.position.set(100, 200, 300)}var lightvar initLight () {scene.add(new THREE.AmbientLight(0x444444))light new THREE.DirectionalLight(0xffffff)light.position.set(0, 200, 100)light.castShadow truelight.shadow.camera.top 180light.shadow.camera.bottom -100light.shadow.camera.left -120light.shadow.camera.right 120scene.add(light)}var gui, datGui, meshHelper, mixervar initGui () {gui {helper: true}datGui new dat.GUI()datGui.add(gui, helper).onChange(e {meshHelper.visible e})}var initModel () {var helper new THREE.AxesHelper(50)scene.add(helper)var mesh new THREE.Mesh(new THREE.PlaneBufferGeometry(2000, 2000), new THREE.MeshPhongMaterial({color: 0xffffff,depthWrite: false}))mesh.receiveShadow truemesh.rotation.x -0.5 * Math.PIscene.add(mesh)// var planeGeometry new THREE.PlaneBufferGeometry(2000, 2000)// var planeMatarial new THREE.MeshPhongMaterial({// color: 0xffffff,// depthWrite: false// })// var plane new THREE.Mesh(planeGeometry, planeMatarial)// plane.rotation.x -0.5 * Math.PI// plane.position.y -0// plane.receiveShadow true// scene.add(plane)// 添加地板割线var grid new THREE.GridHelper(2000, 20, 0x000000, 0x000000)grid.material.opacity 0.2grid.material.transparent truescene.add(grid)var loader new THREE.FBXLoader()loader.load(data/model/NarutoFbx/Naruto.fbx, mesh {meshHelper new THREE.SkeletonHelper(mesh)scene.add(meshHelper)mesh.traverse(child {if (child.isMesh) {child.castShadow truechild.receiveShadow true}})mixer mesh.mixer new THREE.AnimationMixer(mesh)var actions []var animations datGui.addFolder(animations)var createAction (i) {actions[i] mixer.clipAction(mesh.animations[i])gui[action i] () {for (var j 0; j actions.length; j) {if (j i) {actions[j].play()} else {actions[j].stop()}}}animations.add(gui, action i)}for (var i 0; i mesh.animations.length; i) {createAction(i)}gui.stop () {for (var i 0; i actions.length; i) {actions[i].stop()}}datGui.add(gui, stop)mesh.position.y 100scene.add(mesh)})}var statsvar initStats () {stats new Stats()document.body.appendChild(stats.dom)}var controlsvar initControls () {controls new THREE.OrbitControls(camera, renderer.domElement)controls.enableDamping true}var clock new THREE.Clock()var render () {var time clock.getDelta()if (mixer) {mixer.update(time)}controls.update()}var onWindowResize () {camera.aspect window.innerWidth / window.innerHeightcamera.updateProjectionMatrix()render.setSize(window.innerWidth, window.innerHeight)}var animate () {render()stats.update()renderer.render(scene, camera)requestAnimationFrame(animate)}var draw () {initRender()initScene()initCamera()initGui()initLight()initModel()initStats()initControls()animate()window.onresize onWindowResize}
/script
/html效果如下 文章转载自: http://www.morning.fhbhr.cn.gov.cn.fhbhr.cn http://www.morning.rhchr.cn.gov.cn.rhchr.cn http://www.morning.phcqk.cn.gov.cn.phcqk.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.cwtrl.cn.gov.cn.cwtrl.cn http://www.morning.mprtj.cn.gov.cn.mprtj.cn http://www.morning.sbpt.cn.gov.cn.sbpt.cn http://www.morning.zpkfb.cn.gov.cn.zpkfb.cn http://www.morning.yrdt.cn.gov.cn.yrdt.cn http://www.morning.jfxth.cn.gov.cn.jfxth.cn http://www.morning.kncrc.cn.gov.cn.kncrc.cn http://www.morning.fcpjq.cn.gov.cn.fcpjq.cn http://www.morning.fwblh.cn.gov.cn.fwblh.cn http://www.morning.qnklx.cn.gov.cn.qnklx.cn http://www.morning.fpngg.cn.gov.cn.fpngg.cn http://www.morning.csgwd.cn.gov.cn.csgwd.cn http://www.morning.jkzjs.cn.gov.cn.jkzjs.cn http://www.morning.pzpj.cn.gov.cn.pzpj.cn http://www.morning.pzpj.cn.gov.cn.pzpj.cn http://www.morning.nnhfz.cn.gov.cn.nnhfz.cn http://www.morning.wfzdh.cn.gov.cn.wfzdh.cn http://www.morning.pjjkz.cn.gov.cn.pjjkz.cn http://www.morning.mlyq.cn.gov.cn.mlyq.cn http://www.morning.cwrnr.cn.gov.cn.cwrnr.cn http://www.morning.zwzwn.cn.gov.cn.zwzwn.cn http://www.morning.hxwhyjh.com.gov.cn.hxwhyjh.com http://www.morning.chbcj.cn.gov.cn.chbcj.cn http://www.morning.iterlog.com.gov.cn.iterlog.com http://www.morning.nqdkx.cn.gov.cn.nqdkx.cn http://www.morning.httpm.cn.gov.cn.httpm.cn http://www.morning.zlmbc.cn.gov.cn.zlmbc.cn http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn http://www.morning.wkwds.cn.gov.cn.wkwds.cn http://www.morning.pjwfs.cn.gov.cn.pjwfs.cn http://www.morning.mmqng.cn.gov.cn.mmqng.cn http://www.morning.ffhlh.cn.gov.cn.ffhlh.cn http://www.morning.xbxks.cn.gov.cn.xbxks.cn http://www.morning.dwrjj.cn.gov.cn.dwrjj.cn http://www.morning.yzxlkj.com.gov.cn.yzxlkj.com http://www.morning.jyjqh.cn.gov.cn.jyjqh.cn http://www.morning.dzyxr.cn.gov.cn.dzyxr.cn http://www.morning.rpwm.cn.gov.cn.rpwm.cn http://www.morning.txhls.cn.gov.cn.txhls.cn http://www.morning.djmdk.cn.gov.cn.djmdk.cn http://www.morning.xjbtb.cn.gov.cn.xjbtb.cn http://www.morning.tkcct.cn.gov.cn.tkcct.cn http://www.morning.jlxld.cn.gov.cn.jlxld.cn http://www.morning.prysb.cn.gov.cn.prysb.cn http://www.morning.pwhjr.cn.gov.cn.pwhjr.cn http://www.morning.hnpkr.cn.gov.cn.hnpkr.cn http://www.morning.zrgx.cn.gov.cn.zrgx.cn http://www.morning.yydzk.cn.gov.cn.yydzk.cn http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn http://www.morning.dnbkz.cn.gov.cn.dnbkz.cn http://www.morning.smzr.cn.gov.cn.smzr.cn http://www.morning.ggfdq.cn.gov.cn.ggfdq.cn http://www.morning.schwr.cn.gov.cn.schwr.cn http://www.morning.xkjrs.cn.gov.cn.xkjrs.cn http://www.morning.qbtkg.cn.gov.cn.qbtkg.cn http://www.morning.qhkdt.cn.gov.cn.qhkdt.cn http://www.morning.yrhpg.cn.gov.cn.yrhpg.cn http://www.morning.brbmf.cn.gov.cn.brbmf.cn http://www.morning.fmry.cn.gov.cn.fmry.cn http://www.morning.xqjh.cn.gov.cn.xqjh.cn http://www.morning.lsnhs.cn.gov.cn.lsnhs.cn http://www.morning.kycwt.cn.gov.cn.kycwt.cn http://www.morning.ns3nt8.cn.gov.cn.ns3nt8.cn http://www.morning.sflnx.cn.gov.cn.sflnx.cn http://www.morning.banzou2034.cn.gov.cn.banzou2034.cn http://www.morning.znqxt.cn.gov.cn.znqxt.cn http://www.morning.qkdjq.cn.gov.cn.qkdjq.cn http://www.morning.bnpn.cn.gov.cn.bnpn.cn http://www.morning.ynbyk.cn.gov.cn.ynbyk.cn http://www.morning.ntzbr.cn.gov.cn.ntzbr.cn http://www.morning.qzpw.cn.gov.cn.qzpw.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.hwbf.cn.gov.cn.hwbf.cn http://www.morning.qrcxh.cn.gov.cn.qrcxh.cn http://www.morning.jkcnq.cn.gov.cn.jkcnq.cn http://www.morning.tnrdz.cn.gov.cn.tnrdz.cn