@kimap/indoor-positioning-sdk-vue2 4.2.3 → 4.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/KMUtil.js +1 -0
- package/src/core/KimapSDK.js +37 -19
- package/src/core/SceneCore.js +5 -7
package/package.json
CHANGED
package/src/KMUtil.js
CHANGED
package/src/core/KimapSDK.js
CHANGED
|
@@ -852,11 +852,23 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
852
852
|
|
|
853
853
|
// 等待loader加载完成后再加载模型
|
|
854
854
|
loaderPromise.then(function(loader) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
function(
|
|
858
|
-
//
|
|
859
|
-
|
|
855
|
+
// 先验证URL是否返回HTML(只拦截HTML,允许404等错误通过)
|
|
856
|
+
return fetch(modelUrl, { method: 'HEAD' })
|
|
857
|
+
.then(function(response) {
|
|
858
|
+
// 只检查Content-Type,不检查HTTP状态码
|
|
859
|
+
// 404等错误让OBJLoader自己处理
|
|
860
|
+
var contentType = response.headers.get('content-type');
|
|
861
|
+
if (response.ok && contentType && contentType.includes('text/html')) {
|
|
862
|
+
throw new Error('URL返回HTML而不是3D模型文件: ' + modelUrl);
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// 验证通过或404等错误,继续加载(让loader处理)
|
|
866
|
+
return new Promise(function(resolveLoad, rejectLoad) {
|
|
867
|
+
loader.load(
|
|
868
|
+
modelUrl,
|
|
869
|
+
function(result) {
|
|
870
|
+
// GLTF/GLB格式返回的是gltf对象,需要提取scene
|
|
871
|
+
var obj = (ext === '.glb' || ext === '.gltf') ? result.scene : result;
|
|
860
872
|
// 应用旋转
|
|
861
873
|
obj.rotation.set(
|
|
862
874
|
furniture.rotation.x,
|
|
@@ -916,22 +928,28 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
916
928
|
furniture.position.z
|
|
917
929
|
);
|
|
918
930
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
931
|
+
obj.userData = {
|
|
932
|
+
type: 'furniture',
|
|
933
|
+
furnitureId: furniture.id,
|
|
934
|
+
furnitureType: furniture.type
|
|
935
|
+
};
|
|
936
|
+
|
|
937
|
+
resolveLoad(obj);
|
|
938
|
+
},
|
|
939
|
+
undefined,
|
|
940
|
+
function(error) {
|
|
941
|
+
console.error('❌ 家具模型加载失败:', furniture.type, error);
|
|
942
|
+
rejectLoad(error);
|
|
943
|
+
}
|
|
944
|
+
);
|
|
945
|
+
});
|
|
946
|
+
})
|
|
947
|
+
.then(function(obj) {
|
|
925
948
|
resolve(obj);
|
|
926
|
-
}
|
|
927
|
-
undefined,
|
|
928
|
-
function(error) {
|
|
929
|
-
console.error('❌ 家具模型加载失败:', furniture.type, error);
|
|
930
|
-
reject(error);
|
|
931
|
-
}
|
|
932
|
-
);
|
|
949
|
+
});
|
|
933
950
|
}).catch(function(error) {
|
|
934
|
-
console.error('❌
|
|
951
|
+
console.error('❌ 家具模型URL验证或加载失败:', furniture.type, error.message);
|
|
952
|
+
console.error('URL:', modelUrl);
|
|
935
953
|
reject(error);
|
|
936
954
|
});
|
|
937
955
|
});
|
package/src/core/SceneCore.js
CHANGED
|
@@ -407,19 +407,17 @@ SceneCore.prototype._loadOBJFile = function(url, objLoader, resolve, reject) {
|
|
|
407
407
|
|
|
408
408
|
console.log('加载OBJ文件...', url);
|
|
409
409
|
|
|
410
|
-
// 先验证URL
|
|
410
|
+
// 先验证URL是否返回HTML(只拦截HTML,允许404等错误通过)
|
|
411
411
|
fetch(url, { method: 'HEAD' })
|
|
412
412
|
.then(function(response) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
|
|
413
|
+
// 只检查Content-Type,不检查HTTP状态码
|
|
414
|
+
// 404等错误让OBJLoader自己处理
|
|
417
415
|
var contentType = response.headers.get('content-type');
|
|
418
|
-
if (contentType && contentType.includes('text/html')) {
|
|
416
|
+
if (response.ok && contentType && contentType.includes('text/html')) {
|
|
419
417
|
throw new Error('URL返回的是HTML页面而不是OBJ文件,请检查URL是否正确');
|
|
420
418
|
}
|
|
421
419
|
|
|
422
|
-
//
|
|
420
|
+
// 验证通过或404等错误,继续加载(让loader处理)
|
|
423
421
|
objLoader.load(
|
|
424
422
|
url,
|
|
425
423
|
function(object) {
|