@kimap/indoor-positioning-sdk-vue2 4.2.2 → 4.2.4
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/core/KimapSDK.js +39 -19
- package/src/core/SceneCore.js +38 -18
package/package.json
CHANGED
package/src/core/KimapSDK.js
CHANGED
|
@@ -852,11 +852,25 @@ 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是否有效
|
|
856
|
+
return fetch(modelUrl, { method: 'HEAD' })
|
|
857
|
+
.then(function(response) {
|
|
858
|
+
if (!response.ok) {
|
|
859
|
+
throw new Error('家具模型文件不存在 (HTTP ' + response.status + '): ' + modelUrl);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
var contentType = response.headers.get('content-type');
|
|
863
|
+
if (contentType && contentType.includes('text/html')) {
|
|
864
|
+
throw new Error('URL返回HTML而不是3D模型文件: ' + modelUrl);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// URL验证通过,开始加载模型
|
|
868
|
+
return new Promise(function(resolveLoad, rejectLoad) {
|
|
869
|
+
loader.load(
|
|
870
|
+
modelUrl,
|
|
871
|
+
function(result) {
|
|
872
|
+
// GLTF/GLB格式返回的是gltf对象,需要提取scene
|
|
873
|
+
var obj = (ext === '.glb' || ext === '.gltf') ? result.scene : result;
|
|
860
874
|
// 应用旋转
|
|
861
875
|
obj.rotation.set(
|
|
862
876
|
furniture.rotation.x,
|
|
@@ -916,22 +930,28 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
916
930
|
furniture.position.z
|
|
917
931
|
);
|
|
918
932
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
933
|
+
obj.userData = {
|
|
934
|
+
type: 'furniture',
|
|
935
|
+
furnitureId: furniture.id,
|
|
936
|
+
furnitureType: furniture.type
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
resolveLoad(obj);
|
|
940
|
+
},
|
|
941
|
+
undefined,
|
|
942
|
+
function(error) {
|
|
943
|
+
console.error('❌ 家具模型加载失败:', furniture.type, error);
|
|
944
|
+
rejectLoad(error);
|
|
945
|
+
}
|
|
946
|
+
);
|
|
947
|
+
});
|
|
948
|
+
})
|
|
949
|
+
.then(function(obj) {
|
|
925
950
|
resolve(obj);
|
|
926
|
-
}
|
|
927
|
-
undefined,
|
|
928
|
-
function(error) {
|
|
929
|
-
console.error('❌ 家具模型加载失败:', furniture.type, error);
|
|
930
|
-
reject(error);
|
|
931
|
-
}
|
|
932
|
-
);
|
|
951
|
+
});
|
|
933
952
|
}).catch(function(error) {
|
|
934
|
-
console.error('❌
|
|
953
|
+
console.error('❌ 家具模型URL验证或加载失败:', furniture.type, error.message);
|
|
954
|
+
console.error('URL:', modelUrl);
|
|
935
955
|
reject(error);
|
|
936
956
|
});
|
|
937
957
|
});
|
package/src/core/SceneCore.js
CHANGED
|
@@ -405,27 +405,47 @@ SceneCore.prototype._loadKimapFile = function(kimapUrl, themeUrl, objLoader, mtl
|
|
|
405
405
|
SceneCore.prototype._loadOBJFile = function(url, objLoader, resolve, reject) {
|
|
406
406
|
var self = this;
|
|
407
407
|
|
|
408
|
-
console.log('加载OBJ文件...');
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
function(
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
console.log('OBJ加载进度:', percent + '%');
|
|
408
|
+
console.log('加载OBJ文件...', url);
|
|
409
|
+
|
|
410
|
+
// 先验证URL是否返回正确的内容
|
|
411
|
+
fetch(url, { method: 'HEAD' })
|
|
412
|
+
.then(function(response) {
|
|
413
|
+
if (!response.ok) {
|
|
414
|
+
throw new Error('文件不存在或无法访问 (HTTP ' + response.status + ')');
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
var contentType = response.headers.get('content-type');
|
|
418
|
+
if (contentType && contentType.includes('text/html')) {
|
|
419
|
+
throw new Error('URL返回的是HTML页面而不是OBJ文件,请检查URL是否正确');
|
|
421
420
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
421
|
+
|
|
422
|
+
// URL验证通过,开始加载
|
|
423
|
+
objLoader.load(
|
|
424
|
+
url,
|
|
425
|
+
function(object) {
|
|
426
|
+
console.log('OBJ文件下载完成,开始处理...');
|
|
427
|
+
self._processLoadedModel(object, null, {});
|
|
428
|
+
resolve();
|
|
429
|
+
},
|
|
430
|
+
function(progress) {
|
|
431
|
+
if (progress.lengthComputable) {
|
|
432
|
+
var percent = (progress.loaded / progress.total * 100).toFixed(2);
|
|
433
|
+
console.log('OBJ加载进度:', percent + '%');
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
function(error) {
|
|
437
|
+
console.error('❌ OBJ文件加载失败:', error);
|
|
438
|
+
console.error('URL:', url);
|
|
439
|
+
reject(error);
|
|
440
|
+
}
|
|
441
|
+
);
|
|
442
|
+
})
|
|
443
|
+
.catch(function(error) {
|
|
444
|
+
console.error('❌ OBJ文件URL验证失败:', error.message);
|
|
425
445
|
console.error('URL:', url);
|
|
446
|
+
console.error('提示: 请确保URL指向有效的.obj文件');
|
|
426
447
|
reject(error);
|
|
427
|
-
}
|
|
428
|
-
);
|
|
448
|
+
});
|
|
429
449
|
};
|
|
430
450
|
|
|
431
451
|
/**
|