当前位置:网站首页>Threejs controller cube space basic controller + inertia control + flight control
Threejs controller cube space basic controller + inertia control + flight control
2022-07-02 14:30:00 【Under the bridge in front of the gate】
threejs The controller Cube space Basic controller + Inertia control + Flight control
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";
// more Inertial OrbitControls The upgrade of is basically
import {
TrackballControls} from "three/examples/jsm/controls/TrackballControls";
// Flight control Mouse operation Perspective Forward and direction
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(){
// Set up
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(){
// The ambient light
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(){
// establish rander -- The camera --- scene ---- 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()
}
// Add lights
this.addLight()
// Add controller
this.control=this.getControl()
// Perform animation
this.animation()
}
animation(){
requestAnimationFrame(this.animation.bind(this))
this.renderer.render(this.scene,this.camera)
this.control.update(clock.getDelta())
}
}
export default Index;
边栏推荐
- Data consistency between redis and database
- c# 水晶报表打印
- TeamTalk源码分析之win-client
- Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
- 2022家用投影仪首选!当贝F5强悍音画效果带来极致视听体验
- How kaggle uses utility script
- Multi rotor aircraft control using PID and LQR controllers
- Golang quickly generates model and queryset of database tables
- 没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法
- OpenHarmony笔记-----------(四)
猜你喜欢

<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持

Launcher startup process

What is erdma? Popular science cartoon illustration

The conference on the growth of all things was held in Hangzhou, and dangbei was selected into the top 100 list of future unicorns in China in 2022

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

途家木鸟美团夏日折扣对垒,门槛低就一定香吗?

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

There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '

php链表创建和遍历
![[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)](/img/e0/e9cb42f241a60995d4598ba6a1a2fe.jpg)
[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)
随机推荐
Codeforces Round #803 (Div. 2)(A~D)
P1042 [noip2003 popularization group] Table Tennis
Error: eacces: permission denied, access to "/usr/lib/node_modules"
Understanding of mongodb
Quick analysis: easy to share the Internet
The evolution process of the correct implementation principle of redis distributed lock and the summary of redison's actual combat
Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
Fabric. JS zoom canvas
线性dp求解 最长子序列 —— 小题三则
MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
Fabric.js 橡皮擦的用法(包含恢复功能)
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
Teamtalk source code analysis win client
Using computed in uni app solves the abnormal display of data () value in tab switching
Mysql5.7 installation super easy tutorial
[deep learning] simple implementation of neural network forward propagation
3、函数指针和指针函数
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
Default slot, named slot, scope slot
Quarkus学习四 - 项目开发到部署