diff --git a/index.html b/index.html index bf56927..12a5549 100644 --- a/index.html +++ b/index.html @@ -2091,6 +2091,31 @@ function addCompoundPrimitiveExample(position="0 1.4 -0.2"){ return el } +function collideTwoElements(elementA, elementB, compatible=true){ // dropping b on a + let a = elementA.object3D.position + let b = elementB.object3D.position + // should rely on starting position otherwise it will be too small + // tested without hand tracking so a "jump" from source to target + let dir = new THREE.Vector3() + let vol = new THREE.Box3 + dir.subVectors( a, b ).normalize() + if (!compatible){ + elementB.object3D.position.add( dir.multiplyScalar(-1)) // repulsive + } else { + elementB.object3D.position.copy( a ) + vol.setFromObject( elA.object3D ) + elementB.object3D.position.x += (vol.max.x - vol.min.x) // snapping equivalent + // then can also test for larger structures + // e.g H2O chain "../content/WaterBottle.glb" // by sirkitree (CC-BY) + } +} +/* testing +elA = addBlockCodeExample('O', '-0.2 1.4 -0.2') +elB = addBlockCodeExample('H') // need few milliseconds to create before testing, so no copy/paste +collideTwoElements(elA, elB) +collideTwoElements(elA, elB, false) +*/ + function addBlockCodeExample(text="hi", pos="0 1.4 -0.2", color="black", outlineColor="white"){ let el = addNewNote( text ) el.setAttribute("color", color) @@ -2286,20 +2311,11 @@ consider pick then apply, i.e changeColorLastId() but for next Id - - - - - - - - - - + + + + - - -