当前位置:网站首页>threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
2022-07-02 14:30:00 【門前大橋下.】
threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
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";
//更加 有慣性的OrbitControls 的昇級基本
import {
TrackballControls} from "three/examples/jsm/controls/TrackballControls";
//飛行控制 鼠標操作視角 的前進和方向
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(){
//設置
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(){
//環境光
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(){
//創建rander --相機 ---場景----動畫
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()
}
//添加燈光
this.addLight()
//添加控制器
this.control=this.getControl()
//執行動畫
this.animation()
}
animation(){
requestAnimationFrame(this.animation.bind(this))
this.renderer.render(this.scene,this.camera)
this.control.update(clock.getDelta())
}
}
export default Index;
边栏推荐
- Use of UIC in QT
- Adhere to the foundation of 20 minutes go every day II
- Story point vs. Human Sky
- HMS core machine learning service helps zaful users to shop conveniently
- < schematic diagram of oral arithmetic exercise machine program development> oral arithmetic exercise machine / oral arithmetic treasure / children's math treasure / children's calculator LCD LCD driv
- Packet capturing tool Fiddler learning
- Multi rotor aircraft control using PID and LQR controllers
- mongodb的认识
- PyQt5_QScrollArea内容保存成图片
- Federated Search: all requirements in search
猜你喜欢

每日学习3

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

Design and implementation of car query system based on php+mysql

QT new project

Pychart connects to the remote server

关于Flink框架窗口(window)函数最全解析

Pycharm连接远程服务器

<口算練習機 方案開發原理圖>口算練習機/口算寶/兒童數學寶/兒童計算器 LCD液晶顯示驅動IC-VK1621B,提供技術支持

抓包工具fiddler学习

< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621
随机推荐
OpenHarmony笔记-----------(四)
Available solution development oral arithmetic training machine / math treasure / children's oral arithmetic treasure / intelligent math treasure LCD LCD driver ic-vk1622 (lqfp64 package), original te
Do you know that there is an upper limit on the size of Oracle data files?
测试框架TestNG的使用(二):testNG xml的使用
Codeforces Round #803 (Div. 2)(A~D)
<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
P1908 reverse sequence pair
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
由粒子加速器产生的反中子形成的白洞
C语言高级用法--函数指针:回调函数;转换表
软件测试的方法
MQ教程 | Exchange(交换机)
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
Openharmony notes --------- (4)
How many knowledge points can a callable interface have?
Fabric.js 元素被选中时保持原有层级
Daily learning 3
Analysis of CPU surge in production environment service
STM32-DAC实验&高频DAC输出测试