赞
踩
效果:
stl、obj都是静态模型,不可以包含动画,fbx除了包含几何、材质信息,可以存储骨骼动画等数据。
代码:
- <!DOCTYPE html>
- <html lang="en">
-
- <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">
- <title>.加载FBX并解析骨骼动画</title>
- <script src="../three.js"></script>
- <script src="../OrbitControls.js"></script>
- <script src="../js/FBXLoader.js"></script>
- <script src="../js/inflate.min.js"></script>
- </head>
-
- <body>
- <script>
- let N = 128;
- let analyser = null;
- // 1,创建场景
- var scene = new THREE.Scene();
- // 创建STL加载器
- var fbxLoader = new THREE.FBXLoader();
- fbxLoader.load('./斯巴达从光晕战斗进化成3D CG模型/0.fbx',
- obj => {
- scene.add(obj);
- console.log(obj);
- })
-
- // 3,创建灯光
- var point = new THREE.PointLight(0xffffff, 0.5);
- point.position.set(200, 200, 200);
- scene.add(point);
- var point2 = new THREE.PointLight(0xffffff, 0.5);
- point2.position.set(-200, 200, 200);
- scene.add(point2);
- var point3 = new THREE.PointLight(0xffffff);
- point3.position.set(200, -200, 200);
-
- // 4,创建相机对象
- var width = window.innerWidth;
- var height = window.innerHeight;
- var k = width / height;
- var s = 50;
- var camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, -2000, 2000);
- camera.position.set(0, 200, 100);
- camera.lookAt(scene.position);
- // 5,创建渲染器
- var renderer = new THREE.WebGLRenderer();
- renderer.setSize(width, height);
- document.body.appendChild(renderer.domElement);
-
- function render() {
- renderer.render(scene, camera);
- requestAnimationFrame(render);
- }
- var controls = new THREE.OrbitControls(camera, renderer.domElement);
- var axes = new THREE.AxesHelper(500);
- scene.add(axes);
- render();
- </script>
- </body>
-
- </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。