103 lines
5.2 KiB
HTML
103 lines
5.2 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<title>AFRAME - xrfragment sandbox</title>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||
<link rel="stylesheet" href="./../../assets/css/axist.min.css" />
|
||
<link type="text/css" rel="stylesheet" href="./../../assets/css/style.css"/>
|
||
<script async src="./../../assets/js/alpine.min.js" defer></script>
|
||
<script src="https://aframe.io/releases/1.4.2/aframe.min.js"></script>
|
||
<script src="https://cdn.jsdelivr.net/npm/aframe-blink-controls/dist/aframe-blink-controls.min.js"></script>
|
||
<script src="./../../../dist/xrfragment.aframe.js"></script>
|
||
</head>
|
||
<body>
|
||
<div id="overlay" style="display:none">
|
||
<img src="./../../assets/logo.png" class="logo"/>
|
||
<button id="navback" onclick="history.back()"><</button>
|
||
<button id="navforward" onclick="history.forward()">></button>
|
||
<input type="submit" value="load 3D file"></input>
|
||
<input type="text" id="uri" value="" onchange="AFRAME.XRF.navigator.to( $('#uri').value )"/>
|
||
</div>
|
||
|
||
<!-- open AFRAME inspector: $('a-scene').components.inspector.openInspector() -->
|
||
<a class="btn-foot" id="source" target="_blank" href="https://github.com/coderofsalvation/xrfragment-helloworld">➕ clone project</a>
|
||
<a class="btn-foot" id="embed" target="_blank" onclick="embed()">📺 embed</a>
|
||
<a class="btn-foot" id="model" target="_blank" href="example.gltf">⬇️ model</a>
|
||
<a class="btn-foot" id="more" target="_blank">XRF</a>
|
||
<textarea style="display:none"></textarea>
|
||
<a-scene light="defaultLightsEnabled: false">
|
||
<a-entity id="player" wasd-controls look-controls>
|
||
<a-entity id="left-hand" laser-controls="hand: left" raycaster="objects:.ray" 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" 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>
|
||
|
||
<a-entity id="home" xrf="index.gltf#pos=0,0,0"></a-entity>
|
||
<a-plane id="floor" position="0 0 0" rotation="-90 0 0" width="100" height="100" material="visible:false"></a-plane>
|
||
</a-scene>
|
||
|
||
<script type="module">
|
||
import { loadFile, setupConsole, setupUrlBar, notify, embed } from './../../assets/js/utils.js';
|
||
window.$ = (s) => document.querySelector(s)
|
||
window.notify = notify(window)
|
||
window.embed = embed
|
||
|
||
console.log = ( (log) => function(str){
|
||
if( String(str).match(/:.*#/) ) window.notify(str)
|
||
log(str)
|
||
})(console.log)
|
||
|
||
if( document.location.search.length > 2 )
|
||
$('#home').setAttribute('xrf', document.location.search.substr(1)+document.location.hash )
|
||
|
||
$('a-scene').addEventListener('XRF', () => {
|
||
|
||
let XRF = window.AFRAME.XRF
|
||
setupConsole( $('textarea') )
|
||
setupUrlBar( $('input#uri'), XRF )
|
||
|
||
// 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
|
||
const isExtern = url[0] != '#'
|
||
const notIsHome = url != $('#home').getAttribute("xrf")
|
||
const promise = e.promise() // promisify event
|
||
document.querySelector('#model').setAttribute('href',url.replace(/.*\?/,'') )
|
||
if( !renderer.xr.isPresenting ){
|
||
if( isExtern && notIsHome ){
|
||
if( !confirm("teleport to "+url+" ?") ) return promise.reject('teleport rejected')
|
||
}
|
||
}
|
||
promise.resolve()
|
||
}
|
||
})
|
||
|
||
// add screenshot component with camera to capture bigger size equirects
|
||
// document.querySelector('a-scene').components.screenshot.capture('perspective')
|
||
$('a-scene').setAttribute("screenshot",{camera: "[camera]",width: 4096*2, height:2048*2})
|
||
|
||
if( window.outerWidth > 800 )
|
||
setTimeout( () => window.notify("use WASD-keys and mouse-drag to move around",{timeout:false}),2000 )
|
||
|
||
window.AFRAME.XRF.addEventListener('href', (data) => data.selected ? window.notify(`href: ${data.xrf.string}`) : false )
|
||
|
||
// enable user-uploaded asset files
|
||
let fileLoaders = loadFile({
|
||
".gltf": (file) => file.arrayBuffer().then( (data) => xrf.navigator.to(file.name,null, (new xrf.loaders.gltf()), data) ),
|
||
".glb": (file) => file.arrayBuffer().then( (data) => xrf.navigator.to(file.name,null, (new xrf.loaders.gltf()), data) )
|
||
})
|
||
$("#overlay > input[type=submit]").addEventListener("click", fileLoaders )
|
||
|
||
})
|
||
</script>
|
||
</body>
|
||
</html>
|