How to add a 2D flat image to panorama 360

hello,

I am a Three.js beginner.

I created a 360° panorama with equirectangular images inspired by the example of THREE.js three.js examples

I would like to add a fixed flat 2D image in the center of the scene like on the screenshot.

I tried to use the Sprite but without success.

can someone help me please

Please demonstrate with a live example what you have tried so far.

Hello Mugen87,

Thank you for your answer.

Here is what I want to do:

At the launch of the 360° panorama I want to display a 2D flat image with a width and height of 80% of the screen for 10 seconds and it will disappear.

This 2D flat image will contain information about the panorama such as :
-information about the author of the panorama
-the location
etc…

So I tried to use the Sprtite() but nothing is displayed on the panorama and I confess I can’t figure out how to do it, maybe I’m looking for the wrong thing.

Here is an example of my code:

Thanks in advance for your help

let point = new THREE.Vector3(2,0,0);

thank you for your reply.

I just put 2 instead of 0 in the coordinates of the point and the sprite is displayed well thank you very much :slight_smile:

How to set a size (width and height) for this sprite, because I want it to display in 1920px X 1080px

sprite.scale.set(1920, 1080, 1);

hello

thank you for your reply,

I just tested the panorama with your line of code and indeed it zooms the sprite well but the problem is that this sprite moves when the panorama moves or I want the sprite to remain static for 10 seconds after it disappears.

do you have any clue how to do that?

thanks a lot for your help

Because example rotating camera. This code rorating mesh.

<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - equirectangular panorama</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<link type="text/css" rel="stylesheet" href="main.css">
	</head>
	<body>

		<div id="container"></div>


		<!-- Import maps polyfill -->
		<!-- Remove this when import maps will be widely supported -->
		<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>

		<script src="//cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script>

		<script>

			let camera, scene, renderer;

			let isUserInteracting = false,
				onPointerDownMouseX = 0, onPointerDownMouseY = 0,
				lon = 0, onPointerDownLon = 0,
				lat = 0, onPointerDownLat = 0,
				phi = 0, theta = 0;

			init();
			animate();
var mesh;
			function init() {

				const container = document.getElementById( 'container' );

				camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );

				scene = new THREE.Scene();

				const geometry = new THREE.SphereGeometry( 500, 60, 40 );
				// invert the geometry on the x-axis so that all of the faces point inward
				geometry.scale( - 1, 1, 1 );

				const texture = new THREE.TextureLoader().load( 'https://raw.githubusercontent.com/mrdoob/three.js/master/examples/textures/2294472375_24a3b8ef46_o.jpg' );
				const material = new THREE.MeshBasicMaterial( { map: texture } );

				mesh = new THREE.Mesh( geometry, material );

				scene.add( mesh );
        
        let point = new THREE.Vector3(2,0,-2)
        let spriteMap = new THREE.TextureLoader().load('https://i.picsum.photos/id/1000/1920/1080.jpg?hmac=9oFbSamit9P-mTER0QbZy1HIdkMB94bY70uOERfB97A')
        let spriteMaterial = new THREE.SpriteMaterial({
            map: spriteMap
        })
        let sprite = new THREE.Sprite(spriteMaterial)
        sprite.name = point.name
        sprite.position.copy(point.clone()) 
        scene.add(sprite)

				renderer = new THREE.WebGLRenderer();
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				container.appendChild( renderer.domElement );

				container.style.touchAction = 'none';
				container.addEventListener( 'pointerdown', onPointerDown );

				document.addEventListener( 'wheel', onDocumentMouseWheel );

				//

				document.addEventListener( 'dragover', function ( event ) {

					event.preventDefault();
					event.dataTransfer.dropEffect = 'copy';

				} );

				document.addEventListener( 'dragenter', function () {

					document.body.style.opacity = 0.5;

				} );

				document.addEventListener( 'dragleave', function () {

					document.body.style.opacity = 1;

				} );

				document.addEventListener( 'drop', function ( event ) {

					event.preventDefault();

					const reader = new FileReader();
					reader.addEventListener( 'load', function ( event ) {

						material.map.image.src = event.target.result;
						material.map.needsUpdate = true;

					} );
					reader.readAsDataURL( event.dataTransfer.files[ 0 ] );

					document.body.style.opacity = 1;

				} );

				//

				window.addEventListener( 'resize', onWindowResize );

			}

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

			}

			function onPointerDown( event ) {

				if ( event.isPrimary === false ) return;

				isUserInteracting = true;

				onPointerDownMouseX = event.clientX;
				onPointerDownMouseY = event.clientY;

				onPointerDownLon = lon;
				onPointerDownLat = lat;

				document.addEventListener( 'pointermove', onPointerMove );
				document.addEventListener( 'pointerup', onPointerUp );

			}

			function onPointerMove( event ) {

				if ( event.isPrimary === false ) return;

				lon = ( onPointerDownMouseX - event.clientX ) * 0.1 + onPointerDownLon;
				lat = ( event.clientY - onPointerDownMouseY ) * 0.1 + onPointerDownLat;

			}

			function onPointerUp() {

				if ( event.isPrimary === false ) return;

				isUserInteracting = false;

				document.removeEventListener( 'pointermove', onPointerMove );
				document.removeEventListener( 'pointerup', onPointerUp );

			}

			function onDocumentMouseWheel( event ) {

				const fov = camera.fov + event.deltaY * 0.05;

				camera.fov = THREE.MathUtils.clamp( fov, 10, 75 );

				camera.updateProjectionMatrix();

			}

			function animate() {

				requestAnimationFrame( animate );
				update();

			}

			function update() {

				if ( isUserInteracting === false ) {

					lon += 0.1;

				}

				lat = Math.max( - 85, Math.min( 85, lat ) );
				phi = THREE.MathUtils.degToRad( 90 - lat );
				theta = THREE.MathUtils.degToRad( lon );

				const x = 500 * Math.sin( phi ) * Math.cos( theta );
				const y = 500 * Math.cos( phi );
				const z = 500 * Math.sin( phi ) * Math.sin( theta );

				mesh.lookAt( x, y, z );

				renderer.render( scene, camera );

			}

		</script>
	</body>
</html>

Hello,

thank you for your reply,

I tested it and il works :wink:

Thank you very match for your help :pray:

1 Like