1 Star 0 Fork 0

zouxh/Panorama-Viewer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.html 4.51 KB
一键复制 编辑 原始数据 按行查看 历史
zouxh 提交于 2017-02-15 17:47 . no message
<html>
<head>
<style>
body{
margin: 0;
}
canvas{
width: 100%;
height: 100%
}
</style>
<script src="js\three.js"></script>
<script src="js\OrbitControls.js"></script>
<script src="js\dat.gui.min.js"></script>
</head>
<body>
<script>
THREE.ImageLoader2 = function ( manager ) {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
};
THREE.ImageLoader2.prototype = {
constructor: THREE.ImageLoader2,
load: function ( url, onLoad, onProgress, onError ) {
var _url = url;
url += '.jpg';
var scope = this;
var cached = THREE.Cache.get( url );
if ( cached !== undefined ) {
scope.manager.itemStart( url );
if ( onLoad ) {
setTimeout( function () {
onLoad( cached );
scope.manager.itemEnd( url );
}, 0 );
} else {
scope.manager.itemEnd( url );
}
return cached;
}
var e = document.createElement('img');
e.src = _url + '_2.jpg';
var image = document.createElement( 'img' );
e.addEventListener( 'load', function ( event ) {
console.log('success to load :' + e.src);
if ( onLoad ) onLoad( this );
}, false );
image.addEventListener( 'load', function ( event ) {
THREE.Cache.add( url, this );
if ( onLoad ) onLoad( this );
scope.manager.itemEnd( url );
}, false );
if ( onProgress !== undefined ) {
image.addEventListener( 'progress', function ( event ) {
onProgress( event );
}, false );
}
image.addEventListener( 'error', function ( event ) {
if ( onError ) onError( event );
scope.manager.itemError( url );
}, false );
if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
scope.manager.itemStart( url );
image.src = url;
return image;
},
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
}
};
</script>
<script>
// panoramas background
var panoramaPath = "PanoramaData/r1/ladybug_panoramic_001915";
// setting up the renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// creating a new scene
var scene = new THREE.Scene();
// adding a camera
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set( 0, 0, 100 );
camera.target = new THREE.Vector3(0, 0, 0);
//control
controls = new THREE.OrbitControls( camera );
controls.enablePan = false;
controls.minDistance = 10;
//controls.maxDistance = 80;
// creation of a big sphere geometry
var sphere = new THREE.SphereGeometry(40, 200, 200); //widthSegments >= 8 , heightSegments >= 4
sphere.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));
// creation of the sphere material
var sphereMaterial = new THREE.MeshBasicMaterial();
var texture = new THREE.Texture();
var loader = new THREE.ImageLoader2();
loader.load(panoramaPath,function(image){
texture.image = image;
texture.needsUpdate = true;
},false);
sphereMaterial.map = texture;
// geometry + material = mesh (actual object)
var sphereMesh = new THREE.Mesh(sphere, sphereMaterial);
scene.add(sphereMesh);
var axisHelper = new THREE.AxisHelper( 50 );
scene.add( axisHelper );
window.addEventListener( 'resize', onWindowResize, false );
render();
function render(){
requestAnimationFrame(render);
// moving the camera according to current latitude (vertical movement) and longitude (horizontal movement)
camera.lookAt(camera.target);
controls.update();
// calling again render function
renderer.render(scene, camera);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zouxh/Panorama-Viewer.git
git@gitee.com:zouxh/Panorama-Viewer.git
zouxh
Panorama-Viewer
Panorama-Viewer
master

搜索帮助