proper primitives and components

real-world-meshing
Fabien Benetou 4 months ago
parent c10f90aeb5
commit 6cf4acb7d6
  1. 50
      index.html

@ -13,26 +13,70 @@
<body> <body>
<script> <script>
// used for keywords like LAST / PREVIOUS / ALL
let addedContent = []
function getAllPrimitives(){
const other_primitives = ["camera", "cursor", "sky", "light", "sound", "videosphere"]
const other_primitives_with_param_needed = ["text", "gltf-model", "obj-model", "troika-text"]
return Object.getOwnPropertyNames(AFRAME.primitives.primitives)
// thanks to https://github.com/Utopiah/aframe-inVR-blocks-based-editor/blob/master/aframe-invr-inspect.js
.map( i => i.replace("a-",""))
.filter( i => other_primitives.indexOf(i) < 0 )
.filter( i => other_primitives_with_param_needed.indexOf(i) < 0 ) // temporarilty disabled
// .map( (i,j) => addPrimitive( i, ""+ j/7 + " 1.4 -0.5" ) )
.map( (i,j) => i )
} // adapted from https://git.benetou.fr/utopiah/text-code-xr-engine/src/commit/0e1f297ec0cd17b0356811dfa0ab55f1e2629e7c/index.html#L2101
const SpeechRecognition = window.webkitSpeechRecognition; const SpeechRecognition = window.webkitSpeechRecognition;
recognizer = new SpeechRecognition(); recognizer = new SpeechRecognition();
recognizer.interimResults = true; recognizer.interimResults = true;
recognizer.continuous = true; recognizer.continuous = true;
recognizer.lang = 'en-US'; recognizer.lang = 'en-US';
const aframeprimitives = getAllPrimitives()
const speechactions = [ "add", "apply" ]
const speechcustomcomponents = [ "target", "teleporter" ]
recognizer.onresult = (event) => { recognizer.onresult = (event) => {
let result = event.results[event.resultIndex] let result = event.results[event.resultIndex]
if (result.isFinal) { if (result.isFinal) {
console.log('You said: ' + result[0].transcript + '_END') console.log('You said: ' + result[0].transcript )
// should instead look if starting with speechContent following by aframeprimitives, optionally speechcustomcomponents
// then apply accordingly
let speechContent = result[0].transcript
let cmd_words = speechContent.split(" ").map( i => i.toLowerCase() )
if (cmd_words[0] == speechactions[0]){ // limited to add command for now
console.log("recognized proper command")
let primitive = cmd_words[1] // assuming fixed order for now
let el = document.createElement("a-"+primitive)
el.setAttribute("target", "")
el.setAttribute("scale", ".1 .1 .1")
el.setAttribute("position", "0 1.5 -0.4")
addedContent.push(el)
AFRAME.scenes[0].appendChild( el )
}
if (cmd_words[0] == speechactions[1]){ // limited to apply
console.log("recognized apply command")
addedContent.at(-1).setAttribute( cmd_words[1], cmd_words[2]) // assuming fixed order for now
}
if ( result[0].transcript == "Add red cube"){ if ( result[0].transcript == "Add red cube"){
// should instead look for syntax e.g ACTION PROPERTY_SHORTCUT ENTITY_TYPE
// itself generated from AFrame introspection
console.log("recognized command") console.log("recognized command")
let newPostIt = addNewNoteAsPostItNote(speechContent, "0 1.2 -.5")
// could become jxr code proper later, also allowing to re-execute a command again
let el = document.createElement("a-box") let el = document.createElement("a-box")
el.setAttribute("color", "red") el.setAttribute("color", "red")
el.setAttribute("target", "") el.setAttribute("target", "")
el.setAttribute("scale", ".1 .1 .1") el.setAttribute("scale", ".1 .1 .1")
el.setAttribute("position", "0 1.5 -0.4") el.setAttribute("position", "0 1.5 -0.4")
AFRAME.scenes[0].appendChild( el ) AFRAME.scenes[0].appendChild( el )
// among ACTION could also have a selection area, e.g a bounding box wireframe to apply the action to all elements within in
addedContent.push(el)
} }
} }
} }

Loading…
Cancel
Save