clone (partly working, losing attributes) and delete commands

real-world-meshing
Fabien Benetou 7 months ago
parent 6cf4acb7d6
commit b5556ff071
  1. 24
      index.html

@ -35,7 +35,7 @@ recognizer.continuous = true;
recognizer.lang = 'en-US'; recognizer.lang = 'en-US';
const aframeprimitives = getAllPrimitives() const aframeprimitives = getAllPrimitives()
const speechactions = [ "add", "apply" ] const speechactions = [ "add", "apply", "delete", "clone" ]
const speechcustomcomponents = [ "target", "teleporter" ] const speechcustomcomponents = [ "target", "teleporter" ]
recognizer.onresult = (event) => { recognizer.onresult = (event) => {
@ -46,6 +46,8 @@ recognizer.onresult = (event) => {
// should instead look if starting with speechContent following by aframeprimitives, optionally speechcustomcomponents // should instead look if starting with speechContent following by aframeprimitives, optionally speechcustomcomponents
// then apply accordingly // then apply accordingly
let speechContent = result[0].transcript let speechContent = result[0].transcript
// let newPostIt = addNewNoteAsPostItNote(speechContent, "0 1.2 -.5")
// could become jxr code proper later, also allowing to re-execute a command again
let cmd_words = speechContent.split(" ").map( i => i.toLowerCase() ) let cmd_words = speechContent.split(" ").map( i => i.toLowerCase() )
if (cmd_words[0] == speechactions[0]){ // limited to add command for now if (cmd_words[0] == speechactions[0]){ // limited to add command for now
console.log("recognized proper command") console.log("recognized proper command")
@ -63,21 +65,17 @@ recognizer.onresult = (event) => {
addedContent.at(-1).setAttribute( cmd_words[1], cmd_words[2]) // assuming fixed order for now addedContent.at(-1).setAttribute( cmd_words[1], cmd_words[2]) // assuming fixed order for now
} }
if ( result[0].transcript == "Add red cube"){ if (cmd_words[0] == speechactions[2])
console.log("recognized command") deleteTarget( addedContent.at(-1) )
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")
el.setAttribute("color", "red")
el.setAttribute("target", "")
el.setAttribute("scale", ".1 .1 .1")
el.setAttribute("position", "0 1.5 -0.4")
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 if (cmd_words[0] == speechactions[3]){
let el = addedContent.at(-1).cloneNode(true) // does not work properly, losing some attributes, in particular scale can be problematic
// could optionally add a number of times
addedContent.push(el) addedContent.push(el)
el.object3D.translateX(1)
AFRAME.scenes[0].appendChild( el )
} }
} }
} }
recognizer.start(); recognizer.start();

Loading…
Cancel
Save