当前位置:网站首页>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;
边栏推荐
- P1908 逆序对
- NLA natural language analysis makes data analysis more intelligent
- Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
- Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
- 篇9:XShell免费版安装
- 【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
- What is erdma? Popular science cartoon illustration
- Fabric.js 元素被选中时保持原有层级
- Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?
- Route (II)
猜你喜欢

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

Mysql5.7 installation super easy tutorial

全屋Wi-Fi:一个谁也解决不好的痛点?

Quick analysis: easy to share the Internet

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

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

uniapp自动化测试学习

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

PyQt5_QScrollArea内容保存成图片

由粒子加速器产生的反中子形成的白洞
随机推荐
P1042 [NOIP2003 普及组] 乒乓球
途家木鸟美团夏日折扣对垒,门槛低就一定香吗?
Fabric.js 自由绘制圆形
MySQL 45 lecture - learning the actual battle of MySQL in Geek time 45 Lecture Notes - 05 | easy to understand index (Part 2)
Fabric. Keep the original level when JS element is selected
你知道Oracle的数据文件大小有上限么?
Slashgear shares 2021 life changing technology products, which are somewhat unexpected
<口算练习机 方案开发原理图>口算练习机/口算宝/儿童数学宝/儿童计算器 LCD液晶显示驱动IC-VK1621B,提供技术支持
MQ tutorial | exchange (switch)
Thymeleaf dependency
Multi rotor aircraft control using PID and LQR controllers
Essential elements of science fiction 3D scenes - City
篇9:XShell免费版安装
Penetrate the remote connection database through the Intranet
Development and design of animation surrounding mall sales website based on php+mysql
C语言高级用法--函数指针:回调函数;转换表
Tujia muniao meituan has a discount match in summer. Will it be fragrant if the threshold is low?
The evolution process of the correct implementation principle of redis distributed lock and the summary of redison's actual combat
由粒子加速器产生的反中子形成的白洞
卷积神经网络(入门)