Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GLTFLoader加载有额外纹理配置的gltf模型 #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions miniprogram/packageAPI/pages/ar/loaders/gltf-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ export function registerGLTFLoader(THREE) {
var json = this.json;
var options = this.options;
var textureLoader = this.textureLoader;
var URL = global.URL;
// var URL = global.URL;
var textureDef = json.textures[textureIndex];
var textureExtensions = textureDef.extensions || {};
var source;
Expand All @@ -1013,11 +1013,14 @@ export function registerGLTFLoader(THREE) {
if (source.bufferView !== undefined) {
sourceURI = parser.getDependency('bufferView', source.bufferView).then(function(bufferView) {
isObjectURL = true;
var blob = new global.Blob([bufferView], {
type: source.mimeType
});
sourceURI = URL.createObjectURL(blob);
return sourceURI
// var blob = new global.Blob([bufferView], {
// type: source.mimeType
// });
// sourceURI = URL.createObjectURL(blob);
// 小程序不支持 Blob 对象,使用 base64 编码的字符串来创建 data URI
const base64Str = wx.arrayBufferToBase64(bufferView);
sourceURI = `data:${source.mimeType};base64,${base64Str}`;
return sourceURI;
})
}
return Promise.resolve(sourceURI).then(function(sourceURI) {
Expand All @@ -1030,7 +1033,7 @@ export function registerGLTFLoader(THREE) {
})
}).then(function(texture) {
if (isObjectURL === true) {
URL.revokeObjectURL(sourceURI)
// URL.revokeObjectURL(sourceURI)
}
texture.flipY = false;
if (textureDef.name !== undefined) texture.name = textureDef.name;
Expand Down