working principle, one console per jxr snippet (temporary visible toggling on execution)

spatial-introspection
Fabien Benetou 7 months ago
parent f9953f151d
commit 9dbc57991d
  1. 58
      index.html
  2. 21
      jxr-core.js

@ -4,15 +4,64 @@
<head>
<!-- Suggestions? https://git.benetou.fr/utopiah/text-code-xr-engine/issues/ -->
<script src='dependencies/aframe.offline.min.js'></script>
<script>
// testing spatial introspection, starting with console output
// see #spatial-introspection-test
// example of normal output
// which should print to the main console AND to the local one (might actually be the same output at first)
// for that could modifiy captureConsole of <a-console>
// itself passed to grabAllLogs() https://github.com/kylebakerio/a-console/blob/master/a-console.js#L680
// might require too much rework, could be interesting to have own equivalent instead
// define a new console, from https://stackoverflow.com/questions/7042611/override-console-log-for-production
/*
var console=(function(oldCons){
return {
debug: function(text){
oldCons.debug(text);
// Your code
},
log: function(text){
oldCons.log("modified!"+text, arguments.caller);
// this does though rewrite for ALL, so might not help much to find provenance, i.e which functions did call for that output
// could try to get a strack trace from here and only filter from what has gone through interpretJXR / onreleased / onpicked
// does NOT get picked by <a-console> though
// Your code
},
info: function (text) {
oldCons.info(text);
// Your code
},
warn: function (text) {
oldCons.warn(text);
// Your code
},
error: function (text) {
oldCons.error(text);
// Your code
}
};
}(window.console));
// for now could add mini console after each secondary pinch
//Then redefine the old console
window.console = console;
*/
</script>
<script src="dependencies/a-console.js"></script>
<script src='dependencies/aframe-troika-text.min.js'></script>
<script src='dependencies/webdav.js'></script>
<script src='jxr-core.js?123'></script>
<script src='jxr-core.js?12'></script>
<script src='jxr-postitnote.js?13235'></script>
</head>
<body>
<script>
var forceXaxis
// setInterval( _ => console.log(forceXaxis), 1000)
@ -347,6 +396,13 @@ setTimeout( _ => {
<!-- see pinchmoved in primary pinch in jxr-core.js as potential solution -->
</a-box>
<a-box teleporter height=".1" class="teleportable" material="color: cyan" position="0 0 0" ></a-box>
<a-troika-text id="spatial-introspection-test" anchor=left value="console.log('executing from secondary pinch');"
onreleased="console.log('run on released')"
onpicked="console.log('run on picked')"
target position=" -0.3 1.35 0" rotation="0 40 0" scale="0.1 0.1 0.1">
</a-troika-text>
</a-scene>
</body>
</script>

@ -129,8 +129,11 @@ AFRAME.registerComponent('pinchsecondary', {
this.el.addEventListener('pinchended', function (event) {
selectedElement = getClosestTargetElement( event.detail.position )
selectedElements.push({element:selectedElement, timestamp:Date.now(), primary:false})
// could push on pinchstarted instead
// if close enough to a target among a list of potential targets, unselect previous target then select new
if (selectedElement) interpretJXR( selectedElement.getAttribute("value") )
if (selectedElement) interpretJXR( selectedElement.getAttribute("value"), selectedElement )
// if (selectedElement) selectedElement.emit('released', {element:selectedElement, timestamp:Date.now(), primary:false})
// would be coherent BUT so far NOT testing on e.detail.primary thus probably getting unexpected behaviors
selectedElement = null
});
this.el.addEventListener('pinchmoved', function (event) {
@ -477,7 +480,7 @@ function parseJXR( code ){
return newcode
}
function interpretJXR( code ){
function interpretJXR( code, sourceElement ){
if (!code) return
if (code.length == 1) { // special case of being a single character, thus keyboard
if (code == ">") { // Enter equivalent
@ -502,6 +505,20 @@ function interpretJXR( code ){
commandhistory.push( {date: +Date.now(), uninterpreted: uninterpreted, interpreted: parseCode} )
console.log( parseCode )
if (sourceElement){
let consoleEl = sourceElement.querySelector("a-console")
if (consoleEl === null){
consoleEl = document.createElement("a-console")
consoleEl.setAttribute("position","1 -.4 0")
consoleEl.setAttribute("font-size","30")
consoleEl.setAttribute("height",".4")
consoleEl.setAttribute("width","2")
consoleEl.setAttribute("skip-intro",true)
sourceElement.appendChild(consoleEl)
}
consoleEl.setAttribute("visible", "true")
setTimeout( _ => consoleEl.setAttribute("visible", "false") , 10000)
}
try {
eval( parseCode )
} catch (error) {

Loading…
Cancel
Save