当前位置:网站首页>Threejs MMD model loading + contour loading + animation loading + Audio loading + camera animation loading +ammojs loading gltf model loading +gltf reflection adjustment
Threejs MMD model loading + contour loading + animation loading + Audio loading + camera animation loading +ammojs loading gltf model loading +gltf reflection adjustment
2022-06-24 09:32:00 【Under the bridge in front of the gate】
<script src="./base/ammo.wasm.js"> </script>
import React, {
Component} from 'react';
import "./home.css"
import * as THREE from "three";
import {
OrbitControls} from "three/examples/jsm/controls/OrbitControls";
// import {GLTFLoader} from "three/examples/jsm/loaders/GLTFLoader";
// load mmd Physical model
import {
MMDLoader} from "three/examples/jsm/loaders/MMDLoader";
// introduce Outer frame line
import {
OutlineEffect} from "three/examples/jsm/effects/OutlineEffect";
// Animation
import {
MMDAnimationHelper} from "three/examples/jsm/animation/MMDAnimationHelper";
// load Physical engine
window.Ammo().then(res=>{
window.Ammo=res})
const clock=new THREE.Clock()
class Home extends Component {
ready:false
constructor(args) {
super(args);
this.state={
width:window.innerWidth,
height:window.innerHeight,
count:0
}
}
render() {
return (
<div className={
'three-canvas'}>
</div>
);
}
componentDidMount() {
if(this.state.count===0){
this.init()
this.state.count++
}
}
getRenderer(){
// Set up
const renderer=new THREE.WebGLRenderer()
renderer.gammaFactor=true
renderer.setSize(this.state.width,this.state.height)
document.querySelector('.three-canvas').appendChild(renderer.domElement)
return renderer
}
getCamera(){
const camera=new THREE.PerspectiveCamera(75,this.state.width/this.state.height,1,1000)
camera.position.z=50
camera.lookAt(0,0,0)
return camera
}
getScene(){
const scene=new THREE.Scene()
return scene
}
addCube(){
const box= new THREE.Mesh(
new THREE.BoxGeometry(2,2,2),
new THREE.MeshNormalMaterial()
)
this.scene.add(box)
}
getControl(){
const control=new OrbitControls(this.camera,this.renderer.domElement)
return control
}
addSenceBg(){
this.scene.background=new THREE.CubeTextureLoader().setPath('/textures/cube/Bridge2/').load(
['posx.jpg',"negx.jpg",
'posy.jpg',"negy.jpg",
'posz.jpg',"negz.jpg",
]
)
}
addToukui(){
// const loader = new GLTFLoader();
// loader.load('models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf',res=>{
// res.scene.traverse(mesh=>{
// if (mesh.isMesh){
// mesh.material.envmap=this.scene.background
// }
// })
// this.scene.add(res.scene)
// })
// load Ammd Model of
this.helper = new MMDAnimationHelper();
const loader = new MMDLoader();
loader.loadWithAnimation(
// path to PMD/PMX file
'models/mmd/miku/miku_v2.pmd',
'models/mmd/vmds/wavefile_v2.vmd',
// called when the resource is loaded
( mmd ) =>{
this.helper.add( mmd.mesh, {
animation: mmd.animation,
physics: true
} );
this.scene.add( mmd.mesh );
// Load the audio
const audioLoader=new THREE.AudioLoader()
audioLoader.load(
'models/mmd/audios/wavefile_short.mp3',
( buffer )=> {
const listener = new THREE.AudioListener();
const audio = new THREE.Audio( listener ).setBuffer( buffer );
this.helper.add(audio,{
delayTime:160/30})
listener.position.z = 1;
this.scene.add( audio );
this.scene.add( listener );
this.ready=true
}
);
loader.loadAnimation('models/mmd/vmds/wavefile_camera.vmd',
this.camera,
animations=>{
this.helper.add(this.camera,{
animation:animations
})
}
)
}
)
}
addLight(){
const light = new THREE.AmbientLight( 0xffffff);
light.position.set( 20, 20, 20 );
this.scene.add( light );
}
init(){
// establish rander -- The camera --- scene ---- Animation
this.renderer=this.getRenderer()
this.renderer=new OutlineEffect(this.renderer)
this.camera=this.getCamera()
this.scene=this.getScene()
// Add objects
// this.addCube()
// Add helmet
this.addToukui()
// Add lights
this.addLight()
// Add controller
this.control=this.getControl()
// Set the background
this.addSenceBg()
// Perform animation
this.animation()
}
animation(){
requestAnimationFrame(this.animation.bind(this))
this.renderer.render(this.scene,this.camera)
if(this.ready){
this.helper.update( clock.getDelta() );
}
this.control.update()
}
}
export default Home;
边栏推荐
- ThinkPHP5多语言切换项目实战
- Numpy numpy中的np.c_和np.r_详解
- 深入了解 border
- Dynamic saving and recovery of FPU context under risc-v architecture
- The native applet uses canvas to make posters, which are scaled to the same scale. It is similar to the uniapp, but the writing method is a little different
- LeetCode: 240. 搜索二维矩阵 II
- Cdga | how can we do well in data governance?
- 实战剖析:app扫码登陆实现原理(app+网页端详细逻辑)附源码
- PHP封装一个文件上传类(支持单文件多文件上传)
- NETRCA: AN EFFECTIVE NETWORK FAULT CAUSE LOCALIZATION之论文阅读
猜你喜欢
![The printed object is [object object]. Solution](/img/fc/9199e26b827a1c6304fcd250f2301e.png)
The printed object is [object object]. Solution
![[GDB debugging tool] | how to debug under multithreading, multiprocessing and running programs](/img/b5/38a53c88240c4308452d0208173461.png)
[GDB debugging tool] | how to debug under multithreading, multiprocessing and running programs

Squid proxy application

Netrca: an effective network fault cause localization

Alibaba Senior Software Testing Engineer recommends testers to learn -- Introduction to security testing

浮点数表示法(总结自CS61C和CMU CSAPP)

【LeetCode】415. String addition

Remote connection of raspberry pie without display by VNC viewer

十二、所有功能实现效果演示

Easyexcel single sheet and multi sheet writing
随机推荐
二十、处理器调度(RR时间片轮转,MLFQ多级反馈队列,CFS完全公平调度器,优先级翻转;多处理器调度)
Target of cmake command_ compile_ options
Squid proxy application
2020 China's provinces and cities, three-level linkage data, data agencies (data from the official website of the National Bureau of Statistics)
P6117-[joi 2019 final] greedy
从618看京东即时零售的野心
cookie加密 4 rpc方法确定cookie加密
Lu Qi: I am most optimistic about these four major technology trends
LeetCode: 137. 只出现一次的数字 II
[noi Simulation Competition] send (tree DP)
Easyexcel single sheet and multi sheet writing
Event registration Apache pulsar x kubesphere online meetup hot registration
Redis实现全局唯一ID
当程序员被问会不会修电脑时… | 每日趣闻
活动报名|Apache Pulsar x KubeSphere 在线 Meetup 火热报名中
学习太极创客 — ESP8226 (十二)ESP8266 多任务处理
threejs的 mmd模型加载+轮廓加载+动画加载+音频加载+相机动画加载+ammojs加载 gltf模型的加载 +gltf的反射调整
零基础自学SQL课程 | 相关子查询
Weekly recommended short video: is the ultimate form of computing "meta universe"?
How to import MDF and LDF files into MySQL workbench