Three.js 加载 fbx 3D模型

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
   <title>Three.js</title>
   <style>
      body {
         margin: 0;
      }
   </style>
</head>
<body>
<script type="module">

   import * as THREE from '../build/three.module.js';
   import { OrbitControls } from './jsm/controls/OrbitControls.js';
   import { FBXLoader } from './jsm/loaders/FBXLoader.js';

   const scene = new THREE.Scene();
   scene.background = new THREE.Color( 0xFFFFFF );

   const hemisphereLight = new THREE.HemisphereLight( 0xffffff, 0xFFD700 );
   hemisphereLight.position.set( 0, 200, 0 );
   scene.add( hemisphereLight );

   const directionalLight = new THREE.DirectionalLight( 0xFFD700 );
   directionalLight.position.set( 0, 200, 100 );
   scene.add( directionalLight );

   const perspectiveCamera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
   perspectiveCamera.position.set( 0, 1, 1 );

   const texture = THREE.ImageUtils.loadTexture( 'Baking-mountain4K.jpg' );

   const fbxLoader = new FBXLoader();

   fbxLoader.load( 'models/fbx/scene.fbx', function ( object ) {

      object.traverse( function ( child ) {

         child.material = new THREE.MeshPhongMaterial( {
            map: texture
         } );
         if ( child.isMesh ) {

            child.castShadow = true;
            child.receiveShadow = true;

         }

      } );

      scene.add( object );

   } );

   const webGLRenderer = new THREE.WebGLRenderer();
   webGLRenderer.setSize( window.innerWidth, window.innerHeight );
   document.body.appendChild( webGLRenderer.domElement );

   const orbitControls = new OrbitControls( perspectiveCamera, webGLRenderer.domElement );
   orbitControls.target.set( 0, 0, 0 );
   orbitControls.update();

   animate();

   function animate() {

      requestAnimationFrame( animate );

      webGLRenderer.render( scene, perspectiveCamera );

   }

</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值