@kimap/indoor-positioning-sdk-vue2 4.2.0 → 4.2.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimap/indoor-positioning-sdk-vue2",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Vue2自包含室内定位SDK - 完全兼容Webpack3+Babel6 | Vue2 Self-Contained Indoor Positioning SDK",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -671,10 +671,169 @@ KimapSDK.prototype._loadFurnitureModels = function(kidataObj) {
671
671
  this.core.scene.add(this.furnitureGroup);
672
672
  }
673
673
 
674
+ // 清空现有家具
675
+ while (this.furnitureGroup.children.length > 0) {
676
+ var child = this.furnitureGroup.children[0];
677
+ this.furnitureGroup.remove(child);
678
+
679
+ // 释放资源
680
+ if (child.geometry) child.geometry.dispose();
681
+ if (child.material) {
682
+ if (Array.isArray(child.material)) {
683
+ child.material.forEach(function(m) { m.dispose(); });
684
+ } else {
685
+ child.material.dispose();
686
+ }
687
+ }
688
+ }
689
+
690
+ // 优先使用dataUrl,如果不存在则使用serverUrl(兼容旧版本)
691
+ var serverUrl = kidataObj.dataUrl || kidataObj.serverUrl;
692
+ var loadPromises = [];
693
+ var loadedCount = 0;
694
+ var failedCount = 0;
695
+
674
696
  console.log('📦 开始加载', kidataObj.furnitures.length, '个家具模型');
675
697
 
676
- // 简化版本:暂时返回成功,实际加载逻辑可以后续完善
677
- return Promise.resolve({ loaded: 0, failed: 0, message: '家具加载功能需要完整实现' });
698
+ // 加载每个家具模型
699
+ kidataObj.furnitures.forEach(function(furniture) {
700
+ var promise = self._loadSingleFurniture(furniture, serverUrl)
701
+ .then(function(mesh) {
702
+ if (mesh) {
703
+ self.furnitureGroup.add(mesh);
704
+ loadedCount++;
705
+ } else {
706
+ failedCount++;
707
+ }
708
+ })
709
+ .catch(function(error) {
710
+ console.error('加载家具模型失败:', furniture.type, error);
711
+ failedCount++;
712
+ });
713
+
714
+ loadPromises.push(promise);
715
+ });
716
+
717
+ return Promise.all(loadPromises).then(function() {
718
+ return { loaded: loadedCount, failed: failedCount };
719
+ });
720
+ };
721
+
722
+ /**
723
+ * 加载单个家具模型
724
+ * @private
725
+ * @param {Object} furniture - 家具数据
726
+ * @param {string} serverUrl - 模型服务器URL
727
+ * @returns {Promise<THREE.Object3D>} 返回加载的模型对象
728
+ */
729
+ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
730
+ var self = this;
731
+
732
+ return new Promise(function(resolve, reject) {
733
+ // 构建模型URL
734
+ var baseUrl = serverUrl || self.dataUrl;
735
+
736
+ // 从 id 中解析扩展名
737
+ var rawId = furniture.id || '';
738
+ var ext = '.obj';
739
+ var id = rawId;
740
+
741
+ if (typeof rawId === 'string') {
742
+ var dotIndex = rawId.lastIndexOf('.');
743
+ if (dotIndex >= 0) {
744
+ ext = rawId.substring(dotIndex).toLowerCase();
745
+ id = rawId.substring(0, dotIndex);
746
+ }
747
+ }
748
+
749
+ var modelUrl;
750
+ var loader;
751
+
752
+ if (ext === '.fbx' && typeof THREE.FBXLoader === 'function') {
753
+ modelUrl = baseUrl + '/' + furniture.type + '/' + id + ext;
754
+ loader = new THREE.FBXLoader();
755
+ } else {
756
+ modelUrl = baseUrl + '/' + furniture.type + '/' + id + '.obj';
757
+ loader = new THREE.OBJLoader();
758
+ }
759
+
760
+ loader.load(
761
+ modelUrl,
762
+ function(obj) {
763
+ // 应用旋转
764
+ obj.rotation.set(
765
+ furniture.rotation.x,
766
+ furniture.rotation.y,
767
+ furniture.rotation.z
768
+ );
769
+
770
+ // 应用缩放
771
+ if (furniture.targetSize) {
772
+ // 计算模型的边界框
773
+ var box = new THREE.Box3().setFromObject(obj);
774
+ var size = new THREE.Vector3();
775
+ box.getSize(size);
776
+
777
+ // 计算归一化缩放因子
778
+ var scaleX = size.x > 0 ? furniture.targetSize.width / size.x : 1;
779
+ var scaleY = size.y > 0 ? furniture.targetSize.height / size.y : 1;
780
+ var scaleZ = size.z > 0 ? furniture.targetSize.depth / size.z : 1;
781
+ var uniformScale = (scaleX + scaleY + scaleZ) / 3;
782
+
783
+ // 应用归一化缩放和用户缩放
784
+ var finalScale = uniformScale * furniture.scale.x;
785
+ obj.scale.set(finalScale, finalScale, finalScale);
786
+ } else {
787
+ // 兼容旧版本kidata,直接使用scale值
788
+ obj.scale.set(
789
+ furniture.scale.x,
790
+ furniture.scale.y,
791
+ furniture.scale.z
792
+ );
793
+ }
794
+
795
+ // 应用颜色(如果有)
796
+ if (furniture.color) {
797
+ var color = new THREE.Color(furniture.color);
798
+ obj.traverse(function(child) {
799
+ if (child instanceof THREE.Mesh) {
800
+ if (Array.isArray(child.material)) {
801
+ child.material.forEach(function(mat) {
802
+ if (mat.color) mat.color.copy(color);
803
+ });
804
+ } else if (child.material && child.material.color) {
805
+ child.material.color.copy(color);
806
+ }
807
+ }
808
+ });
809
+ }
810
+
811
+ // 重新计算边界框,将模型底部对齐到地面
812
+ var scaledBox = new THREE.Box3().setFromObject(obj);
813
+ var bottomOffset = -scaledBox.min.y;
814
+
815
+ // 应用位置(包含底部对齐偏移)
816
+ obj.position.set(
817
+ furniture.position.x,
818
+ furniture.position.y + bottomOffset,
819
+ furniture.position.z
820
+ );
821
+
822
+ obj.userData = {
823
+ type: 'furniture',
824
+ furnitureId: furniture.id,
825
+ furnitureType: furniture.type
826
+ };
827
+
828
+ resolve(obj);
829
+ },
830
+ undefined,
831
+ function(error) {
832
+ console.error('❌ 家具模型加载失败:', furniture.type, error);
833
+ reject(error);
834
+ }
835
+ );
836
+ });
678
837
  };
679
838
 
680
839
  /**