pmndrs / drei

🥉 useful helpers for react-three-fiber
https://drei.pmnd.rs/
MIT License
7.85k stars 641 forks source link

useGLTF在安卓环境下报错 #1924

Open bieao411327 opened 2 months ago

bieao411327 commented 2 months ago

Uncaught (in promise) {"name": "TypeError", "message": "Cannot read property 'length' of undefined", "stack": "TypeError: Cannot read property 'length' of undefined\n at http://localhost:13000/clientDist_1.6.5.69/925.4a9527e1.async.js:910:1197"},使用useGLTF加载glb文件时,在ios环境下是可以运行的,但是在安卓环境下就报错无法使用,是什么原因

bieao411327 commented 2 months ago

原因: useGLTF方法加载glb模型时需要返回二进制数据,也就是ArrayBuffer,在浏览器和IOS环境中使用本地路径加载glb文件是没问题的,但是在安卓系统中,加载本地的glb文件返回的是base64字符串,所以会报以上错误 解决方案: 1、将本地的glb文件放到远程服务器上,使用域名加载,安卓就可以读出二进制文件 2、修改useGLTF方法,判断在安卓环境下将base64改为ArrayBuffer