diff --git a/assets/img/cursor-mesh.png b/assets/img/cursor-mesh.png new file mode 100644 index 0000000..1b8aa95 Binary files /dev/null and b/assets/img/cursor-mesh.png differ diff --git a/src/components/cursor-mesh.js b/src/components/cursor-mesh.js new file mode 100644 index 0000000..ec4b2e6 --- /dev/null +++ b/src/components/cursor-mesh.js @@ -0,0 +1,44 @@ +/** + * Cursor mesh to show at intersection point with respective hand. + */ +AFRAME.registerComponent('cursor-mesh', { + schema: { + cursorEl: {type: 'selector'} + }, + + init: function () { + this.scenePivotEl = document.getElementById('scenePivot'); + }, + + tick: function () { + var cursor; + var cursorEl = this.data.cursorEl; + var el = this.el; + var i; + var intersection; + var intersectedEl; + var intersectionPoint; + var object3D = this.el.object3D; + var scenePivotEl = this.scenePivotEl; + + cursor = cursorEl.components.cursor; + if (!cursor) { return; } + + // Look for valid intersection target. + intersectedEl = cursorEl.components.cursor.intersectedEl; + if (intersectedEl) { + el.object3D.visible = true; + } else { + el.object3D.visible = false; + return; + } + + // Update cursor mesh. + intersection = cursorEl.components.raycaster.getIntersection(intersectedEl); + el.object3D.position.copy(intersection.point); + + if (scenePivotEl) { + el.object3D.rotation.copy(scenePivotEl.object3D.rotation); + } + } +}); diff --git a/src/index.html b/src/index.html index 7302c8f..e815a96 100644 --- a/src/index.html +++ b/src/index.html @@ -31,6 +31,7 @@ + @@ -70,6 +71,7 @@ + + + {% if not IS_PRODUCTION %} + {% endif %} diff --git a/src/templates/menu.html b/src/templates/menu.html index b23e9b1..b718386 100644 --- a/src/templates/menu.html +++ b/src/templates/menu.html @@ -78,7 +78,8 @@ + position="0 0 -0.005" + raycastable>