xrfragment/example/aframe/sandbox/index.html

88 lines
4.3 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">
<img src="./../../assets/logo.png" class="logo"/>
<button id="navback" onclick="history.back()">&lt;</button>
<button id="navforward" onclick="history.forward()">&gt;</button>
<input type="submit" value="load 3D asset"></input>
<input type="text" id="uri" value="" onchange="AFRAME.XRF.navigator.to( $('#uri').value )"/>
</div>
<a class="btn-foot" id="source" target="_blank" href="https://github.com/coderofsalvation/xrfragment/blob/main/example/aframe/sandbox/index.html">sourcecode</a>
<a class="btn-foot" id="model" target="_blank" href="">⬇️ model</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;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>
<a-entity id="home" xrf="example3.gltf#pos=0,0,0"></a-entity>
<a-entity id="floor" xrf-get="floor"></a-entity>
</a-scene>
<script type="module">
import { loadFile, setupConsole, setupUrlBar, notify } from './../../assets/js/utils.js';
window.$ = (s) => document.querySelector(s)
window.notify = notify(window)
console.log = ( (log) => function(str){
if( String(str).match(/(camera)/) ) 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('loaded', () => {
setupConsole( $('textarea') )
setupUrlBar( $('input#uri'), window.AFRAME.XRF )
// optional hook to prompt surfing to external asset
window.AFRAME.XRF.href = (xrf,v,opts) => {
let { mesh, model, camera, scene, renderer, THREE} = opts
alert("1")
let isExtern = v.string[0] != '#'
let notIsHome = v.string != $('#home').getAttribute("xrf")
// xrf(v,opts) // original init
// const exec = mesh.userData.XRF.href.exec
//console.dir(exec)
// mesh.userData.XRF.href.exec = (e) => {
// if( !renderer.xr.isPresenting && isExtern && notIsHome ){
// if( !confirm("teleport to "+v.string+" ?") ) return
// }
// exec(e)
// }
}
// add screenshot component with camera to capture bigger size equirects
$('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 )
})
</script>
</body>
</html>