from primitive to instance (without instancing proper)

primitives_as_set
Fabien Benetou 2 years ago
parent 1ce813ebac
commit 1bb95fa69c
  1. 30
      index.html

@ -2139,18 +2139,22 @@ AFRAME.registerComponent('clone-on-primarypinchstarted', {
init: function () { init: function () {
let el = this.el let el = this.el
this.el.addEventListener('picked', function (event) { this.el.addEventListener('picked', function (event) {
var clone = selectedElement.cloneNode(true) selectedElement = instanciateFromPrimitive( selectedElement )
clone.removeAttribute('clone-on-primarypinchstarted')
clone.setAttribute( "scale", selectedElement.getAttribute("scale") ) // somehow lost?
clone.id += "_clone" + Date.now()
clone.className = "cloned"
targets.push(clone)
AFRAME.scenes[0].appendChild(clone)
selectedElement = clone
}) })
} }
}) })
function instanciateFromPrimitive(element){
var clone = element.cloneNode(true)
clone.removeAttribute('clone-on-primarypinchstarted')
clone.setAttribute( "scale", element.getAttribute("scale") ) // somehow lost?
clone.id += "_clone" + Date.now()
clone.className = "cloned"
targets.push(clone)
AFRAME.scenes[0].appendChild(clone)
return clone
}
function addAllPrimitives(){ function addAllPrimitives(){
const other_primitives = ["camera", "cursor", "sky", "light", "sound", "videosphere"] const other_primitives = ["camera", "cursor", "sky", "light", "sound", "videosphere"]
const other_primitives_with_param_needed = ["text", "gltf-model", "obj-model", "troika-text"] const other_primitives_with_param_needed = ["text", "gltf-model", "obj-model", "troika-text"]
@ -2198,6 +2202,16 @@ function getClassFromPick(){ // should be classes, for now assuming one
return classFound return classFound
} }
function getArrayFromClass(classname){
return Array.from( document.querySelectorAll("."+classname) )
}
function applyToClass(classname, callback, value){
// example applyToClass("template_object", (e, val ) => e.setAttribute("scale", val), ".1 .1 .2")
getArrayFromClass(classname).map( e => callback(e, value))
// could instead become a jxr shortcut, namely apply a set attribute to a class of entities
}
function changeColorLastClass(){ function changeColorLastClass(){
let classFound = getClassFromPick() // applies on primary only let classFound = getClassFromPick() // applies on primary only
if (classFound) if (classFound)

Loading…
Cancel
Save