Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Aframe AR.js Show A Preloading Screen Till All The Assets Loads And Renders

I Want To Show A Preloading Screen Till All Assets Loads And Renders.

I Tried Using Assets Event loaded but its not working . When We Augment 3d Model , Image and video , So These Assets Are Almost 50-60mb . So it takes time to load the assets and augment . The video when we augment for 4-8 seconds the black screen comes and plays,if the network is slow (In inspect Network Tab Select 3G Slow We Test). Please Edit My Code in Glitch

<!DOCTYPE html>
    <html lang="en">
       <head>
          <title>Hello!</title>
          <meta charset="utf-8">
          <meta http-equiv="X-UA-Compatible" content="IE=edge">
          <script type="text/javascript" src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
          <script type="text/javascript" src="https://cdn.rawgit.com/jeromeetienne/AR.js/1.7.2/aframe/build/aframe-ar.min.js"></script>
          <script type="text/javascript" src="https://cdn.rawgit.com/donmccurdy/aframe-extras/v6.0.0/dist/aframe-extras.min.js"></script>
          <script src="https://unpkg.com/[email protected]/dist/aframe-animation-component.min.js"></script>
          <script>
             AFRAME.registerComponent("vidhandler", {
              init: function () {
                // Set up initial state and variables.
                this.toggle = false;
                this.vid = document.querySelector("#vid");
                this.vid.pause();
                console.log('************* Vid Paused');
              },
              tick: function () {
                if (this.el.object3D.visible == true) {
                  if (!this.toggle) {
                    this.toggle = true;
                    this.vid.play();
                    console.log('************* Vid Play');
                  }
                } else {
                  this.toggle = false;
                  this.vid.pause();
                  //console.log('************* Vid Paused');
                }
              }
             });    
          </script>
       </head>
       <body>
          <a-scene vr-mode-ui="enabled: false" artoolkit='sourceType: webcam; detectionMode: mono; maxDetectionRate: 90;' arjs='debugUIEnabled: false;detectionMode: mono_and_matrix; matrixCodeType: 3x3;'>
             <!--  ALL  ASSETS  -->
             <a-assets>
        <!--   3D MODEL -->
                <a-entity  id="model" src="https://cdn.glitch.com/c3106e6c-98cb-40e4-b0c1-85257680d25a%2Fygark.glb?v=1564472468760" crossorigin="anonymous" rotation="-90 0 -90">
                </a-entity>
        <!--   VIDEO -->
                <video preload="auto" id="vid" response-type="arraybuffer" loop="false" crossorigin webkit-playsinline playsinline controls>
                   <source src="https://cdn.glitch.com/c3106e6c-98cb-40e4-b0c1-85257680d25a%2Fvid.mp4?v=1564472320471" type="video/mp4">
                </video>
        <!--   IMAGE -->
                <img id="img" src="https://cdn.glitch.com/c3106e6c-98cb-40e4-b0c1-85257680d25a%2Fsun.png?v=1564472507237">
             </a-assets>
             <!--  ALL  ASSETS  -->
             <a-marker type="pattern" preset="hiro" vidhandler>
                <a-entity position="0 0 0">
                   <a-video width="2" height="2" rotation="-90 0 0" material='transparent:true;shader:flat;side:double;src:#vid'></a-video>
                </a-entity>
                <a-image width="2" height="2" material='transparent:true;shader:flat;side:double;src:#img' position="2 0 0" rotation="-90 0 0"></a-image>
                <a-entity position="-1.5 0 0" gltf-model="#model"  material='transparent:true;shader:flat;side:double;metelness:2' rotation="0 0 0" scale="0.5 0.5 0.5"  shadow="receive: false"  >
                </a-entity>
             </a-marker>
             <a-entity camera>
                <a-entity cursor="rayOrigin: mouse;fuse: false;"></a-entity>
             </a-entity>
          </a-scene>
       </body>
    </html>

Asset loaded event is not working . Please Edit My Code in Glitch

Thanks In Advance

like image 248
Aryan Avatar asked Nov 06 '22 15:11

Aryan


1 Answers

There are a couple different options.

  1. Aframe has a built in loading screen that is enabled within the <a-scene> declaration
<a-scene loading-screen="dotsColor: red; backgroundColor: black"></a-scene>
  1. Another option is to follow the steps in the response from Noam Almosnino
  2. Use a component like, Aframe Preloader

    Note: I am not associated with this component and have not tested it. Please see the demo page for some examples

Update

Based on your comment (below) I would recommend #2 (above)

create a listener for the scene's loaded event

document.addEventListener('DOMContentLoaded', function() {
    var scene = document.querySelector('a-scene');
    scene.addEventListener('loaded', function (e) {
        // hide splash screen
    });
});
like image 116
Hermes Avatar answered Nov 14 '22 23:11

Hermes