当前位置:网站首页>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;
边栏推荐
- 每日学习3
- Advanced usage of C language -- function pointer: callback function; Conversion table
- PyQt5_QScrollArea内容保存成图片
- 篇9:XShell免费版安装
- A white hole formed by antineutrons produced by particle accelerators
- < 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
- 一般来讲,如果频繁出现inconsistent tab and space的报错
- Packet capturing tool Fiddler learning
- 4、数组指针和指针数组
- 每天坚持20分钟go的基础二
猜你喜欢

PHP linked list creation and traversal

每日学习2

kaggle如何使用utility script

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

Daily learning 3

MySQL 45 lecture - learning the actual battle of MySQL in Geek time 45 Lecture Notes - 05 | easy to understand index (Part 2)

没有从远程服务器‘‘映射到本地用户‘(null)/sa‘的远程用户‘sa‘及服务主密码解密错误的解决办法

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%

How kaggle uses utility script

Do you know that there is an upper limit on the size of Oracle data files?
随机推荐
测试框架TestNG的使用(二):testNG xml的使用
NLA自然语言分析,让数据分析更智能
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%
What is erdma? Popular science cartoon illustration
MQ tutorial | exchange (switch)
Fabric. JS free drawing ellipse
Fabric.js 橡皮擦的用法(包含恢复功能)
Quick analysis: easy to share the Internet
NLA natural language analysis makes data analysis more intelligent
PHP linked list creation and traversal
Daily learning 3
篇9:XShell免费版安装
3、函数指针和指针函数
HMS core machine learning service helps zaful users to shop conveniently
自定义事件,全局事件总线,消息订阅与发布,$nextTick
Default slot, named slot, scope slot
How kaggle uses utility script
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
< 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
Development and design of animation surrounding mall sales website based on php+mysql