0
votes

I'm using AR.js and Aframe, so that when I click my model it loads a URL.

The below works fine when I use a basic box shape but when I add a 3D model the model takes a few seconds to load and then executes the document.location.href function once loaded but I only want to trigger the click when the model is clicked?

<html>
    <head>
      <script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
      <script src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.6.0/aframe/build/aframe-ar.js"></script>

      <script>
        AFRAME.registerComponent('mas', {

          init: function () {
            var data = this.data;
            var el = this.el;  // <a-box>

            el.addEventListener('click', function () {
              console.log('click');
              masClick();
            });

            function masClick() {
              document.location.href = "http://www.google.com";
            };
          }
        });
      </script>

    </head>

    <body style='margin : 0px; overflow: hidden;'>

    <a-scene embedded arjs='sourceType: webcam;' cursor="rayOrigin: mouse">

      <a-entity rotation="0 90 0" dur="7000" mas>
        <a-gltf-model src="scene.gltf" scale="0.05 0.05 0.05" position='0 0.5 0' >
          <a-animation 
             dur="8000" 
             attribute="rotation" 
             to="0 360 0" 
             repeat="indefinite">
          </a-animation>   
        </a->
      </a-entity>

      <a-marker-camera preset='hiro'></a-marker-camera>
    </a-scene> 

    </body>
    </html>
1

1 Answers

0
votes

The cursor component works when put within the <a-marker> entity:

<a-marker preset='hiro' cursor="rayOrigin: mouse">
  .....
</a-marker>

codepen here.