Skip to content

Commit d93a54e

Browse files
author
huiqi.xhq
committed
fix: upload obj dont auto load mtl
1 parent 4f324ce commit d93a54e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@
6363
}
6464

6565
//传递obj文件数据给渲染器
66-
function transferObj(txtObj, txtMtl) {
66+
function transferObj(txtObj, needFetchMtl) {
6767
const scene = txtObj ? ObjParser(txtObj) : '';
6868
scene.materialLibraries = scene.materialLibraries || [];
6969
$("selFile").disabled = false;
7070
const mtlPath = scene.materialLibraries[0];
71-
if (mtlPath) {//若存在引用mtl文件,则请求mtl文件
71+
if (needFetchMtl && mtlPath) {//若存在引用mtl文件,则请求mtl文件
7272
lastRequestPath = lastRequestPath.replace(REG_OBJ, mtlPath);
7373
fetch(lastRequestPath).then(r => r.text()).catch(ex => alert(ex)).then(txtMtl => {
7474
let mtl = null;
@@ -88,6 +88,7 @@
8888
mtl.forEach(m => {
8989
const imagePath = m.map_Kd.file;
9090
if (!imagePath) return;
91+
debugger
9192
if (mtl.__imageData[imagePath]) return;//若图片数据已经存在,说明之前请求过了,则忽略
9293

9394
fetch(lastRequestPath.replace(REG_MTL, imagePath)).then(r => r.blob()).catch(ex => alert(ex)).then(blob => {
@@ -126,7 +127,7 @@
126127
lastRequestPath = ABS_PATH + path;
127128
$("selFile").disabled = true;
128129
fetch(lastRequestPath).then(r => r.text()).catch(ex => alert(ex)).then(txt => {
129-
transferObj(txt);
130+
transferObj(txt,true);
130131
});
131132
}
132133
function uploadFile(evt) {
@@ -139,7 +140,7 @@
139140
let reader = new FileReader();
140141
reader.onload = function (e) {
141142
const txt = e.target.result;
142-
transferObj(txt);
143+
transferObj(txt,false);
143144
};
144145
reader.readAsText(f);
145146
}

0 commit comments

Comments
 (0)