threejs加载fbx三维男人人物模型并进行手势运动动画效果代码

代码语言:html

所属分类:三维

代码描述:threejs加载fbx三维男人人物模型并进行手势运动动画效果代码

代码标签: threejs 加载 fbx 三维 男人 人物 模型 手势 运动 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  
  <style>
    :root {
      --themeColor: #0072ff;
      --secondColor: #00c6ff;
    }
    * {
      margin: 0;
      padding: 0;
    }
    html {
      background: var(--themeColor);
      background: -webkit-linear-gradient(to left, var(--themeColor) , var(--secondColor));
      background: linear-gradient(to left, var(--themeColor), var(--secondColor));
    }
    body {
  
      font-family: Arial, Helvetica, sans-serif;
    }
    .loading {
      position: fixed;
      height: 100%;
      width: 100%;
      left: 0;
      top: 0;
      background: #FFFFFF;
    }
    .loading .content {
      height: 330px;
      width: 540px;
      position: absolute;
      top: 50%;
      left: 50%;
      margin-top: -165px;
      margin-left: -270px;
    }
    .loading .content .banner {
      display: inline-block;
      width: 540px;
      height: 303px;
      background: url('//repo.bfw.wiki/bfwrepo/icon/5f7abfbff367a.gif') no-repeat center;
      background-size: 100% 100%;
    }
    .loading .content {
      text-align: center;
      font-size: 20px;
      color: #666666;
    }
    .loading .content span {
      color: var(--themeColor);
      padding-left: 8px;
    }
    .logo {
      position: absolute;
      top: 56px;
      left: 56px;
      width: 321px;
      height: 64.875px;
      background: url('//repo.bfw.wiki/bfwrepo/icon/617245a85118d.png') no-repeat center;
      background-size: 100% 100%;
      filter: drop-shadow(0px 1px 5px rgba(255, 255, 255, .2));
    }
  </style>
</head>

<body>
  <i class="logo"></i>
  <div class="loading" id="loading">
    <div class="content">
      <i class="banner"></i>
      <p class="text">加载进度<span id="progress">0%</span></p>
    </div>
  <div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.92.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/FBXLoader.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/inflate.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.min.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Stats-16.js"></script>
  <script>
    var container, stats, controls, compose;
    var camera, scene, renderer, light, clickableObjects = [];
    var clock = new THREE.Clock();
    var mixer, mixerArr = [], manMixer;
    init();
    animate();
    function init() {
      container = document.createElement('div');
      document.body.appendChild(container);
      // 场景
      scene = new THREE.Scene();
      scene.transparent = true;
      scene.opacity = 0.1;
      scene.fog = new THREE.Fog(0xa0a0a0, 200, 1000);
      // 透视相机:视场、长宽比、近面、远面
      camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 1000);
      camera.position.set(0, 4, 16);
      camera.lookAt(new THREE.Vector3(0, 0, 0));
      // 半球光源:创建室外效果更加自然的光源
      light = new THREE.HemisphereLight(0xefefef);
      light.position.set(0, 20, 0);
      scene.add(light);
      // 平行光
      light = new THREE.DirectionalLight(0x2d2d2d);
      light.position.set(0, 20, 10);
      light.castShadow = true;
      scene.add(light);
      // 环境光
      var ambientLight = new THREE.AmbientLight(0xffffff, .5);
      scene.add(ambientLight);
      // 网格
      var grid = new THREE.GridHelper(100, 100, 0xffffff, 0xffffff);
      grid.position.set(0, -10, 0);
      grid.material.opacity = 0.3;
      grid.material.transparent = true;
      scene.add(grid);
      // 加载模型
      var loader = new THREE.FBXLoader();
      var texLoader = new THREE.TextureLoader();
      loader.load('//repo.bfw.wiki/bfwrepo/threemodel/meta.fbx', function (mesh) {
        mesh.traverse(function (child) {
          if (child.isMesh) {
            child.castShadow = true;
            child.receiveShadow = true;
            // 隐藏多余物体
            if (child.name === '球体' || child.name === '球体001') {
              child.visible = false
            }
            // 设置材质
            if (child.name === '贝塞尔圆') {
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0