BabylonJs加载stl文件,报错Uncaught RangeError: Invalid typed array length: 9065025882

初学BabylonJs,遇到一个问题,当我想要加载一个stl文件时,控制台报错Uncaught RangeError: Invalid typed array length: 9065025882

请各位指教一下如何解决这个错误

来自Babylon PlayGround的代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
            body{
                overflow: hidden;
                width: 100%;
                height: 100%;
            }

            #renderCanvas{
                width: 100%;
                height: 100%;
            }
        </style>
        <script src="../static/js/jquery-3.4.0.min.js" type="text/javascript"></script>
        <script src="../static/js/babylon.js" type="text/javascript"></script>
        <!-- <script src="../static/js/babylon.stlFileLoader.min.js" type="text/javascript"></script> -->
        <script src="../static/js/babylonjs.loaders.js" type="text/javascript"></script>
    </head>
    <body>
        <canvas id="renderCanvas"></canvas>
    </body>

    <script>
        // 从上面的HTML中取得canvas元素
        var canvas = document.getElementById("renderCanvas");       
        //  加载BABYLON 3D 引擎
        var engine = new BABYLON.Engine(canvas, true);

        var createScene = function () {    
            // Create a scene.
            var scene = new BABYLON.Scene(engine);

            var cam = new BABYLON.ArcRotateCamera("ArcRotateCamera", 0, 0, 1, new BABYLON.Vector3(0, 1, 0), scene);
            cam.attachControl(canvas);

            // Create a default skybox with an environment.
            var hdrTexture = BABYLON.CubeTexture.CreateFromPrefilteredData("textures/environment.dds", scene);
            var currentSkybox = scene.createDefaultSkybox(hdrTexture, true);

            // Append glTF model to scene.
            BABYLON.SceneLoader.Append("/", "bunny.stl", scene, function (scene) {
            // Create a default arc rotate camera and light.
            scene.createDefaultCameraOrLight(true, true, true);

            // The default camera looks at the back of the asset.
            // Rotate the camera by 180 degrees to the front of the asset.
            scene.activeCamera.alpha += Math.PI;
            });

            return scene;

        };


        var scene = createScene();

        engine.runRenderLoop(function() {  
            scene.render();  
        });

        window.addEventListener("resize", function () {     
            engine.resize();
        });

    </script>
</html>

来自其他网址的代码

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
            body{
                overflow: hidden;
                width: 100%;
                height: 100%;
            }

            #renderCanvas{
                width: 100%;
                height: 100%;
            }
        </style>
        <script src="../static/js/jquery-3.4.0.min.js" type="text/javascript"></script>
        <script src="../static/js/babylon.js" type="text/javascript"></script>
        <!-- <script src="../static/js/babylon.stlFileLoader.min.js" type="text/javascript"></script> -->
        <script src="../static/js/babylonjs.loaders.js" type="text/javascript"></script>
    </head>
    <body>
        <canvas id="renderCanvas"></canvas>
    </body>

    <script>
        var canvas = document.getElementById("renderCanvas");
        var engine = new BABYLON.Engine(canvas, true);

        var createScene = function() {

            // This creates a basic Babylon Scene object (non-mesh)
            var scene = new BABYLON.Scene(engine);

            new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
            var cam = new BABYLON.ArcRotateCamera("ArcRotateCamera", 0, 0, 1, new BABYLON.Vector3(0, 1, 0), scene);
            cam.attachControl(canvas);

            var loader = new BABYLON.AssetsManager(scene);

            var position = 0;
            var pos = function(t) {
                t.loadedMeshes.forEach(function(m) {
                    m.position.x -= position;
                });
                position += 1;
            };

            var bunny = loader.addMeshTask("bunny", "", "/", "bunny.stl");
            bunny.onSuccess = pos;

            loader.onFinish = function() {
                engine.runRenderLoop(function() {
                    scene.render();
                });
            };

            loader.load();

            return scene;

        };

        var scene = createScene();

        engine.runRenderLoop(function() {
            scene.render();
        });

        // Resize
        window.addEventListener("resize", function() {
            engine.resize();
        });


    </script>
</html>

这两份代码运行均报错

来自Babylon PlayGround的代码报错的详细内容如下:

stlFileLoader.ts:183 Uncaught RangeError: Invalid typed array length: 9065025882
    at new Float32Array (<anonymous>)
    at STLFileLoader../STL/stlFileLoader.ts.STLFileLoader._parseBinary (stlFileLoader.ts:183)
    at STLFileLoader../STL/stlFileLoader.ts.STLFileLoader.importMesh (stlFileLoader.ts:61)
    at STLFileLoader../STL/stlFileLoader.ts.STLFileLoader.load (stlFileLoader.ts:125)
    at babylon.js:16
    at f (babylon.js:16)
    at XMLHttpRequest.p (babylon.js:16)
./STL/stlFileLoader.ts.STLFileLoader._parseBinary   @   stlFileLoader.ts:183
./STL/stlFileLoader.ts.STLFileLoader.importMesh @   stlFileLoader.ts:61
./STL/stlFileLoader.ts.STLFileLoader.load   @   stlFileLoader.ts:125
(anonymous) @   babylon.js:16
f   @   babylon.js:16
p   @   babylon.js:16
XMLHttpRequest.send (async)     
e.send  @   babylon.js:16
s   @   babylon.js:16
p   @   babylon.js:16
e.LoadFile  @   babylon.js:16
m   @   babylon.js:16
e   @   babylon.js:16
ge.b.OfflineProviderFactory @   babylon.js:16
e._loadData @   babylon.js:16
e.Append    @   babylon.js:16
createScene @   test1.html:45
(anonymous) @   test1.html:59

来自其他网站的代码报错的详细内容如下:

stlFileLoader.ts:183 Uncaught RangeError: Invalid typed array length: 9065025882
    at new Float32Array (<anonymous>)
    at STLFileLoader../STL/stlFileLoader.ts.STLFileLoader._parseBinary (stlFileLoader.ts:183)
    at STLFileLoader../STL/stlFileLoader.ts.STLFileLoader.importMesh (stlFileLoader.ts:61)
    at babylon.js:16
    at f (babylon.js:16)
    at XMLHttpRequest.p (babylon.js:16)
./STL/stlFileLoader.ts.STLFileLoader._parseBinary   @   stlFileLoader.ts:183
./STL/stlFileLoader.ts.STLFileLoader.importMesh @   stlFileLoader.ts:61
(anonymous) @   babylon.js:16
f   @   babylon.js:16
p   @   babylon.js:16
XMLHttpRequest.send (async)     
e.send  @   babylon.js:16
s   @   babylon.js:16
p   @   babylon.js:16
e.LoadFile  @   babylon.js:16
m   @   babylon.js:16
e   @   babylon.js:16
ge.b.OfflineProviderFactory @   babylon.js:16
e._loadData @   babylon.js:16
e.ImportMesh    @   babylon.js:16
t.runTask   @   babylon.js:16
e.run   @   babylon.js:16
e._runTask  @   babylon.js:16
e.load  @   babylon.js:16
createScene @   test2.html:59
(anonymous) @   test2.html:65
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!