当前位置:网站首页>Contrôleur pour threejs cube Space Basic Controller + Inertial Control + Flight Control
Contrôleur pour threejs cube Space Basic Controller + Inertial Control + Flight Control
2022-07-02 14:30:00 【Sous le pont avant.】
threejsContrôleur pour Espace cubique Contrôleur de base+Contrôle inertiel+Commandes de vol
import React, {
Component} from 'react';
import * as THREE from "three";
import {
OrbitControls} from "three/examples/jsm/controls/OrbitControls";
// import {reflect} from "three/examples/jsm/nodes/shadernode/ShaderNodeBaseElements";
// import {Refractor} from "three/examples/jsm/objects/Refractor";
// import {Reflector} from "three/examples/jsm/objects/Reflector";
//Plus InertielOrbitControls Mise à jour de base de
import {
TrackballControls} from "three/examples/jsm/controls/TrackballControls";
//Commandes de vol Vue de fonctionnement de la souris Pour aller de l'avant et aller de l'avant
import {
FlyControls} from "three/examples/jsm/controls/FlyControls";
const clock=new THREE.Clock()
class Index extends Component {
ready:false
constructor(args) {
super(args);
this.state={
width:window.innerWidth,
height:window.innerHeight,
count:0,
}
this.ballpoi={
x:0,
y:100,
z:0,
vx:(Math.random()-0.5)*7,
vy:(Math.random()-0.5)*7,
vz:(Math.random()-0.5)*7
}
}
render() {
return (
<div className={
'three-canvas'}>
</div>
);
}
componentDidMount() {
if(this.state.count===0){
this.init()
// eslint-disable-next-line react/no-direct-mutation-state
this.state.count++
}
}
getRenderer(){
//Paramètres
const renderer=new THREE.WebGLRenderer()
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=400
camera.lookAt(0,0,0)
return camera
}
getScene(){
const scene=new THREE.Scene()
return scene
}
getControl(){
const control=new FlyControls(this.camera,this.renderer.domElement)
control.movementSpeed=50
control.autoForward =false
control.rollSpeed=0.5
return control
}
addLight(){
//Éclairage ambiant
const light = new THREE.AmbientLight( 0xffffff,0.5);
const pointLight = new THREE.PointLight( 0xffffff,1);
pointLight.position.set(0,0,0)
pointLight.castShadow=true
this.scene.add( light ,pointLight);
}
addPlane(){
const geometry=new THREE.BoxGeometry(Math.random()*10,Math.random()*10,Math.random()*10)
const material = new THREE.MeshNormalMaterial({
side: THREE.DoubleSide})
const box= new THREE.Mesh(
geometry,
material
)
box.rotation.set(Math.PI/(Math.random()*10),Math.PI/(Math.random()*10),Math.PI/(Math.random()*10))
box.position.set((Math.random()-0.5)*300,(Math.random()-0.5)*300,(Math.random()-0.5)*300)
this.scene.add(box)
return box
}
init(){
//Créationrander --La caméra ---Scénario----Animation
this.renderer=this.getRenderer()
this.camera=this.getCamera()
this.scene=this.getScene()
this.scene.background=new THREE.Color('#d1b8b8')
for (let i=0;i<400;i++){
this.addPlane()
}
//Ajouter des lumières
this.addLight()
//Ajouter un contrôleur
this.control=this.getControl()
//Exécuter l'animation
this.animation()
}
animation(){
requestAnimationFrame(this.animation.bind(this))
this.renderer.render(this.scene,this.camera)
this.control.update(clock.getDelta())
}
}
export default Index;
边栏推荐
- Fabric. Usage of JS eraser (including recovery function)
- Fabric.js 动态设置字号大小
- Understanding of mongodb
- Chinese science and technology from the Winter Olympics (III): the awakening and evolution of digital people
- Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
- 故事點 vs. 人天
- Advanced usage of C language -- function pointer: callback function; Conversion table
- [development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)
- The most complete analysis of Flink frame window function
- Certik released the defi security report in 2021, disclosing key data of industry development (PDF download link attached)
猜你喜欢

C crystal report printing

What is erdma? Popular science cartoon illustration

In 2021, the global styrene butadiene styrene (SBS) revenue was about $3722.7 million, and it is expected to reach $5679.6 million in 2028

Selenium element positioning method

MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)

PHP linked list creation and traversal

每日学习2

A white hole formed by antineutrons produced by particle accelerators

Penetrate the remote connection database through the Intranet

Mysql5.7 installation super easy tutorial
随机推荐
C crystal report printing
Data Lake (11): Iceberg table data organization and query
Route (II)
Story points vs. human days
一般来讲,如果频繁出现inconsistent tab and space的报错
NLA自然语言分析,让数据分析更智能
Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
Go operation redis
Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'
PHP linked list creation and traversal
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?
[deep learning] simple implementation of neural network forward propagation
Use of freemaker
快解析:轻松实现共享上网
Method of creating linked server for cross server data access
卷积神经网络(入门)
Story point vs. Human Sky
MySQL 45 lecture - learning the actual battle of MySQL in Geek time 45 Lecture Notes - 05 | easy to understand index (Part 2)
NLA natural language analysis makes data analysis more intelligent
The most complete analysis of Flink frame window function