当前位置:   article > 正文

three.js 加载fbx文件并解析_three.js load fbx

three.js load fbx

效果:

 stl、obj都是静态模型,不可以包含动画,fbx除了包含几何、材质信息,可以存储骨骼动画等数据。

代码:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>.加载FBX并解析骨骼动画</title>
  8. <script src="../three.js"></script>
  9. <script src="../OrbitControls.js"></script>
  10. <script src="../js/FBXLoader.js"></script>
  11. <script src="../js/inflate.min.js"></script>
  12. </head>
  13. <body>
  14. <script>
  15. let N = 128;
  16. let analyser = null;
  17. // 1,创建场景
  18. var scene = new THREE.Scene();
  19. // 创建STL加载器
  20. var fbxLoader = new THREE.FBXLoader();
  21. fbxLoader.load('./斯巴达从光晕战斗进化成3D CG模型/0.fbx',
  22. obj => {
  23. scene.add(obj);
  24. console.log(obj);
  25. })
  26. // 3,创建灯光
  27. var point = new THREE.PointLight(0xffffff, 0.5);
  28. point.position.set(200, 200, 200);
  29. scene.add(point);
  30. var point2 = new THREE.PointLight(0xffffff, 0.5);
  31. point2.position.set(-200, 200, 200);
  32. scene.add(point2);
  33. var point3 = new THREE.PointLight(0xffffff);
  34. point3.position.set(200, -200, 200);
  35. // 4,创建相机对象
  36. var width = window.innerWidth;
  37. var height = window.innerHeight;
  38. var k = width / height;
  39. var s = 50;
  40. var camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, -2000, 2000);
  41. camera.position.set(0, 200, 100);
  42. camera.lookAt(scene.position);
  43. // 5,创建渲染器
  44. var renderer = new THREE.WebGLRenderer();
  45. renderer.setSize(width, height);
  46. document.body.appendChild(renderer.domElement);
  47. function render() {
  48. renderer.render(scene, camera);
  49. requestAnimationFrame(render);
  50. }
  51. var controls = new THREE.OrbitControls(camera, renderer.domElement);
  52. var axes = new THREE.AxesHelper(500);
  53. scene.add(axes);
  54. render();
  55. </script>
  56. </body>
  57. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/91505
推荐阅读
相关标签
  

闽ICP备14008679号