xrfragment/example/aframe/sandbox/index.html

88 lines
4.3 KiB
HTML
Raw Normal View History

2023-05-09 17:42:29 +02:00
<!DOCTYPE html>
<html lang="en">
2023-05-22 18:58:05 +02:00
<head>
<title>AFRAME - xrfragment sandbox</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
2023-05-22 14:10:44 +02:00
<link rel="stylesheet" href="./../../assets/css/axist.min.css" />
<link type="text/css" rel="stylesheet" href="./../../assets/css/style.css"/>
2023-05-22 18:58:05 +02:00
<script async src="./../../assets/js/alpine.min.js" defer></script>
<script src="https://aframe.io/releases/1.4.2/aframe.min.js"></script>
2023-05-10 19:12:15 +02:00
<script src="https://cdn.jsdelivr.net/npm/aframe-blink-controls/dist/aframe-blink-controls.min.js"></script>
2023-05-22 18:58:05 +02:00
<script src="./../../../dist/xrfragment.aframe.js"></script>
</head>
<body>
2023-05-22 14:10:44 +02:00
<div id="overlay">
2023-05-09 17:42:29 +02:00
<img src="./../../assets/logo.png" class="logo"/>
<button id="navback" onclick="history.back()">&lt;</button>
<button id="navforward" onclick="history.forward()">&gt;</button>
2023-05-22 18:58:05 +02:00
<input type="submit" value="load 3D asset"></input>
2023-05-18 17:11:11 +02:00
<input type="text" id="uri" value="" onchange="AFRAME.XRF.navigator.to( $('#uri').value )"/>
2023-05-09 17:42:29 +02:00
</div>
2023-07-03 19:56:39 +02:00
<a class="btn-foot" id="source" target="_blank" href="https://github.com/coderofsalvation/xrfragment-aframe-helloworld">clone project</a>
2023-05-17 21:31:28 +02:00
<a class="btn-foot" id="model" target="_blank" href="">⬇️ model</a>
2023-05-22 18:58:05 +02:00
<textarea style="display:none"></textarea>
<a-scene light="defaultLightsEnabled: false">
2023-05-22 18:58:05 +02:00
<a-entity id="player" wasd-controls look-controls>
<a-entity id="left-hand" laser-controls="hand: left" raycaster="objects:.ray;far:5500" oculus-touch-controls="hand: left" blink-controls="cameraRig:#player; teleportOrigin: #camera; collisionEntities: #floor">
<a-entity rotation="-90 0 0" position="0 0.1 0">
<a-entity id="back" xrf-button="label: <; width:0.05; action: history.back()" position="-0.025 0 0" class="ray"></a-entity>
<a-entity id="next" xrf-button="label: >; width:0.05; action: history.forward()" position=" 0.025 0 0" class="ray"></a-entity>
</a-entity>
</a-entity>
<a-entity id="right-hand" laser-controls="hand: right" raycaster="objects:.ray;far:5500" oculus-touch-controls="hand: right" blink-controls="cameraRig:#player; teleportOrigin: #camera; collisionEntities: #floor"></a-entity>
<a-entity camera="fov:90" position="0 1.6 0" id="camera"></a-entity>
</a-entity>
2023-06-09 16:56:15 +02:00
<a-entity id="home" xrf="example.gltf#pos=0,0,0"></a-entity>
<a-entity id="floor" xrf-get="floor"></a-entity>
2023-05-09 17:42:29 +02:00
</a-scene>
2023-05-22 18:58:05 +02:00
<script type="module">
import { loadFile, setupConsole, setupUrlBar, notify } from './../../assets/js/utils.js';
2023-05-09 17:42:29 +02:00
window.$ = (s) => document.querySelector(s)
2023-05-22 14:10:44 +02:00
window.notify = notify(window)
console.log = ( (log) => function(str){
2023-06-22 13:59:17 +02:00
if( String(str).match(/:.*#/) ) window.notify(str)
2023-05-22 14:10:44 +02:00
log(str)
})(console.log)
2023-05-09 17:42:29 +02:00
2023-05-22 18:58:05 +02:00
if( document.location.search.length > 2 )
$('#home').setAttribute('xrf', document.location.search.substr(1)+document.location.hash )
2023-05-09 17:42:29 +02:00
2023-05-22 18:58:05 +02:00
$('a-scene').addEventListener('loaded', () => {
2023-06-02 09:42:52 +02:00
2023-06-02 12:00:21 +02:00
let XRF = window.AFRAME.XRF
2023-05-22 18:58:05 +02:00
setupConsole( $('textarea') )
2023-06-02 12:00:21 +02:00
setupUrlBar( $('input#uri'), XRF )
2023-06-02 09:42:52 +02:00
2023-06-02 12:00:21 +02:00
// example listener, to prompt surfing to external asset
XRF.addEventListener('href',(e) => {
if( e.click ){
const { mesh, model, camera, scene, renderer, THREE} = e.XRF
const url = e.xrf.string
2023-06-07 15:36:19 +02:00
const isExtern = url[0] != '#'
2023-06-02 12:00:21 +02:00
const notIsHome = url != $('#home').getAttribute("xrf")
const promise = e.promise() // promisify event
2023-06-07 15:36:19 +02:00
if( !renderer.xr.isPresenting ){
if( isExtern && notIsHome ){
if( !confirm("teleport to "+url+" ?") ) return promise.reject('teleport rejected')
}
2023-06-02 12:00:21 +02:00
}
2023-06-07 15:36:19 +02:00
promise.resolve()
2023-06-02 12:00:21 +02:00
}
})
2023-06-02 09:42:52 +02:00
// add screenshot component with camera to capture bigger size equirects
$('a-scene').setAttribute("screenshot",{camera: "[camera]",width: 4096*2, height:2048*2})
2023-05-23 14:45:55 +02:00
if( window.outerWidth > 800 )
setTimeout( () => window.notify("use WASD-keys and mouse-drag to move around",{timeout:false}),2000 )
2023-05-22 14:10:44 +02:00
window.AFRAME.XRF.addEventListener('href', (data) => data.selected ? window.notify(`href: ${data.xrf.string}`) : false )
2023-05-22 18:58:05 +02:00
})
</script>
</body>
2023-05-09 17:42:29 +02:00
</html>