engine
engine copied to clipboard
请问该如何正确加载用户通过input[type=file]选择的模型文件?
我的思路
获取到File对象后,通过
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function () {
//当读取完成之后会回调这个函数,然后此时文件的内容存储到了result中。
engine.resourceManager.load<GLTFResource>(this.result);
};
但是会解析错误
请问该如何正确加载呢?
@zhuxudong 后面把 glTFParser export 出去才可以吧
内置的 parser 也不支持解析 file,可以先把file 转成blob url 解决
file 转成 json 更直接一点吧
内置的 parser 也不支持解析 file,可以先把file 转成blob url 解决
好的,学习官方的代码解决了。https://github.com/oasis-engine/oasis-engine.github.io/blob/main/src/pages/gltf-viewer.tsx
@zhuxudong 这个功能做一些本地工具挺常用,加个 playground 吧
Convert to discussion.