From 3e3e6fa6027ba63c521c79408ff3a8777ac4810a Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Thu, 19 Jan 2023 10:37:33 +0100 Subject: [PATCH] refactoring and compound example --- index.html | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 55c85ff..c68200c 100644 --- a/index.html +++ b/index.html @@ -2026,23 +2026,53 @@ function addScreenshot(){ targets.push(sel) } -function addPrimitive( name, position="0 1.4 -0.2" ){ - let el = document.createElement("a-"+name) // e.g box or sphere - let el_outline = document.createElement("a-"+name) // e.g box or sphere - AFRAME.scenes[0].appendChild(el) +function newPrimitiveWithOutline( name="box", position="0 0 0", scale=".1 .1 .1" ){ + let el = document.createElement("a-"+name) + let el_outline = document.createElement("a-"+name) el.appendChild(el_outline) + el.setAttribute("scale", scale) el.setAttribute("position", position) - el.setAttribute("scale", ".1 .1 .1") el_outline.setAttribute("scale", "1.01 1.01 1.01") el_outline.setAttribute("color", "gray") el_outline.setAttribute("wireframe", "true") + return el +} + +function addCompoundPrimitiveExample(position="0 1.4 -0.2"){ + var el = document.createElement("a-entity") + el.setAttribute("position", position) + AFRAME.scenes[0].appendChild(el) + el.id = "compound_object_" + name + el.className = "compound_object" + let parts = [] + parts.push( newPrimitiveWithOutline("box", "0 0 0", ".2 .1 .1") ) + parts.push( newPrimitiveWithOutline("box", ".125 0 0", ".05 .05 .05") ) + parts.push( newPrimitiveWithOutline("box", "-.125 0.0375 0", ".05 .025 .1") ) + parts.push( newPrimitiveWithOutline("box", "-.125 -0.0375 0", ".05 .025 .1") ) + parts.push( newPrimitiveWithOutline("box", "-.125 0 0.0375", ".05 .05 .025") ) + parts.push( newPrimitiveWithOutline("box", "-.125 0 -0.0375", ".05 .05 .025") ) + parts.map( p => el.appendChild(p) ) + targets.push(el) +} + +function addPrimitive( name, position="0 1.4 -0.2" ){ + let el = newPrimitiveWithOutline( name ) + el.setAttribute("position", position) + AFRAME.scenes[0].appendChild(el) + el.id = "template_object_" + name + el.className = "template_object" + targets.push(el) + // should have a dedicated cloning component activated on primary pinchstarted } -functions addAllPrimitives(){ +function addAllPrimitives(){ + const other_primitives = ["camera", "cursor", "sky", "light", "sound", "videosphere"] + const other_primitives_with_param_needed = ["text", "gltf-model", "obj-model", "troika-text"] 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 => i != "camera") // should add more, e.g sky, light, etc + .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" ) ) } @@ -2089,7 +2119,7 @@ functions addAllPrimitives(){ - +