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
Table of contents Conclusion first question Solut...
1. Test environment name Version centos 7.6 docke...
Table of contents Scenario: The server database n...
Including the use of check boxes and radio buttons...
/******************** * Virtual File System VFS *...
Table of contents 1. What is Javascript? 2. What ...
1.17.9 More delicious, really Nginx download addr...
1. Setting case sensitivity of fields in the tabl...
1. Data Deduplication In daily work, there may be...
1. Backup source list The default source of Ubunt...
Table of contents Preface think Library directory...
Table of contents Separation effect Command line ...
Canvas is a new tag in HTML5. You can use js to o...
Error screenshot Can't find where the excepti...
Table of contents How to represent the current ti...