当前位置:网站首页>threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
threejs的控制器 立方體空間 基本控制器+慣性控制+飛行控制
2022-07-02 14:30: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;
边栏推荐
- Fabric. JS free drawing ellipse
- Federated Search: all requirements in search
- 《可供方案开发》口算训练机/数学宝/儿童口算宝/智能数学宝 LCD液晶显示驱动IC-VK1622(LQFP64封装),原厂技术支持
- 故事點 vs. 人天
- Golang 快速生成数据库表的 model 和 queryset
- Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?
- The evolution process of the correct implementation principle of redis distributed lock and the summary of redison's actual combat
- 全屋Wi-Fi:一个谁也解决不好的痛点?
- 默认插槽,具名插槽,作用域插槽
- Yyds dry goods inventory software encryption lock function
猜你喜欢

In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028

PHP linked list creation and traversal

Chinese science and technology from the Winter Olympics (III): the awakening and evolution of digital people

Pycharm连接远程服务器

Stm32-dac Experiment & high frequency DAC output test

Use of swagger

Analysis of CPU surge in production environment service

抓包工具fiddler学习
![[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)](/img/08/9f25515e600a3174340b2589c81b0e.jpg)
[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)

Codeforces Round #803 (Div. 2)(A~D)
随机推荐
Fabric. JS zoom canvas
Qt新建项目
自定义事件,全局事件总线,消息订阅与发布,$nextTick
OpenHarmony笔记-----------(四)
YOLOv3&YOLOv5输出结果说明
Fabric.js 橡皮擦的用法(包含恢复功能)
[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
docker mysql
Solving the longest subsequence with linear DP -- three questions
默认插槽,具名插槽,作用域插槽
QT new project
Pychart connects to the remote server
C crystal report printing
全屋Wi-Fi:一个谁也解决不好的痛点?
Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?
uni-app中使用computed解决了tab切换中data()值显示的异常
go操作redis
途家木鸟美团夏日折扣对垒,门槛低就一定香吗?
P1908 逆序对
HMS core machine learning service helps zaful users to shop conveniently