From 89ee270eecd98c3e570ff16bb04478951678ce06 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Thu, 19 Jan 2023 22:54:18 +0100 Subject: [PATCH] snapping sound and fixed sky --- index.html | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index c68200c..3167d13 100644 --- a/index.html +++ b/index.html @@ -1960,7 +1960,7 @@ AFRAME.registerComponent('snap-on-pinchended', { init: function(){ let el = this.el this.el.addEventListener('released', function (event) { - if (tile_snapping_enabled) { + if (tile_snapping_enabled) { // might generalize the name as now used for compound primitives too el.setAttribute("rotation", "0 0 0") // could limit to an axis or two, e.g here y axis probably should be kept or at least adjust to next 1/6th rotation // could snap to invisible grid too, e.g every 1 or 1/10th unit @@ -1972,6 +1972,17 @@ AFRAME.registerComponent('snap-on-pinchended', { // but then if not, what? move to another of the closest 6th closest points? (2 vertical, 2 horizontal, 2 depth) or even 8th with diagonales? // if not? now what? move until there is a free spot? el.setAttribute("position", AFRAME.utils.coordinates.stringify(pos)) + + if (el.className == "compound_object"){ + let thresholdDistance = 0.2 // based on object size + targets.filter( i => ( + (i.className == el.className) + && el.getAttribute("position").distanceTo(i.getAttribute("position")) == 0.2) + && el.getAttribute("position").y == i.getAttribute("position").y + && el.getAttribute("position").z == i.getAttribute("position").z + ).map( _ => document.querySelector("#snapping-sound").components.sound.playSound() ) + } // very restrictive, also doesn't repulse away + // if works, generalize and add to https://git.benetou.fr/utopiah/text-code-xr-engine/issues/66 // should come back from emit('released') // could rely on getClosestTilesSnappingPosition() @@ -2017,13 +2028,14 @@ function rescalePlace(scale = 10, yoffset=-1){ function addScreenshot(){ screenshotcanvas = document.querySelector('a-scene').components.screenshot.getCanvas('perspective') - var sel = document.createElement("a-image") + var sel = document.createElement("a-image") // could use a flat box instead, or use it as a frame AFRAME.scenes[0].appendChild(sel) sel.setAttribute("src", screenshotcanvas.toDataURL() ) sel.setAttribute("height", .1) sel.setAttribute("width", .2) sel.setAttribute("position", "0 1.4 -0.1") targets.push(sel) + return sel } function newPrimitiveWithOutline( name="box", position="0 0 0", scale=".1 .1 .1" ){ @@ -2042,7 +2054,7 @@ 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.id = "compound_object_" + Date.now() el.className = "compound_object" let parts = [] parts.push( newPrimitiveWithOutline("box", "0 0 0", ".2 .1 .1") ) @@ -2053,6 +2065,8 @@ function addCompoundPrimitiveExample(position="0 1.4 -0.2"){ parts.push( newPrimitiveWithOutline("box", "-.125 0 -0.0375", ".05 .05 .025") ) parts.map( p => el.appendChild(p) ) targets.push(el) + el.setAttribute('snap-on-pinchended', true) // could set the parameter here, e.g sound if close to same type + return el } function addPrimitive( name, position="0 1.4 -0.2" ){ @@ -2063,6 +2077,7 @@ function addPrimitive( name, position="0 1.4 -0.2" ){ el.className = "template_object" targets.push(el) // should have a dedicated cloning component activated on primary pinchstarted + return el } function addAllPrimitives(){ @@ -2076,12 +2091,20 @@ function addAllPrimitives(){ .map( (i,j) => addPrimitive( i, ""+ j/7 + " 1.4 -0.5" ) ) } +function startExperience(){ + //AFRAME.scenes[0].enterVR(); + document.querySelector("#snapping-sound").components.sound.playSound(); + document.querySelector("#mainbutton").style.display = "none" +} + // could change model opacity based on hand position, fading out when within a (very small here) safe space
+ + + + @@ -2114,18 +2138,16 @@ function addAllPrimitives(){ - - - - + + + + - + + - - -