当前位置:网站首页>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;
边栏推荐
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- kaggle如何使用utility script
- Convolutional neural network (Introduction)
- A white hole formed by antineutrons produced by particle accelerators
- [development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)
- Fabric.js 元素被选中时保持原有层级
- Fabric. JS free drawing ellipse
- 无主灯设计:如何让智能照明更加「智能」?
- Story point vs. Human Sky
- Daily learning 2
猜你喜欢

自定义事件,全局事件总线,消息订阅与发布,$nextTick
![[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)](/img/de/7d70f513577e93f1bde1969935a29e.jpg)
[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)

Custom events, global event bus, message subscription and publishing, $nexttick

PHP linked list creation and traversal

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

【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试

Stm32-dac Experiment & high frequency DAC output test

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

< 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

Pycharm连接远程服务器
随机推荐
uniapp自动化测试学习
MQ tutorial | exchange (switch)
[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)
Chapter 9: xshell free version installation
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?
Codeforces Round #803 (Div. 2)(A~D)
当贝投影4K激光投影X3 Pro获得一致好评:万元投影仪首选
go操作redis
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
Generally speaking, if the error of inconsistent tab and space occurs frequently
Fabric. JS free draw circle
Default slot, named slot, scope slot
[deep learning] simple implementation of neural network forward propagation
Data Lake (11): Iceberg table data organization and query
Fabric.js 上划线、中划线(删除线)、下划线
Fabric.js 缩放画布
你知道Oracle的数据文件大小有上限么?
NLA自然语言分析实现数据分析零门槛
freemarker的使用
Basic knowledge of QT original code