|
26 | 26 |
|
27 | 27 | <a-entity position="0 .6 4">
|
28 | 28 | <a-camera>
|
29 |
| - <a-entity cursor |
| 29 | + <a-entity raycaster="far: 30; objects: .intersectable" |
| 30 | + cursor |
30 | 31 | geometry="primitive: ring; radiusOuter: 0.015;
|
31 | 32 | radiusInner: 0.01; segmentsTheta: 32"
|
32 | 33 | material="color: #283644; shader: flat"
|
33 |
| - raycaster="far: 30" |
34 | 34 | position="0 0 -0.75"></a-entity>
|
35 | 35 | </a-camera>
|
36 | 36 | </a-entity>
|
37 | 37 |
|
38 | 38 | <a-entity position="-3.5 1 0">
|
39 |
| - <a-entity mixin="red cube"> |
| 39 | + <a-entity mixin="red cube" |
| 40 | + class="intersectable"> |
40 | 41 | <a-animation begin="click" attribute="position" from="0 0 0"
|
41 | 42 | to="0 0 -10" dur="2000" fill="both"></a-animation>
|
42 | 43 | </a-entity>
|
43 | 44 | </a-entity>
|
44 | 45 |
|
45 |
| - <a-entity position="-1 1 0"> |
46 |
| - <a-entity mixin="green cube" |
| 46 | + <a-entity position="0 1 1"> |
| 47 | + <a-entity id="invisibleCube" |
| 48 | + mixin="cube" |
| 49 | + material="color: grey; opacity: 0.3; transparent: true" |
| 50 | + scale="1 1 0.1"> |
| 51 | + <a-animation begin="click" attribute="rotation" to="0 360 0" |
| 52 | + easing="linear" dur="2000" fill="backwards"></a-animation> |
| 53 | + </a-entity> |
| 54 | + </a-entity> |
| 55 | + |
| 56 | + <a-entity position="0 1 0"> |
| 57 | + <a-entity id="foregroundCube" |
| 58 | + class="intersectable" |
| 59 | + mixin="green cube" |
47 | 60 | sound__1="on: click; src: #blip1;"
|
48 | 61 | sound__2="on: mouseenter; src: #blip2;">
|
49 | 62 | <a-animation begin="click" attribute="rotation" to="0 360 0"
|
|
60 | 73 | </a-entity>
|
61 | 74 | </a-entity>
|
62 | 75 |
|
| 76 | + <a-entity position="0 1 -3"> |
| 77 | + <a-entity id="backgroundCube" |
| 78 | + class="intersectable" |
| 79 | + mixin="green cube"> |
| 80 | + <a-animation begin="click" attribute="rotation" to="0 360 0" |
| 81 | + easing="linear" dur="2000" fill="backwards"></a-animation> |
| 82 | + </a-entity> |
| 83 | + </a-entity> |
| 84 | + |
63 | 85 | <a-entity position="3.5 1 0" rotation="0 45 0">
|
64 |
| - <a-entity mixin="blue cube"> |
| 86 | + <a-entity mixin="blue cube" |
| 87 | + class="intersectable"> |
65 | 88 | <a-animation begin="click" fill="forwards" repeat="1"
|
66 | 89 | direction="alternate" attribute="position" from="0 0 0"
|
67 | 90 | to="15 0 0" dur="2000"></a-animation>
|
68 | 91 | </a-entity>
|
69 | 92 | </a-entity>
|
70 | 93 |
|
71 |
| - <a-entity mixin="yellow cube" position="0 3 0" class="clickable" |
| 94 | + <a-entity mixin="yellow cube" position="0 3 -3" class="intersectable clickable" |
72 | 95 | rotation="0 45 0" scale=".5 .5 .5"></a-entity>
|
73 | 96 | </a-scene>
|
74 | 97 |
|
|
98 | 121 | window.top.postMessage({type: 'navigate', data: {url: href}}, '*');
|
99 | 122 | })
|
100 | 123 | }
|
| 124 | + |
| 125 | + // testing mouseenter and mouseleave |
| 126 | + var foregroundCube = document.querySelector('#foregroundCube'); |
| 127 | + foregroundCube.addEventListener('mouseenter', function (evt) { |
| 128 | + foregroundCube.setAttribute('mixin','cube cube-hovered') |
| 129 | + }) |
| 130 | + foregroundCube.addEventListener('mouseleave', function (evt) { |
| 131 | + foregroundCube.setAttribute('mixin','green cube') |
| 132 | + }) |
| 133 | + foregroundCube.addEventListener('mousedown', function (evt) { |
| 134 | + foregroundCube.setAttribute('mixin','cube cube-selected') |
| 135 | + }) |
| 136 | + foregroundCube.addEventListener('mouseup', function (evt) { |
| 137 | + foregroundCube.setAttribute('mixin','cube cube-hovered') |
| 138 | + }) |
| 139 | + foregroundCube.addEventListener('click', function (evt) { |
| 140 | + var scene = document.querySelector('a-scene'); |
| 141 | + var clickRing = document.createElement('a-entity'); |
| 142 | + clickRing.id = 'clickRing-'+new Date().getTime(); |
| 143 | + clickRing.setAttribute('material','color: magenta; transparent: true; opacity: 0.6'); |
| 144 | + clickRing.setAttribute('geometry','primitive: ring; radius-inner: 0.5; radius-outer: 0.6'); |
| 145 | + clickRing.setAttribute('position',evt.detail.intersection.point); |
| 146 | + var opacityAnimation = document.createElement('a-animation'); |
| 147 | + opacityAnimation.setAttribute('attribute','material.opacity'); |
| 148 | + opacityAnimation.setAttribute('to',0); |
| 149 | + opacityAnimation.setAttribute('duration','250'); |
| 150 | + opacityAnimation.setAttribute('easing','ease-out-quad'); |
| 151 | + var scaleAnimation = document.createElement('a-animation'); |
| 152 | + scaleAnimation.setAttribute('attribute','scale'); |
| 153 | + scaleAnimation.setAttribute('to','3 3 3'); |
| 154 | + scaleAnimation.setAttribute('duration','250'); |
| 155 | + scaleAnimation.setAttribute('easing','ease-out-quad'); |
| 156 | + var onAnimationEnd = function () { |
| 157 | + scene.removeChild(document.querySelector('#'+clickRing.id)) |
| 158 | + } |
| 159 | + scaleAnimation.addEventListener('animationend', onAnimationEnd.bind(this)) |
| 160 | + clickRing.appendChild(opacityAnimation); |
| 161 | + clickRing.appendChild(scaleAnimation); |
| 162 | + scene.appendChild(clickRing); |
| 163 | + }) |
101 | 164 | })();
|
102 | 165 | </script>
|
103 | 166 | </body>
|
|
0 commit comments