0

Here's the code:

<html lang="en">
<head>
    <meta charset="utf-8">
        <script src="node_modules\aframe\dist\aframe.min.js" type="text/javascript"></script>
        <script type:"text/javascript">
            var sceneEl = document.querySelector('a-scene');
                AFRAME.registerComponent('loadchunk', {
                    init: function () {console.log('loadChunk initialized');
                    }
                });
            function loadChunk (ndx){
                var passId = "zChunk" + ndx;
                var zPos = ndx * 12;
                var addEl = document.createElement('a-entity');
                addEl.setAttribute("gltf-model", "#bound");
                addEl.object3D.position.set(0, 0, zPos);
                sceneEl.appendChild(addEl);
            }
            
            function initLoad (){
                var i;
                for(i=-13; i<12; i++){
                    loadChunk(i);
                }
            }
        </script>
</head>
<body>

    <a-scene>
        <a-assets>
            <a-asset-item id="bound" src="/models/boundery.gltf" ></a-asset-item>
        </a-assets>
        <a-sky color="#ECECEC"></a-sky>
    </a-scene>
    <script type="text/javascript">
    initLoad();
    </script>
</body>
</html>

Here's the error:

(index):18 Uncaught TypeError: Cannot read property 'appendChild' of null at loadChunk ((index):18) at initLoad ((index):24) at (index):38 loadChunk @ (index):18 initLoad @ (index):24 (anonymous) @ (index):38

Don't know what I don't know. :P

Ten Zen
  • 3
  • 4
  • `document.querySelector('a-scene')` didn't find the element, because the element doesn't exist at the time the script is executed. – Teemu Jul 30 '20 at 13:27
  • Thank you so much! For now I am just moving my code to the bottom of the body of the page. – Ten Zen Jul 30 '20 at 14:29

0 Answers0