【问题标题】:In Aframe AR.js Show A Preloading Screen Till All The Assets Loads And Renders在 Aframe AR.js 中显示一个预加载屏幕,直到所有资产加载和渲染
【发布时间】:2023-04-02 18:35:01
【问题描述】:

我想在所有资源加载和渲染之前显示一个预加载屏幕。

我尝试使用加载的资产事件,但它不起作用。当我们增强 3d 模型、图像和视频时,这些资产几乎是 50-60mb。因此加载资产和扩充需要时间。当我们增加 4-8 秒的视频时,黑屏出现并播放,如果网络很慢(在检查网络选项卡中选择 3G 慢我们测试)。 请编辑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/aframe-animation-component@5.1.2/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>

资产加载事件不起作用。请编辑My Code in Glitch

提前致谢

【问题讨论】:

    标签: javascript augmented-reality aframe ar.js jsartoolkit


    【解决方案1】:

    有几个不同的选项。

    1. &lt;a-scene&gt; 声明中启用的Aframe has a built in loading screen
    <a-scene loading-screen="dotsColor: red; backgroundColor: black"></a-scene>
    
    1. 另一种选择是按照response from Noam Almosnino 中的步骤进行操作
    2. 使用像Aframe Preloader 这样的组件

      注意:我与这个组件没有关联,也没有测试过。请see the demo page for some examples

    更新

    根据您的评论(如下),我会推荐#2 (above)

    为场景的加载事件创建一个监听器

    document.addEventListener('DOMContentLoaded', function() {
        var scene = document.querySelector('a-scene');
        scene.addEventListener('loaded', function (e) {
            // hide splash screen
        });
    });
    

    【讨论】:

    • 1. Aframe 9(版本)的 Aframe 加载屏幕 ID,但我使用的是 Aframe 8 .....所以在 8 中没有内置加载屏幕......
    猜你喜欢
    • 2019-11-24
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2021-08-04
    • 1970-01-01
    相关资源
    最近更新 更多