three加载三维vrm模型和fbx动作文件实现美少女人物跳舞动画效果代码

代码语言:html

所属分类:三维

代码描述:three加载三维vrm模型和fbx动作文件实现美少女人物跳舞动画效果代码,fbx动作文件可在mixamo上下载,2000多个不同的动作姿态动画。

代码标签: three 三维 vrm 模型 fbx 动作 文件 人物 跳舞 动画

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

<!DOCTYPE html>

<html>
	<head>
		<meta charset="utf-8" />
	
		<meta
			name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
		/>
		<style>
			body {
				margin: 0;
			}

			canvas {
				display: block;
			}

			#divInfo {
				padding: 8px;
				position: fixed;
				background: white;
			}
		</style>
	</head>

	<body>
		<div id="divInfo">
		从这个网站 <a href="https://www.mixamo.com/" target="_blank" rel="noopener noreferrer">mixamo</a> 下载一个动作动画fbx文件拖拽到这个窗口就能让人物动起来<br />
		</div>

	
		
	<script type="importmap">
  {
    "imports": {
      "fflate": "//repo.bfw.wiki/bfwrepo/js/fflate.esm.browser.js",
      "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/164/three.module.js",
      "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/164/jsm/",
      "@pixiv/three-vrm": "//repo.bfw.wiki/bfwrepo/js/three-vrm.module.3.0.0.js"
    }
  }
		</script>

		<script type="module">
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { VRMLoaderPlugin, VRMUtils } from '@pixiv/three-vrm';
import { loadMixamoAnimation } from '//repo.bfw.wiki/bfwrepo/js/module/loadMixamoAnimation.js';
import GUI from 'three/addons/libs/lil-gui.module.min.js';

// renderer
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );

// camera
const camera = new THREE.PerspectiveCamera( 30.0, window.innerWidth / window.innerHeight, 0.1, 20.0 );
camera.position.set( 0.0, 1.0, 5.0 );

// camera controls
const controls = new OrbitControls( camera, renderer.domElement );
controls.screenSpacePanning = true;
controls.target.set( 0.0, 1.0, 0.0 );
controls.update();

// scene
const scene = new THREE.Scene();

// light
const light = new THREE.DirectionalLight( 0xffffff, Math.PI );
light.position.set( 1.0, 1.0, 1.0 ).normalize();
scene.add( light );

const defaultModelUrl = '//repo.bfw.wiki/bfwrepo/threemodel/girl.vrm';

// gltf and vrm
let currentVrm = undefined;
let currentAnimationUrl = "//repo.bfw.wiki/bfwrepo/threemodel/Rumba Dancing.fbx";
let currentMixer = undefined;

//const helperRoot = new THREE.Group();
//helperRoot.renderOrder = 10000;
//scene.add( helperRoot );

function loadVRM( modelUrl ) {

	const loader = new GLTFLoader();
	loader.crossOrigin = 'anonymous';

	//helperRoot.clear();

	loader.register( ( parser ) =&.........完整代码请登录后点击上方下载按钮下载查看

网友评论0