Recently, I'm learning to use 1. Build the framework and install the required plug-insnpx create-react-app parano // Create a React project npm install -S typescript // Install typescript, this is a type-assisted plugin and has little to do with the Panorama project npm install -S @types/three // Install the three.js plugin supported by typescript 2. Create Pano ComponentThe Pano component is used to load 720 panoramas. import React from 'react' import * as THREE from 'three' // Import the Three.js plugin import banner from './img/playground.jpg' // Import the panoramic image // props type declaration interface interface MyProps { } //state type declaration interface interface MyState { } class Pano extends React.Component<MyProps, MyState> { renderer: any = new THREE.WebGLRenderer() // Create a renderer scene: any = new THREE.Scene() // Create a scene camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) // Create a camera geometry = new THREE.SphereBufferGeometry(100, 60, 40) // Create a spherical container for pasting panoramas material: any // Texture material mesh: any constructor(props: any) { super (props) this.state = {} } componentDidMount() { this.geometry.scale(-1, 1, 1) let texture = new THREE.TextureLoader().load(banner) this.material = new THREE.MeshBasicMaterial({map: texture}) this.mesh = new THREE.Mesh(this.geometry, this.material) this.renderer.setSize(window.innerWidth, window.innerHeight) document.body.appendChild(this.renderer.domElement) this.scene.add(this.mesh) this.camera.position.z = 0 window.addEventListener('resize', this.onWindowResize, false) this.animate() } // Change the display size of the panorama when the window size changes onWindowResize = () => { this.camera.aspect = window.innerWidth / window.innerHeight this.camera.updateProjectionMatrix() this.renderer.setSize(window.innerWidth, window.innerHeight) } // Render frame by frame animate = () => { requestAnimationFrame(this.animate) this.mesh.rotation.y += 0.001 this.renderer.render(this.scene, this.camera) } render () { return ( <div></div> ) } } export default Pano 3. Add the Pano component to the App componentimport React from 'react'; import './App.css'; import Pano from './pano'; function App() { return ( <div className="App"> <Pano /> </div> ); } export default App; At this point, execute This is the end of this article about the detailed process of creating a VR panoramic project using React and Threejs. For more relevant content about creating VR panoramic views with React and Threejs, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Mysql multi-condition query statement with And keyword
>>: Basic usage tutorial of IPTABLES firewall in LINUX
1. Introduction When filtering unknown or partial...
How to check the status of Linux firewall 1. Basi...
What is the role of http in node The responsibili...
background In order to support Docker containeriz...
Today I would like to share with you the CSS3 tra...
There are some differences between filter and bac...
This article shares the MySQL installation and co...
MySQL server has gone away issue in PHP 1. Backgr...
Preface In the springboot configuration file, the...
Subquery in MySql database: Subquery: nesting ano...
This article mainly introduces the sample code of...
HTML comment box with emoticons. The emoticons ar...
Table of contents 1. Introduction 2. The differen...
This article is mainly to take you to quickly und...
Use CSS to create a 3D photo wall. The specific c...