Parcourir la source

add:720全景例子

刘忠健 il y a 1 an
Parent
commit
c86721a0cc

+ 28 - 0
720vr/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>720</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>com.aptana.ide.core.unifiedBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.aptana.projects.webnature</nature>
+	</natures>
+	<filteredResources>
+		<filter>
+			<id>1525745190410</id>
+			<name></name>
+			<type>26</type>
+			<matcher>
+				<id>org.eclipse.ui.ide.multiFilter</id>
+				<arguments>1.0-name-matches-false-false-node_modules</arguments>
+			</matcher>
+		</filter>
+	</filteredResources>
+</projectDescription>

+ 37 - 0
720vr/README.md

@@ -0,0 +1,37 @@
+# 720度全景
+
+#### 项目介绍
+720度全景
+
+#### 软件架构
+软件架构说明
+
+
+#### 安装教程
+
+1. xxxx
+2. xxxx
+3. xxxx
+
+#### 使用说明
+
+1. xxxx
+2. xxxx
+3. xxxx
+
+#### 参与贡献
+
+1. Fork 本项目
+2. 新建 Feat_xxx 分支
+3. 提交代码
+4. 新建 Pull Request
+
+
+#### 码云特技
+
+1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
+2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com)
+3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目
+4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目
+5. 码云官方提供的使用手册 [http://git.mydoc.io/](http://git.mydoc.io/)
+6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

BIN
720vr/images/btn1.png


BIN
720vr/images/btn2.png


BIN
720vr/images/controlIcon.png


BIN
720vr/images/controlIconae.png


BIN
720vr/images/panorama.back.jpg


BIN
720vr/images/panorama.bottom.jpg


BIN
720vr/images/panorama.front.jpg


BIN
720vr/images/panorama.left.jpg


BIN
720vr/images/panorama.right.jpg


BIN
720vr/images/panorama.top.jpg


BIN
720vr/images/pic.back.jpg


BIN
720vr/images/pic.bottom.jpg


BIN
720vr/images/pic.front.jpg


BIN
720vr/images/pic.left.jpg


BIN
720vr/images/pic.right.jpg


BIN
720vr/images/pic.top.jpg


+ 344 - 0
720vr/index.html

@@ -0,0 +1,344 @@
+<!DOCTYPE html>
+
+<head>
+    <title>3D全景之</title>
+    <meta charset="utf-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+    <meta id="jdouview" name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
+    <meta name="format-detection" content="telephone=no">
+    <style>
+        body {
+            background-color: #000000;
+            margin: 0;
+            cursor: move;
+            overflow: hidden;
+        }
+
+        .bg_section {
+            width: 1026px;
+            height: 1026px;
+            background-size: cover;
+            position: absolute;
+        }
+
+        .bg_section .bg {
+            position: absolute;
+            width: 1026px;
+            height: 1026px;
+        }
+
+        .btn1 {
+            position: absolute;
+            width: 74px;
+            height: 96px;
+            top: 20%;
+            left: 40%;
+            -webkit-transform: perspective(600px);
+            background: url("images/btn1.png");
+            background-size: 100% 100%;
+        }
+
+        .btn2 {
+            position: absolute;
+            width: 71px;
+            height: 91px;
+            top: 30%;
+            left: 50%;
+            -webkit-transform: perspective(600px);
+            background: url("images/btn2.png");
+            background-size: 100% 100%;
+        }
+
+        .controlBtn {
+            width: 60px;
+            height: 60px;
+            position: fixed;
+            z-index: 99999;
+            left: 8%;
+            top: 5%;
+        }
+
+        .controlIcon {
+            background: url("images/controlIcon.png");
+            background-size: 100% 100%;
+        }
+
+        .controlIconae {
+            background: url("images/controlIconae.png");
+            background-size: 100% 100%;
+        }
+
+        @-webkit-keyframes bounceant1 {
+            0% {
+                -webkit-transform: translateY(0)
+            }
+
+            50% {
+                -webkit-transform: translateY(-12px)
+            }
+
+            100% {
+                -webkit-transform: translateY(0px)
+            }
+        }
+
+        @keyframes bounceant1 {
+            0% {
+                transform: translateY(0)
+            }
+
+            50% {
+                transform: translateY(-12px)
+            }
+
+            100% {
+                transform: translateY(0px)
+            }
+        }
+
+        .bounceant1 {
+            -webkit-animation: bounceant1 3s infinite;
+            animation: bounceant1 3s infinite
+        }
+    </style>
+</head>
+
+<body>
+
+
+    <!-- <div id="controlBtn" class="controlBtn controlIconae"></div>  -->
+    <!-- 陀螺仪开启按钮 -->
+    <div id="pano">
+        <!-- 正方体的六个面 -->
+        <div id="bg_section_0" class="bg_section bg_section_4 scale_test">
+            <img class="bg" src="images/pic.right.jpg">
+            <!-- <div class="btn1 bounceant1"></div>  -->
+            <!-- 可点击按钮1 -->
+        </div>
+        <div id="bg_section_1" class="bg_section bg_section_5 scale_test">
+            <img class="bg" src="images/pic.left.jpg">
+        </div>
+        <div id="bg_section_2" class="bg_section bg_section_2 scale_test">
+            <img class="bg" src="images/pic.top.jpg">
+        </div>
+        <div id="bg_section_3" class="bg_section bg_section_3 scale_test">
+            <img class="bg" src="images/pic.bottom.jpg">
+        </div>
+        <div id="bg_section_4" class="bg_section bg_section_1 scale_test">
+            <img class="bg" src="images/pic.front.jpg">
+            <!-- <div class="btn2 bounceant1"></div>  -->
+            <!-- 可点击按钮2 -->
+        </div>
+        <div id="bg_section_5" class="bg_section bg_section_0 scale_test">
+            <img class="bg" src="images/pic.back.jpg">
+        </div>
+    </div>
+
+    <script src="js/zepto.min.js"></script>
+    <script src="js/three.min.js"></script>
+    <script src="js/CSS3DRenderer.min.js"></script>
+    <script src="js/DeviceOrientationControls.js"></script>
+    <script>
+
+        var camera, scene, renderer;
+        var geometry, material, mesh;
+        var target = new THREE.Vector3();
+
+        var lon = 90, lat = 0;
+        var phi = 0, theta = 0;
+
+        var touchX, touchY;
+
+        init();
+        animate();
+
+        function init() {
+            /**
+            * 添加相机
+             * @type {THREE.PerspectiveCamera}
+             */
+            camera = new THREE.PerspectiveCamera(
+                75, // 相机视角的夹角
+                window.innerWidth / window.innerHeight,  // 相机画幅比
+                1, // 最近焦距
+                1000 // 最远焦距
+            );
+
+            /**
+             * 创建场景
+             * @type {THREE.Scene}
+             */
+            scene = new THREE.Scene();
+
+            /**
+             *正方体的6个面的资源及相关(坐标、旋转等)设置
+             */
+            var flipAngle = Math.PI, // 180度
+                rightAngle = flipAngle / 2, // 90度
+                tileWidth = 512;
+            var sides = [{
+                url: "images/panorama.right.jpg",
+                position: [-tileWidth, 0, 0],
+                rotation: [0, rightAngle, 0]
+            }, {
+                url: "images/panorama.left.jpg",
+                position: [tileWidth, 0, 0],
+                rotation: [0, -rightAngle, 0]
+            }, {
+                url: "images/panorama.top.jpg",
+                position: [0, tileWidth, 0],
+                rotation: [rightAngle, 0, Math.PI]
+            }, {
+                url: "images/panorama.bottom.jpg",
+                position: [0, -tileWidth, 0],
+                rotation: [-rightAngle, 0, Math.PI]
+            }, {
+                url: "images/panorama.front.jpg",
+                position: [0, 0, tileWidth],
+                rotation: [0, Math.PI, 0]
+            }, {
+                url: "images/panorama.back.jpg",
+                position: [0, 0, -tileWidth],
+                rotation: [0, 0, 0]
+            }];
+
+            for (var i = 0; i < sides.length; i++) {
+                var side = sides[i];
+                var element = document.getElementById("bg_section_" + i);
+                element.width = 1026;
+                element.height = 1026; // 2 pixels extra to close the gap.
+                // 添加一个渲染器
+                var object = new THREE.CSS3DObject(element);
+                object.position.fromArray(side.position);
+                object.rotation.fromArray(side.rotation);
+                scene.add(object);
+
+            }
+
+            renderer = new THREE.CSS3DRenderer(); // 定义渲染器
+            renderer.setSize(window.innerWidth, window.innerHeight); // 定义尺寸
+            document.body.appendChild(renderer.domElement); // 将场景到加入页面中
+
+            initDevices();
+            initMouseControl();
+
+        }
+
+        // 初始化控制器
+        function initMouseControl() {
+            // mouseControl = new THREE.OrbitControls(camera);
+            document.addEventListener('mousedown', onDocumentMouseDown, false);
+            document.addEventListener('wheel', onDocumentMouseWheel, false);
+            document.addEventListener('touchstart', onDocumentTouchStart, false);
+            document.addEventListener('touchmove', onDocumentTouchMove, false);
+            window.addEventListener('resize', onWindowResize, false);
+
+        }
+
+        var controlsBtn = document.getElementById("controlBtn"); // 控制陀螺仪开关的按钮
+        var isDeviceing = false; // 陀螺仪状态
+        controlsBtn.addEventListener("touchend", controlDevice, true);
+        isDeviceing == true ? $("#controlBtn").addClass("controlIconae") : $("#controlBtn").addClass("controlIcon");
+        // 初始化陀螺仪
+        function initDevices() {
+            deviceControl = new THREE.DeviceOrientationControls(camera);
+        }
+        /* 控制陀螺仪 */
+        function controlDevice(event) {
+            if (isDeviceing == true) {
+                isDeviceing = false;
+                //关闭陀螺仪
+                $("#controlBtn").removeClass("controlIcon").addClass("controlIconae");
+            } else {
+                isDeviceing = true;
+                //开启陀螺仪
+                $("#controlBtn").removeClass("controlIconae").addClass("controlIcon");
+            }
+        }
+
+        /**
+         * 窗体大小改变
+         */
+        function onWindowResize() {
+            camera.aspect = window.innerWidth / window.innerHeight;
+            camera.updateProjectionMatrix();
+            renderer.setSize(window.innerWidth, window.innerHeight);
+        }
+
+        /*
+        相机焦点跟着鼠标或手指的操作移动
+         */
+        function onDocumentMouseDown(event) {
+            event.preventDefault();
+            document.addEventListener('mousemove', onDocumentMouseMove, false);
+            document.addEventListener('mouseup', onDocumentMouseUp, false);
+
+        }
+
+        function onDocumentMouseMove(event) {
+            var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
+            var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
+            lon -= movementX * 0.1;
+            lat += movementY * 0.1;
+        }
+
+        function onDocumentMouseUp(event) {
+            document.removeEventListener('mousemove', onDocumentMouseMove);
+            document.removeEventListener('mouseup', onDocumentMouseUp);
+        }
+
+        /**
+         * 鼠标滚轮改变相机焦距
+         */
+        function onDocumentMouseWheel(event) {
+            camera.fov += event.deltaY * 0.05;
+            camera.updateProjectionMatrix();
+        }
+
+        function onDocumentTouchStart(event) {
+            event.preventDefault();
+            var touch = event.touches[0];
+            touchX = touch.screenX;
+            touchY = touch.screenY;
+
+        }
+
+        function onDocumentTouchMove(event) {
+            event.preventDefault();
+            var touch = event.touches[0];
+            lon -= (touch.screenX - touchX) * 0.1;
+            lat += (touch.screenY - touchY) * 0.1;
+            touchX = touch.screenX;
+            touchY = touch.screenY;
+        }
+
+        /**
+         * 实时渲染函数
+         */
+        function animate() {
+            requestAnimationFrame(animate);
+            // lon = Math.max(-180, Math.min(180, lon));//限制固定角度内旋转
+            // lon += 0.1;//自动旋转
+            lat = Math.max(-85, Math.min(85, lat)); //限制固定角度内旋转
+            phi = THREE.Math.degToRad(85 - lat);
+            theta = THREE.Math.degToRad(lon + 180);
+            target.x = Math.sin(phi) * Math.cos(theta);
+            target.y = Math.cos(phi);
+            target.z = Math.sin(phi) * Math.sin(theta);
+            camera.lookAt(target);
+            camera.updateProjectionMatrix();
+            isDeviceing == false ? initMouseControl() : deviceControl.update();
+            renderer.render(scene, camera);
+        }
+
+        $('.btn1').on('click', function () {
+            alert('第一个按钮被点击了');
+        });
+        $('.btn2').on('click', function () {
+            alert('第二个按钮被点击了');
+        });
+
+    </script>
+</body>
+
+</html>

Fichier diff supprimé car celui-ci est trop grand
+ 57 - 0
720vr/js/CSS3DRenderer.min.js


+ 111 - 0
720vr/js/DeviceOrientationControls.js

@@ -0,0 +1,111 @@
+/**
+ * @author richt / http://richt.me
+ * @author WestLangley / http://github.com/WestLangley
+ *
+ * W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
+ */
+
+THREE.DeviceOrientationControls = function( object ) {
+
+	var scope = this;
+
+	this.object = object;
+	this.object.rotation.reorder( "YXZ" );
+
+	this.enabled = true;
+
+	this.deviceOrientation = {};
+	this.screenOrientation = 0;
+
+	this.alpha = 0;
+	this.alphaOffsetAngle = 0;
+
+
+	var onDeviceOrientationChangeEvent = function( event ) {
+
+		scope.deviceOrientation = event;
+
+	};
+
+	var onScreenOrientationChangeEvent = function() {
+
+		scope.screenOrientation = window.orientation || 0;
+
+	};
+
+	// The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
+
+	var setObjectQuaternion = function() {
+
+		var zee = new THREE.Vector3( 0, 0, 1 );
+
+		var euler = new THREE.Euler();
+
+		var q0 = new THREE.Quaternion();
+
+		var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis
+
+		return function( quaternion, alpha, beta, gamma, orient ) {
+
+			euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
+
+			quaternion.setFromEuler( euler ); // orient the device
+
+			quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
+
+			quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
+
+		}
+
+	}();
+
+	this.connect = function() {
+
+		onScreenOrientationChangeEvent(); // run once on load
+
+		window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
+		window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
+
+		scope.enabled = true;
+
+	};
+
+	this.disconnect = function() {
+
+		window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );
+		window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );
+
+		scope.enabled = false;
+
+	};
+
+	this.update = function() {
+
+		if ( scope.enabled === false ) return;
+
+		var alpha = scope.deviceOrientation.alpha ? THREE.Math.degToRad( scope.deviceOrientation.alpha ) + this.alphaOffsetAngle : 0; // Z
+		var beta = scope.deviceOrientation.beta ? THREE.Math.degToRad( scope.deviceOrientation.beta ) : 0; // X'
+		var gamma = scope.deviceOrientation.gamma ? THREE.Math.degToRad( scope.deviceOrientation.gamma ) : 0; // Y''
+		var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
+
+		setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
+		this.alpha = alpha;
+
+	};
+
+	this.updateAlphaOffsetAngle = function( angle ) {
+
+		this.alphaOffsetAngle = angle;
+		this.update();
+
+	};
+
+	this.dispose = function() {
+
+		this.disconnect();
+
+	};
+
+	this.connect();
+
+};

Fichier diff supprimé car celui-ci est trop grand
+ 702 - 0
720vr/js/three.min.js


Fichier diff supprimé car celui-ci est trop grand
+ 2 - 0
720vr/js/zepto.min.js