当前位置:网站首页>threejs的控制器 立方体空间 基本控制器+惯性控制+飞行控制
threejs的控制器 立方体空间 基本控制器+惯性控制+飞行控制
2022-07-02 11:21: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;
边栏推荐
- Word frequency statistics & sorting
- Analysis of CPU surge in production environment service
- What is erdma? Popular science cartoon illustration
- <口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
- MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
- Fabric. Usage of JS eraser (including recovery function)
- Advanced usage of C language -- function pointer: callback function; Conversion table
- 线性dp求解 最长子序列 —— 小题三则
- Codeforces Round #803 (Div. 2)(A~D)
- Convolutional neural network (Introduction)
猜你喜欢

What is erdma? Popular science cartoon illustration

Fabric.js 上划线、中划线(删除线)、下划线

万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单

《可供方案开发》口算训练机/数学宝/儿童口算宝/智能数学宝 LCD液晶显示驱动IC-VK1622(LQFP64封装),原厂技术支持

Certik released the defi security report in 2021, disclosing key data of industry development (PDF download link attached)

每日学习2

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

Daily learning 3

Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'

Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
随机推荐
Use of swagger
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
PyQt5_QScrollArea内容保存成图片
Fabric.js 橡皮擦的用法(包含恢复功能)
go操作redis
Use of UIC in QT
Quarkus学习四 - 项目开发到部署
Use of freemaker
跨服务器数据访问的创建链接服务器方法
一般来讲,如果频繁出现inconsistent tab and space的报错
Generally speaking, if the error of inconsistent tab and space occurs frequently
软件测试的方法
字符串匹配问题
The most complete analysis of Flink frame window function
[to be continued] [UE4 notes] l5ue4 model import
关于Flink框架窗口(window)函数最全解析
Whole house Wi Fi: a pain point that no one can solve?
给Android程序员的一些面试建议「建议收藏」
Multi rotor aircraft control using PID and LQR controllers
Fabric. JS upper dash, middle dash (strikethrough), underline