未验证 提交 2802d583 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #14355 from mrdoob/webvr

WebVR examples: Unified ball shooter examples in one. Removed controller models.
......@@ -319,11 +319,9 @@ var files = {
"webaudio_visualizer"
],
"webvr": [
"webvr_ballshooter",
"webvr_cubes",
"webvr_daydream",
"webvr_gearvr",
"webvr_lorenzattractor",
"webvr_oculusgo",
"webvr_panorama",
"webvr_rollercoaster",
"webvr_sandbox",
......
The MIT License
Copyright © 2015-2017 A-Frame authors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# Gear VR Controller MTL
newmtl Base
Kd 0.0911392 0.0911392 0.0911392
Ns 256
d 1
illum 2
Ka 0 0 0
Ks 0.04 0.04 0.04
newmtl Touchpad
Kd 0.172688 0.172688 0.172688
Ns 256
d 1
illum 2
Ka 0 0 0
Ks 0.04 0.04 0.04
newmtl Trigger
Kd 0.172688 0.172688 0.172688
Ns 256
d 1
illum 2
Ka 0 0 0
Ks 0.04 0.04 0.04
The MIT License
Copyright © 2018 @Kosso.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# Color definition for Tinkercad Obj File 2015. Created by @kosso.
newmtl color_10988977
Ka 0 0 0
Kd 0.6549019607843137 0.6784313725490196 0.6941176470588235
d 1.0
illum 0.0
newmtl color_14541540
Ka 0 0 0
Kd 0.8666666666666667 0.8862745098039215 0.8941176470588236
d 1.0
illum 0.0
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webvr - gear vr</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<!-- Origin Trial Token, feature = WebVR (For Chrome M62+), origin = https://threejs.org, expires = 2018-07-25 -->
<meta http-equiv="origin-trial" data-feature="WebVR (For Chrome M62+)" data-expires="2018-07-25" content="AtW06hJFoVWUJTZf5gqymMIlrR60JJi5MsSe44qsHjrCmzDUNmvaTtAVg+K9O9jFpjJtn/W9jvG//hHHaq5HcQoAAABQeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJWUjEuMU02MiIsImV4cGlyeSI6MTUzMjUyNjI5OH0=">
<!-- Origin Trial Token, feature = WebXR Device API, origin = https://threejs.org, expires = 2018-07-21 -->
<meta http-equiv="origin-trial" data-feature="WebXR Device API" data-expires="2018-07-21" content="Anlf1R/bCOUxOEgGI/9TWuzHHNxBMfZSTUMDCN7cLwDj2gpLwgA1K0DPwOzO/O0Jwaur5bsHo7k9KXx+6g+82wIAAABQeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkRldmljZSIsImV4cGlyeSI6MTUzMjE2NjIyNX0=">
<!-- Origin Trial Token, feature = WebXR Gamepad Support, origin = https://threejs.org, expires = 2018-07-21 -->
<meta http-equiv="origin-trial" data-feature="WebXR Gamepad Support" data-expires="2018-07-21" content="ArDsXbwATKHPmvQiPlEIWNCt4DlEjB7bLj9vOgoNmL8r38U+wQNYZyUvjQIqqzgACciUUuAnxluTIL7nNkI89gcAAABYeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkdhbWVwYWRTdXBwb3J0IiwiZXhwaXJ5IjoxNTMyMTY2MjI1fQ==">
<style>
body {
font-family: Monospace;
background-color: #101010;
color: #fff;
margin: 0px;
overflow: hidden;
}
a {
color: #f00;
}
</style>
</head>
<body>
<script src="../build/three.js"></script>
<script src="js/loaders/MTLLoader.js"></script>
<script src="js/loaders/OBJLoader.js"></script>
<script src="js/vr/GearVRController.js"></script>
<script src="js/vr/WebVR.js"></script>
<script>
var container;
var camera, scene, renderer;
var controller;
var room;
var radius = 0.08;
var normal = new THREE.Vector3();
var relativeVelocity = new THREE.Vector3();
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
var info = document.createElement( 'div' );
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.innerHTML = '<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - gear vr';
container.appendChild( info );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x505050 );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );
room = new THREE.Mesh(
new THREE.BoxBufferGeometry( 6, 6, 6, 8, 8, 8 ),
new THREE.MeshBasicMaterial( { color: 0x404040, wireframe: true } )
);
room.position.y = 3;
scene.add( room );
scene.add( new THREE.HemisphereLight( 0x606060, 0x404040 ) );
var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 1, 1, 1 ).normalize();
scene.add( light );
var geometry = new THREE.IcosahedronBufferGeometry( radius, 2 );
for ( var i = 0; i < 200; i ++ ) {
var object = new THREE.Mesh(
geometry,
new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } )
);
object.position.x = Math.random() * 4 - 2;
object.position.y = Math.random() * 4 - 2;
object.position.z = Math.random() * 4 - 2;
object.userData.velocity = new THREE.Vector3();
object.userData.velocity.x = Math.random() * 0.01 - 0.005;
object.userData.velocity.y = Math.random() * 0.01 - 0.005;
object.userData.velocity.z = Math.random() * 0.01 - 0.005;
room.add( object );
}
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.vr.enabled = true;
container.appendChild( renderer.domElement );
document.body.appendChild( WEBVR.createButton( renderer ) );
controller = new THREE.GearVRController();
controller.position.set( 0.25, 0.75, 0 );
scene.add( controller );
var skyBox = {
front: 'textures/cube/Bridge2/posz.jpg',
back: 'textures/cube/Bridge2/negz.jpg',
left: 'textures/cube/Bridge2/posx.jpg',
right: 'textures/cube/Bridge2/negx.jpg',
up: 'textures/cube/Bridge2/posy.jpg',
down: 'textures/cube/Bridge2/negy.jpg'
};
if ( 'SamsungChangeSky' in window ) {
window.SamsungChangeSky( skyBox );
}
var MTL = new THREE.MTLLoader();
MTL.setPath( 'models/obj/gear_vr_controller/' );
MTL.load( 'gear_vr_controller.mtl', function ( materials ) {
materials.preload();
var OBJ = new THREE.OBJLoader();
OBJ.setMaterials( materials );
OBJ.setPath( 'models/obj/gear_vr_controller/' );
OBJ.load( 'gear_vr_controller.obj', function ( obj ) {
obj.translateZ( - 0.03 );
controller.add( obj );
} );
} );
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
renderer.setAnimationLoop( render );
}
function render() {
controller.update();
if ( controller.getTouchpadState() === true ) {
var cube = room.children[ 0 ];
room.remove( cube );
cube.position.copy( controller.position ).sub( room.position );
cube.userData.velocity.x = ( Math.random() - 0.5 ) * 0.02;
cube.userData.velocity.y = ( Math.random() - 0.5 ) * 0.02;
cube.userData.velocity.z = ( Math.random() * 0.02 - 0.1 );
cube.userData.velocity.applyQuaternion( controller.quaternion );
room.add( cube );
}
// keep cubes inside room
var range = 3 - radius;
for ( var i = 0; i < room.children.length; i ++ ) {
var cube = room.children[ i ];
cube.position.add( cube.userData.velocity );
if ( cube.position.x < - range || cube.position.x > range ) {
cube.position.x = THREE.Math.clamp( cube.position.x, - range, range );
cube.userData.velocity.x = - cube.userData.velocity.x;
}
if ( cube.position.y < - range || cube.position.y > range ) {
cube.position.y = Math.max( cube.position.y, - range );
cube.userData.velocity.x *= 0.9;
cube.userData.velocity.y = - cube.userData.velocity.y * 0.8;
cube.userData.velocity.z *= 0.9;
}
if ( cube.position.z < - range || cube.position.z > range ) {
cube.position.z = THREE.Math.clamp( cube.position.z, - range, range );
cube.userData.velocity.z = - cube.userData.velocity.z;
}
for ( var j = i + 1; j < room.children.length; j ++ ) {
var cube2 = room.children[ j ];
normal.copy( cube.position ).sub( cube2.position );
if ( normal.length() < 2 * radius ) {
normal.multiplyScalar( 0.5 * normal.length() - radius );
cube.position.sub( normal );
cube2.position.add( normal );
normal.normalize();
relativeVelocity.copy( cube.userData.velocity ).sub( cube2.userData.velocity );
var dot = relativeVelocity.dot( normal );
normal = normal.multiplyScalar( dot );
cube.userData.velocity.sub( normal );
cube2.userData.velocity.add( normal );
}
}
cube.userData.velocity.y -= 0.00098;
}
renderer.render( scene, camera );
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webvr - oculus go</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<!-- Origin Trial Token, feature = WebVR (For Chrome M62+), origin = https://threejs.org, expires = 2018-07-25 -->
<meta http-equiv="origin-trial" data-feature="WebVR (For Chrome M62+)" data-expires="2018-07-25" content="AtW06hJFoVWUJTZf5gqymMIlrR60JJi5MsSe44qsHjrCmzDUNmvaTtAVg+K9O9jFpjJtn/W9jvG//hHHaq5HcQoAAABQeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJWUjEuMU02MiIsImV4cGlyeSI6MTUzMjUyNjI5OH0=">
<!-- Origin Trial Token, feature = WebXR Device API, origin = https://threejs.org, expires = 2018-07-21 -->
<meta http-equiv="origin-trial" data-feature="WebXR Device API" data-expires="2018-07-21" content="Anlf1R/bCOUxOEgGI/9TWuzHHNxBMfZSTUMDCN7cLwDj2gpLwgA1K0DPwOzO/O0Jwaur5bsHo7k9KXx+6g+82wIAAABQeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkRldmljZSIsImV4cGlyeSI6MTUzMjE2NjIyNX0=">
<!-- Origin Trial Token, feature = WebXR Gamepad Support, origin = https://threejs.org, expires = 2018-07-21 -->
<meta http-equiv="origin-trial" data-feature="WebXR Gamepad Support" data-expires="2018-07-21" content="ArDsXbwATKHPmvQiPlEIWNCt4DlEjB7bLj9vOgoNmL8r38U+wQNYZyUvjQIqqzgACciUUuAnxluTIL7nNkI89gcAAABYeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkdhbWVwYWRTdXBwb3J0IiwiZXhwaXJ5IjoxNTMyMTY2MjI1fQ==">
<style>
body {
font-family: Monospace;
background-color: #101010;
color: #fff;
margin: 0px;
overflow: hidden;
}
a {
color: #f00;
}
</style>
</head>
<body>
<script src="../build/three.js"></script>
<script src="js/loaders/MTLLoader.js"></script>
<script src="js/loaders/OBJLoader.js"></script>
<script src="js/vr/GearVRController.js"></script>
<script src="js/vr/WebVR.js"></script>
<script>
var container;
var camera, scene, renderer;
var controller;
var room;
var radius = 0.08;
var normal = new THREE.Vector3();
var relativeVelocity = new THREE.Vector3();
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
var info = document.createElement( 'div' );
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.innerHTML = '<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webvr - oculus go';
container.appendChild( info );
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x505050 );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );
room = new THREE.Mesh(
new THREE.BoxBufferGeometry( 6, 6, 6, 8, 8, 8 ),
new THREE.MeshBasicMaterial( { color: 0x404040, wireframe: true } )
);
room.position.y = 3;
scene.add( room );
scene.add( new THREE.HemisphereLight( 0x606060, 0x404040 ) );
var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 1, 1, 1 ).normalize();
scene.add( light );
var geometry = new THREE.IcosahedronBufferGeometry( radius, 2 );
for ( var i = 0; i < 200; i ++ ) {
var object = new THREE.Mesh(
geometry,
new THREE.MeshLambertMaterial( { color: Math.random() * 0xffffff } )
);
object.position.x = Math.random() * 4 - 2;
object.position.y = Math.random() * 4 - 2;
object.position.z = Math.random() * 4 - 2;
object.userData.velocity = new THREE.Vector3();
object.userData.velocity.x = Math.random() * 0.01 - 0.005;
object.userData.velocity.y = Math.random() * 0.01 - 0.005;
object.userData.velocity.z = Math.random() * 0.01 - 0.005;
room.add( object );
}
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.vr.enabled = true;
container.appendChild( renderer.domElement );
document.body.appendChild( WEBVR.createButton( renderer ) );
controller = new THREE.GearVRController();
controller.position.set( 0.35, 1.1, -0.3 );
scene.add( controller );
var skyBox = {
front: 'textures/cube/Bridge2/posz.jpg',
back: 'textures/cube/Bridge2/negz.jpg',
left: 'textures/cube/Bridge2/posx.jpg',
right: 'textures/cube/Bridge2/negx.jpg',
up: 'textures/cube/Bridge2/posy.jpg',
down: 'textures/cube/Bridge2/negy.jpg'
};
if ( 'SamsungChangeSky' in window ) {
window.SamsungChangeSky( skyBox );
}
var MTL = new THREE.MTLLoader();
MTL.setPath( 'models/obj/oculus_go_controller/' );
MTL.load( 'oculus_go_controller.mtl', function ( materials ) {
materials.preload();
var OBJ = new THREE.OBJLoader();
OBJ.setMaterials( materials );
OBJ.setPath( 'models/obj/oculus_go_controller/' );
OBJ.load( 'oculus_go_controller.obj', function ( obj ) {
obj.translateZ( - 0.03 );
controller.add( obj );
} );
} );
window.addEventListener( 'resize', onWindowResize, false );
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
renderer.setAnimationLoop( render );
}
function render() {
controller.update();
if ( controller.getTouchpadState() === true ) {
var cube = room.children[ 0 ];
room.remove( cube );
cube.position.copy( controller.position ).sub( room.position );
cube.userData.velocity.x = ( Math.random() - 0.5 ) * 0.02;
cube.userData.velocity.y = ( Math.random() - 0.5 ) * 0.02;
cube.userData.velocity.z = ( Math.random() * 0.02 - 0.1 );
cube.userData.velocity.applyQuaternion( controller.quaternion );
room.add( cube );
}
// keep cubes inside room
var range = 3 - radius;
for ( var i = 0; i < room.children.length; i ++ ) {
var cube = room.children[ i ];
cube.position.add( cube.userData.velocity );
if ( cube.position.x < - range || cube.position.x > range ) {
cube.position.x = THREE.Math.clamp( cube.position.x, - range, range );
cube.userData.velocity.x = - cube.userData.velocity.x;
}
if ( cube.position.y < - range || cube.position.y > range ) {
cube.position.y = Math.max( cube.position.y, - range );
cube.userData.velocity.x *= 0.9;
cube.userData.velocity.y = - cube.userData.velocity.y * 0.8;
cube.userData.velocity.z *= 0.9;
}
if ( cube.position.z < - range || cube.position.z > range ) {
cube.position.z = THREE.Math.clamp( cube.position.z, - range, range );
cube.userData.velocity.z = - cube.userData.velocity.z;
}
for ( var j = i + 1; j < room.children.length; j ++ ) {
var cube2 = room.children[ j ];
normal.copy( cube.position ).sub( cube2.position );
if ( normal.length() < 2 * radius ) {
normal.multiplyScalar( 0.5 * normal.length() - radius );
cube.position.sub( normal );
cube2.position.add( normal );
normal.normalize();
relativeVelocity.copy( cube.userData.velocity ).sub( cube2.userData.velocity );
var dot = relativeVelocity.dot( normal );
normal = normal.multiplyScalar( dot );
cube.userData.velocity.sub( normal );
cube2.userData.velocity.add( normal );
}
}
cube.userData.velocity.y -= 0.00098;
}
renderer.render( scene, camera );
}
</script>
</body>
</html>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册