from primitive to instance (without instancing proper)

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

@ -2139,17 +2139,21 @@ 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 )
})
}
})
function instanciateFromPrimitive(element){
var clone = element.cloneNode(true)
clone.removeAttribute('clone-on-primarypinchstarted') clone.removeAttribute('clone-on-primarypinchstarted')
clone.setAttribute( "scale", selectedElement.getAttribute("scale") ) // somehow lost? clone.setAttribute( "scale", element.getAttribute("scale") ) // somehow lost?
clone.id += "_clone" + Date.now() clone.id += "_clone" + Date.now()
clone.className = "cloned" clone.className = "cloned"
targets.push(clone) targets.push(clone)
AFRAME.scenes[0].appendChild(clone) AFRAME.scenes[0].appendChild(clone)
selectedElement = 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"]
@ -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