zf.xin 2019-07-01 16:47 采纳率: 0%
浏览 1395

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
  • 写回答

2条回答 默认 最新

  • #麻辣小龙虾# 2022-04-26 15:37
    关注

    img


    我也遇到了,我这边是导入gltf模型文件报错了。

    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?