当前位置:网站首页>threejs的控制器 立方体空间 基本控制器+惯性控制+飞行控制
threejs的控制器 立方体空间 基本控制器+惯性控制+飞行控制
2022-07-02 11:21: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;
边栏推荐
- Essential elements of science fiction 3D scenes - City
- NLA自然语言分析实现数据分析零门槛
- 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
- Slashgear shares 2021 life changing technology products, which are somewhat unexpected
- Qt新建项目
- 数据湖(十一):Iceberg表数据组织与查询
- TeamTalk源码分析之win-client
- A white hole formed by antineutrons produced by particle accelerators
- 万物生长大会在杭召开,当贝入选2022中国未来独角兽TOP100榜单
- docker mysql
猜你喜欢

A white hole formed by antineutrons produced by particle accelerators

你知道Oracle的数据文件大小有上限么?

kaggle如何使用utility script

How kaggle uses utility script

Fabric. Usage of JS eraser (including recovery function)

Federated Search: all requirements in search

Fabric.js 橡皮擦的用法(包含恢复功能)

默认插槽,具名插槽,作用域插槽

The use of TestNG, the testing framework (II): the use of TestNG XML
![[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)
随机推荐
《可供方案开发》口算训练机/数学宝/儿童口算宝/智能数学宝 LCD液晶显示驱动IC-VK1622(LQFP64封装),原厂技术支持
Openharmony notes --------- (4)
篇9:XShell免费版安装
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
Advanced usage of C language -- function pointer: callback function; Conversion table
Fabric.js 缩放画布
2022 home projector preferred! Dangbei F5 brings the ultimate audio-visual experience with its powerful audio-visual effect
C语言高级用法--函数指针:回调函数;转换表
YOLOv3&YOLOv5输出结果说明
Golang quickly generates model and queryset of database tables
跨服务器数据访问的创建链接服务器方法
无主灯设计:如何让智能照明更加「智能」?
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
字符串匹配问题
Custom events, global event bus, message subscription and publishing, $nexttick
freemarker的使用
Fabric. JS upper dash, middle dash (strikethrough), underline
Pycharm连接远程服务器
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)