当前位置:网站首页>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;
边栏推荐
- 途家木鸟美团夏日折扣对垒,门槛低就一定香吗?
- [development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
- docker mysql
- uniapp自动化测试学习
- Methods of software testing
- Design and implementation of car query system based on php+mysql
- QT new project
- Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
- How many knowledge points can a callable interface have?
- Fabric.js 手动加粗文本iText
猜你喜欢

2022 home projector preferred! Dangbei F5 brings the ultimate audio-visual experience with its powerful audio-visual effect

跨服务器数据访问的创建链接服务器方法

QT new project

kaggle如何使用utility script

腾讯云 TStor 统一存储通过信通院首批文件存储基础能力评测

PyQt5_ Qscrollarea content is saved as a picture
![[deep learning] simple implementation of neural network forward propagation](/img/a6/9b4896c62e9b77f9d528c3c9efc58f.jpg)
[deep learning] simple implementation of neural network forward propagation

Development and design of animation surrounding mall sales website based on php+mysql

TeamTalk源码分析之win-client

没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
随机推荐
PyQt5_QScrollArea内容保存成图片
Codeforces Round #803 (Div. 2)(A~D)
联合搜索:搜索中的所有需求
Basic knowledge of QT original code
Advanced usage of C language -- function pointer: callback function; Conversion table
[deep learning] simple implementation of neural network forward propagation
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
Quarkus learning IV - project development to deployment
Data consistency between redis and database
Fabric. JS dynamically set font size
Understanding of mongodb
The global special paper revenue in 2021 was about $27 million, and it is expected to reach $35 million in 2028. From 2022 to 2028, the CAGR was 3.8%
Whole house Wi Fi: a pain point that no one can solve?
Fabric. Keep the original level when JS element is selected
Using computed in uni app solves the abnormal display of data () value in tab switching
你知道Oracle的数据文件大小有上限么?
mongodb的认识
What is erdma? Popular science cartoon illustration
[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
Launcher startup process