photo-sphere-viewer.js使用时图片拉伸的问题

photo-sphere-viewer使用了three.js,其代码中下面这句话中,SphereGeometry是用来在三维空间内创建一个球体对象,图片会按球体拉伸。

		var geometry = new THREE.SphereGeometry(200, rings, segments);
		var material = new THREE.MeshBasicMaterial({map: texture, overdraw: true});
		var mesh = new THREE.Mesh(geometry, material);
		mesh.scale.x = -1;
		scene.add(mesh);

在使用photo-sphere-viewer时,在用这个插件显示全景图的时候,由于图片太长,天空部分和地面部分图片拉伸严重变形。在前端处理用canvas将图片上部和下部按比例补上了一部分灰色,显示全景图的时候天空和地面部分就补上了一部分。

HTML
<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="utf-8" />
		<title>Photo Sphere Viewer</title>
		<meta name="viewport" content="initial-scale=1.0" />
		<link rel="stylesheet" href="./example1.css" />
		<script src="../three.min.js"></script>
		<script src="../photo-sphere-viewer.min.js"></script>
		<script src="ex.js"></script>
	</head>

	<body>
		<div id="content">		

			<div id="container"></div>
			<p style="text-align: center;">
				<a href="#" id="go">show</a>
			</p>

			<div id="your-pano"></div>

			<form method="get" action="example1.html">
				<p style="text-align: center;">
					<input type="file" name="pano" id="pano" />
				</p>
			</form>
		</div>
		<div>
		<canvas id="myImage" style="display:none" ></canvas>
		<img id="myimg" style="display:none"/>
		</div>
	</body>

</html>

JS
window.onload = function() {
	document.getElementById('pano').addEventListener('change', upload, false);
};


function upload() {
	var file = document.getElementById('pano').files[0];
	var canvas=document.getElementById('myImage');
	var image=document.getElementById('myimg');
	var ctx=canvas.getContext('2d');
	
	var width=canvas.width;
	var height=canvas.heigth;
	var reader = new FileReader();
	
	var result;
	
	reader.readAsDataURL(file);
	
   
   
	reader.onload = function() {
		var div = document.getElementById('your-pano');
		var PSV;
	    image.src=reader.result;
		width=image.naturalWidth;
		height=image.naturalHeight;
		 
		 if(width/height>2)
		 {
			 console.log('special condition');
			 canvas.width=width;
			 canvas.height=height+width/4;

			 ctx.fillStyle='rgb(200,200,200)';
			 ctx.fillRect(0,0,canvas.width,canvas.height);

			 ctx.drawImage(image,0,width/8);
			 result=canvas.toDataURL("image/jpeg");
			 
			 PSV = new PhotoSphereViewer({
			panorama: result,

			container: div,

			time_anim: false,

			navbar: true,

			size: {
				width: '100%',
				height: '500px'
			},

			usexmpdata: false
		});
			 
		 }
		 else
		 {
            console.log('normal condition');
			result=reader.result;
			
			PSV = new PhotoSphereViewer({
			panorama: result,

			container: div,

			time_anim: false,

			navbar: true,
			
			size: {
				width: '100%',
				height: '500px'
			},

			usexmpdata: false
		});
		 }
    

		
	};

}





评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值