mardi 1 septembre 2020

Aframe issues with interactable components and a random function

I'm trying to create a entity in my Aframe's scene that once clicked bring me in another of my random pages. I'm a newbie, so my code is a patchwork that sometimes works and other times doesn't. I used this addon (https://github.com/silverslade/aframe_blender_exporter) to translate my 3d Blender scene in an "Aframe" page. It worked very well, so I added these javascript lines to my html in order to make my entity interactable and to create the random function:

<script>
    AFRAME.registerComponent('navigate-on-click', {
      schema: {
        url: {default: ''}
      },

      init: function () {
        var data = this.data;
        var el = this.el;

        el.addEventListener('click', function () {
          window.location.href = data.url;
        });
      }
    });
        </script>
        <script>
          var urls = [
             "http://www.findyourface.it/AuroraReinhard/AuroraReinhard.html",
             'http://www.findyourface.it/AmeliaEarthart/AmeliaEarthart.html',
             'http://www.findyourface.it/ElsaSchiapparelli/ElsaSchiapparelli.html',
             'http://www.findyourface.it/FedericaAngeli/FedericaAngeli.html'
          ];

          function goSomewhere() {
              var url = urls[Math.floor(Math.random()*urls.length)];
              window.location = url; // redirect
          }
          </script>

And I added this line in my entity:

<a-entity animation-mixer id="#segnalefreccia"  gltf-model="#segnalefreccia" scale="0.25 0.25 0.25" position="1.385 0.0 -14.0" visible="true" shadow="cast: false" onClick="goSomewhere(); return false;"></a-entity>

The first time you open the scene you have to click on it a lot of times but it eventually works, but in the following pages it stops working altogether. I think it’s because this is a Frankenstein monster of a code, but I didn't find a better way to make it.

Thank you for helping




Aucun commentaire:

Enregistrer un commentaire