@kimap/indoor-positioning-sdk-vue2 5.2.1 → 5.2.2
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/KimapCore.browser.js +59 -56
- package/src/core/KimapSDK.js +57 -67
package/package.json
CHANGED
package/src/KimapCore.browser.js
CHANGED
|
@@ -437,7 +437,7 @@
|
|
|
437
437
|
|
|
438
438
|
var centerX = origin.x + maxX / 2;
|
|
439
439
|
var centerZ = origin.z;
|
|
440
|
-
var distance = Math.max(maxX, maxY) * 1.
|
|
440
|
+
var distance = Math.max(maxX, maxY) * 1.2;
|
|
441
441
|
|
|
442
442
|
this.camera.position.set(centerX, distance, centerZ + distance * 0.5);
|
|
443
443
|
this.camera.lookAt(centerX, 0, centerZ);
|
|
@@ -951,7 +951,7 @@
|
|
|
951
951
|
*/
|
|
952
952
|
SceneCore.prototype.adjustCameraToModel = function(modelSize) {
|
|
953
953
|
var maxDimension = Math.max(modelSize.x, modelSize.z);
|
|
954
|
-
var distance = maxDimension * 1.
|
|
954
|
+
var distance = maxDimension * 1.2;
|
|
955
955
|
|
|
956
956
|
// 计算模型中心(模型已经移动到原点,所以中心就是尺寸的一半)
|
|
957
957
|
var centerX = modelSize.x / 2;
|
|
@@ -1816,6 +1816,60 @@
|
|
|
1816
1816
|
this.core.controls.target.set(centerX, 0, centerZ);
|
|
1817
1817
|
this.core.controls.update();
|
|
1818
1818
|
};
|
|
1819
|
+
|
|
1820
|
+
/**
|
|
1821
|
+
* 自动调整相机视角,使其能够完整看到整个地图模型
|
|
1822
|
+
* @param {Object} options - 配置选项
|
|
1823
|
+
* @param {number} [options.distanceFactor=1.0] - 相机距离因子,值越小相机越近
|
|
1824
|
+
* @param {number} [options.xFactor=0.5] - X轴偏移因子
|
|
1825
|
+
* @param {number} [options.yFactor=0.4] - Y轴偏移因子(高度)
|
|
1826
|
+
* @param {number} [options.zFactor=0.5] - Z轴偏移因子
|
|
1827
|
+
*/
|
|
1828
|
+
KimapSDK.prototype.autoAdjustCamera = function(options) {
|
|
1829
|
+
var self = this;
|
|
1830
|
+
|
|
1831
|
+
if (!self.core || !self.core.mapModel) {
|
|
1832
|
+
console.warn('KimapSDK: 地图模型未加载,无法调整相机');
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
var opts = options || {};
|
|
1837
|
+
var distanceFactor = opts.distanceFactor !== undefined ? opts.distanceFactor : 1.0;
|
|
1838
|
+
var xFactor = opts.xFactor !== undefined ? opts.xFactor : 0.5;
|
|
1839
|
+
var yFactor = opts.yFactor !== undefined ? opts.yFactor : 0.4;
|
|
1840
|
+
var zFactor = opts.zFactor !== undefined ? opts.zFactor : 0.5;
|
|
1841
|
+
|
|
1842
|
+
var box = new THREE.Box3().setFromObject(self.core.mapModel);
|
|
1843
|
+
var center = new THREE.Vector3();
|
|
1844
|
+
var size = new THREE.Vector3();
|
|
1845
|
+
|
|
1846
|
+
box.getCenter(center);
|
|
1847
|
+
box.getSize(size);
|
|
1848
|
+
|
|
1849
|
+
var maxDim = Math.max(size.x, size.y, size.z);
|
|
1850
|
+
var distance = maxDim * distanceFactor;
|
|
1851
|
+
|
|
1852
|
+
self.core.camera.position.set(
|
|
1853
|
+
center.x + distance * xFactor,
|
|
1854
|
+
center.y + distance * yFactor,
|
|
1855
|
+
center.z + distance * zFactor
|
|
1856
|
+
);
|
|
1857
|
+
|
|
1858
|
+
self.core.camera.lookAt(center);
|
|
1859
|
+
|
|
1860
|
+
if (self.core.controls) {
|
|
1861
|
+
self.core.controls.target.copy(center);
|
|
1862
|
+
self.core.controls.update();
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
console.log('KimapSDK: 相机已自动调整', {
|
|
1866
|
+
center: center,
|
|
1867
|
+
distance: distance,
|
|
1868
|
+
size: size
|
|
1869
|
+
});
|
|
1870
|
+
|
|
1871
|
+
return self;
|
|
1872
|
+
};
|
|
1819
1873
|
|
|
1820
1874
|
/**
|
|
1821
1875
|
* 相机控制 - 正视图
|
|
@@ -1944,8 +1998,6 @@
|
|
|
1944
1998
|
var fileName = objUrl.split('/').pop().replace(/\.(obj|kimap)$/i, '');
|
|
1945
1999
|
var kidataUrl = directory + '/' + fileName + '.kidata';
|
|
1946
2000
|
|
|
1947
|
-
console.log('📦 开始加载3D家具模型数据:', kidataUrl);
|
|
1948
|
-
|
|
1949
2001
|
return fetch(kidataUrl)
|
|
1950
2002
|
.then(function(response) {
|
|
1951
2003
|
if (!response.ok) {
|
|
@@ -1963,26 +2015,17 @@
|
|
|
1963
2015
|
|
|
1964
2016
|
// 如果kidata包含楼层数据,设置为projectLayers
|
|
1965
2017
|
if (kidataObj.floors && Array.isArray(kidataObj.floors)) {
|
|
1966
|
-
console.log('KimapSDK: kidata包含楼层数据,楼层数量:', kidataObj.floors.length);
|
|
1967
2018
|
// 设置第一个楼层为当前楼层(如果没有其他楼层数据)
|
|
1968
2019
|
if (!self.projectLayers && kidataObj.floors.length > 0) {
|
|
1969
2020
|
self.projectLayers = kidataObj.floors[0].layers;
|
|
1970
|
-
console.log('KimapSDK: 从kidata设置楼层数据,图层数量:', self.projectLayers.length);
|
|
1971
2021
|
}
|
|
1972
2022
|
}
|
|
1973
2023
|
|
|
1974
|
-
console.log('✅ Kidata文件解密成功:', {
|
|
1975
|
-
version: kidataObj.version,
|
|
1976
|
-
serverUrl: kidataObj.serverUrl,
|
|
1977
|
-
furnitureCount: kidataObj.furnitures ? kidataObj.furnitures.length : 0,
|
|
1978
|
-
floorCount: kidataObj.floors ? kidataObj.floors.length : 0
|
|
1979
|
-
});
|
|
1980
|
-
|
|
1981
2024
|
// 加载3D家具模型
|
|
1982
2025
|
return self._loadFurnitureModels(kidataObj);
|
|
1983
2026
|
})
|
|
1984
2027
|
.then(function(result) {
|
|
1985
|
-
console.log('✅
|
|
2028
|
+
console.log('✅ 家具加载完成:成功 ' + result.loaded + ' 个,失败 ' + result.failed + ' 个');
|
|
1986
2029
|
|
|
1987
2030
|
// 加载完成后应用形状透明度
|
|
1988
2031
|
self._applyShapeOpacity(kidataObj);
|
|
@@ -1990,7 +2033,7 @@
|
|
|
1990
2033
|
return { success: true, loaded: result.loaded, failed: result.failed };
|
|
1991
2034
|
})
|
|
1992
2035
|
.catch(function(error) {
|
|
1993
|
-
console.error('❌
|
|
2036
|
+
console.error('❌ 家具加载失败:', error.message);
|
|
1994
2037
|
return { success: false, error: error.message };
|
|
1995
2038
|
});
|
|
1996
2039
|
};
|
|
@@ -2074,7 +2117,6 @@
|
|
|
2074
2117
|
}
|
|
2075
2118
|
})
|
|
2076
2119
|
.catch(function(error) {
|
|
2077
|
-
console.error('加载家具模型失败:', furniture.type, error);
|
|
2078
2120
|
failedCount++;
|
|
2079
2121
|
});
|
|
2080
2122
|
|
|
@@ -2130,8 +2172,6 @@
|
|
|
2130
2172
|
loader.load(
|
|
2131
2173
|
modelUrl,
|
|
2132
2174
|
function(obj) {
|
|
2133
|
-
console.log('🔧 [家具模型加载] 开始处理:', furniture.type);
|
|
2134
|
-
|
|
2135
2175
|
// 计算模型的边界框
|
|
2136
2176
|
var box = new THREE.Box3().setFromObject(obj);
|
|
2137
2177
|
var size = new THREE.Vector3();
|
|
@@ -2159,16 +2199,6 @@
|
|
|
2159
2199
|
var finalScaleY = scaleY * userScaleY;
|
|
2160
2200
|
var finalScaleZ = scaleZ * userScaleZ;
|
|
2161
2201
|
|
|
2162
|
-
console.log('🔧 [家具缩放] 原始模型尺寸:', { x: size.x.toFixed(4), y: size.y.toFixed(4), z: size.z.toFixed(4) });
|
|
2163
|
-
console.log('🔧 [家具缩放] 目标尺寸:', { width: targetWidth.toFixed(4), height: targetHeight.toFixed(4), depth: targetDepth.toFixed(4) });
|
|
2164
|
-
console.log('🔧 [家具缩放] 轴向缩放因子:', { scaleX: scaleX.toFixed(4), scaleY: scaleY.toFixed(4), scaleZ: scaleZ.toFixed(4) });
|
|
2165
|
-
console.log('🔧 [家具缩放] 用户缩放:', { x: userScaleX, y: userScaleY, z: userScaleZ });
|
|
2166
|
-
console.log('🔧 [家具缩放] 最终缩放:', {
|
|
2167
|
-
x: finalScaleX.toFixed(4),
|
|
2168
|
-
y: finalScaleY.toFixed(4),
|
|
2169
|
-
z: finalScaleZ.toFixed(4)
|
|
2170
|
-
});
|
|
2171
|
-
|
|
2172
2202
|
obj.scale.set(finalScaleX, finalScaleY, finalScaleZ);
|
|
2173
2203
|
|
|
2174
2204
|
// ========== 修复2: 位置处理(与绘制平台一致)==========
|
|
@@ -2190,11 +2220,6 @@
|
|
|
2190
2220
|
var scaledBottomY = scaledBox.min.y;
|
|
2191
2221
|
var elevation = furniture.position.y; // 离地高度(米)
|
|
2192
2222
|
|
|
2193
|
-
console.log('🔧 [家具] scaledCenter:', scaledCenter);
|
|
2194
|
-
console.log('🔧 [家具] scaledBottomY:', scaledBottomY);
|
|
2195
|
-
console.log('🔧 [家具] elevation:', elevation);
|
|
2196
|
-
console.log('🔧 [家具] furniture.position:', furniture.position);
|
|
2197
|
-
|
|
2198
2223
|
// ========== 旋转处理:使用Group包装(围绕家具中心旋转)==========
|
|
2199
2224
|
var hasRotation = furniture.rotation && (
|
|
2200
2225
|
furniture.rotation.x !== 0 ||
|
|
@@ -2220,8 +2245,6 @@
|
|
|
2220
2245
|
-scaledCenter.z
|
|
2221
2246
|
);
|
|
2222
2247
|
|
|
2223
|
-
console.log('🔧 [家具位置] obj.position(中心偏移):', obj.position);
|
|
2224
|
-
|
|
2225
2248
|
// 2. 将obj添加到Group
|
|
2226
2249
|
furnitureGroup.add(obj);
|
|
2227
2250
|
|
|
@@ -2233,20 +2256,15 @@
|
|
|
2233
2256
|
furniture.position.z
|
|
2234
2257
|
);
|
|
2235
2258
|
|
|
2236
|
-
console.log('🔧 [家具位置] furnitureGroup.position(世界位置):', furnitureGroup.position);
|
|
2237
|
-
|
|
2238
2259
|
// 4. 应用旋转到Group(围绕Group原点,即家具中心)
|
|
2239
2260
|
if (furniture.rotation.y) {
|
|
2240
2261
|
furnitureGroup.rotation.y = furniture.rotation.y;
|
|
2241
|
-
console.log('🔧 [家具旋转] 应用Y轴旋转:', furniture.rotation.y.toFixed(4), 'rad =', (furniture.rotation.y * 180 / Math.PI).toFixed(1) + '°');
|
|
2242
2262
|
}
|
|
2243
2263
|
if (furniture.rotation.x) {
|
|
2244
2264
|
furnitureGroup.rotation.x = furniture.rotation.x;
|
|
2245
|
-
console.log('🔧 [家具旋转] 应用X轴旋转:', furniture.rotation.x.toFixed(4), 'rad =', (furniture.rotation.x * 180 / Math.PI).toFixed(1) + '°');
|
|
2246
2265
|
}
|
|
2247
2266
|
if (furniture.rotation.z) {
|
|
2248
2267
|
furnitureGroup.rotation.z = furniture.rotation.z;
|
|
2249
|
-
console.log('🔧 [家具旋转] 应用Z轴旋转:', furniture.rotation.z.toFixed(4), 'rad =', (furniture.rotation.z * 180 / Math.PI).toFixed(1) + '°');
|
|
2250
2268
|
}
|
|
2251
2269
|
|
|
2252
2270
|
// 添加层级设置,确保家具在区域之上
|
|
@@ -2268,7 +2286,6 @@
|
|
|
2268
2286
|
});
|
|
2269
2287
|
}
|
|
2270
2288
|
|
|
2271
|
-
console.log('✅ 家具模型加载成功(有旋转):', furniture.type);
|
|
2272
2289
|
resolve(furnitureGroup);
|
|
2273
2290
|
} else {
|
|
2274
2291
|
// 无旋转时直接设置obj的世界位置
|
|
@@ -2279,8 +2296,6 @@
|
|
|
2279
2296
|
furniture.position.z - scaledCenter.z
|
|
2280
2297
|
);
|
|
2281
2298
|
|
|
2282
|
-
console.log('🔧 [家具位置] obj.position(世界位置):', obj.position);
|
|
2283
|
-
|
|
2284
2299
|
obj.renderOrder = 3000;
|
|
2285
2300
|
|
|
2286
2301
|
// 应用颜色
|
|
@@ -2305,13 +2320,11 @@
|
|
|
2305
2320
|
furnitureType: furniture.type
|
|
2306
2321
|
};
|
|
2307
2322
|
|
|
2308
|
-
console.log('✅ 家具模型加载成功(无旋转):', furniture.type);
|
|
2309
2323
|
resolve(obj);
|
|
2310
2324
|
}
|
|
2311
2325
|
},
|
|
2312
2326
|
undefined,
|
|
2313
2327
|
function(error) {
|
|
2314
|
-
console.error('❌ 家具模型加载失败:', furniture.type, error);
|
|
2315
2328
|
reject(error);
|
|
2316
2329
|
}
|
|
2317
2330
|
);
|
|
@@ -2867,31 +2880,21 @@
|
|
|
2867
2880
|
|
|
2868
2881
|
// 如果kidata包含楼层数据,设置为projectLayers
|
|
2869
2882
|
if (kidataObj.floors && Array.isArray(kidataObj.floors)) {
|
|
2870
|
-
console.log('[KimapSDK] kidata包含楼层数据,楼层数量:', kidataObj.floors.length);
|
|
2871
2883
|
if (!self.projectLayers && kidataObj.floors.length > 0) {
|
|
2872
2884
|
self.projectLayers = kidataObj.floors[0].layers;
|
|
2873
|
-
console.log('[KimapSDK] 从kidata设置楼层数据,图层数量:', self.projectLayers.length);
|
|
2874
2885
|
}
|
|
2875
2886
|
}
|
|
2876
2887
|
|
|
2877
|
-
console.log('[KimapSDK] ✅ Kidata文件解密成功:', {
|
|
2878
|
-
version: kidataObj.version,
|
|
2879
|
-
furnitureCount: kidataObj.furnitures ? kidataObj.furnitures.length : 0,
|
|
2880
|
-
floorCount: kidataObj.floors ? kidataObj.floors.length : 0
|
|
2881
|
-
});
|
|
2882
|
-
|
|
2883
2888
|
// 只加载3D家具模型
|
|
2884
2889
|
return self._loadFurnitureModels(kidataObj)
|
|
2885
2890
|
.then(function(result) {
|
|
2886
|
-
console.log('[KimapSDK] ✅ 3D家具模型加载完成:', result);
|
|
2887
|
-
|
|
2888
2891
|
// 加载完成后应用形状透明度
|
|
2889
2892
|
self._applyShapeOpacity(kidataObj);
|
|
2890
2893
|
|
|
2891
2894
|
return { success: true, loaded: result.loaded, failed: result.failed };
|
|
2892
2895
|
});
|
|
2893
2896
|
} catch (error) {
|
|
2894
|
-
console.error('
|
|
2897
|
+
console.error('❌ Kidata加载失败:', error.message);
|
|
2895
2898
|
return Promise.reject(error);
|
|
2896
2899
|
}
|
|
2897
2900
|
};
|
package/src/core/KimapSDK.js
CHANGED
|
@@ -603,6 +603,60 @@ KimapSDK.prototype.getCoordinateSystem = function() {
|
|
|
603
603
|
return this.core ? this.core.coordinateSystem : null;
|
|
604
604
|
};
|
|
605
605
|
|
|
606
|
+
/**
|
|
607
|
+
* 自动调整相机视角,使其能够完整看到整个地图模型
|
|
608
|
+
* @param {Object} options - 配置选项
|
|
609
|
+
* @param {number} [options.distanceFactor=1.0] - 相机距离因子,值越小相机越近
|
|
610
|
+
* @param {number} [options.xFactor=0.5] - X轴偏移因子
|
|
611
|
+
* @param {number} [options.yFactor=0.4] - Y轴偏移因子(高度)
|
|
612
|
+
* @param {number} [options.zFactor=0.5] - Z轴偏移因子
|
|
613
|
+
*/
|
|
614
|
+
KimapSDK.prototype.autoAdjustCamera = function(options) {
|
|
615
|
+
var self = this;
|
|
616
|
+
|
|
617
|
+
if (!self.core || !self.core.mapModel) {
|
|
618
|
+
console.warn('KimapSDK: 地图模型未加载,无法调整相机');
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
var opts = options || {};
|
|
623
|
+
var distanceFactor = opts.distanceFactor !== undefined ? opts.distanceFactor : 1.0;
|
|
624
|
+
var xFactor = opts.xFactor !== undefined ? opts.xFactor : 0.5;
|
|
625
|
+
var yFactor = opts.yFactor !== undefined ? opts.yFactor : 0.4;
|
|
626
|
+
var zFactor = opts.zFactor !== undefined ? opts.zFactor : 0.5;
|
|
627
|
+
|
|
628
|
+
var box = new THREE.Box3().setFromObject(self.core.mapModel);
|
|
629
|
+
var center = new THREE.Vector3();
|
|
630
|
+
var size = new THREE.Vector3();
|
|
631
|
+
|
|
632
|
+
box.getCenter(center);
|
|
633
|
+
box.getSize(size);
|
|
634
|
+
|
|
635
|
+
var maxDim = Math.max(size.x, size.y, size.z);
|
|
636
|
+
var distance = maxDim * distanceFactor;
|
|
637
|
+
|
|
638
|
+
self.core.camera.position.set(
|
|
639
|
+
center.x + distance * xFactor,
|
|
640
|
+
center.y + distance * yFactor,
|
|
641
|
+
center.z + distance * zFactor
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
self.core.camera.lookAt(center);
|
|
645
|
+
|
|
646
|
+
if (self.core.controls) {
|
|
647
|
+
self.core.controls.target.copy(center);
|
|
648
|
+
self.core.controls.update();
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
console.log('KimapSDK: 相机已自动调整', {
|
|
652
|
+
center: center,
|
|
653
|
+
distance: distance,
|
|
654
|
+
size: size
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
return self;
|
|
658
|
+
};
|
|
659
|
+
|
|
606
660
|
KimapSDK.prototype.getConfig = function() {
|
|
607
661
|
var config = {};
|
|
608
662
|
|
|
@@ -684,8 +738,6 @@ KimapSDK.prototype.loadKMData = function() {
|
|
|
684
738
|
var fileName = objUrl.split('/').pop().replace(/\.(obj|kimap)$/i, '');
|
|
685
739
|
var kidataUrl = directory + '/' + fileName + '.kidata';
|
|
686
740
|
|
|
687
|
-
console.log('📦 开始加载3D家具模型数据:', kidataUrl);
|
|
688
|
-
|
|
689
741
|
return fetch(kidataUrl)
|
|
690
742
|
.then(function(response) {
|
|
691
743
|
if (!response.ok) {
|
|
@@ -703,31 +755,22 @@ KimapSDK.prototype.loadKMData = function() {
|
|
|
703
755
|
|
|
704
756
|
// 如果kidata包含楼层数据,设置为projectLayers
|
|
705
757
|
if (kidataObj.floors && Array.isArray(kidataObj.floors)) {
|
|
706
|
-
console.log('KimapSDK: kidata包含楼层数据,楼层数量:', kidataObj.floors.length);
|
|
707
758
|
// 设置第一个楼层为当前楼层(如果没有其他楼层数据)
|
|
708
759
|
if (!self.projectLayers && kidataObj.floors.length > 0) {
|
|
709
760
|
self.projectLayers = kidataObj.floors[0].layers;
|
|
710
|
-
console.log('KimapSDK: 从kidata设置楼层数据,图层数量:', self.projectLayers.length);
|
|
711
761
|
}
|
|
712
762
|
}
|
|
713
763
|
|
|
714
|
-
console.log('✅ Kidata文件解密成功:', {
|
|
715
|
-
version: kidataObj.version,
|
|
716
|
-
serverUrl: kidataObj.serverUrl,
|
|
717
|
-
furnitureCount: kidataObj.furnitures ? kidataObj.furnitures.length : 0,
|
|
718
|
-
floorCount: kidataObj.floors ? kidataObj.floors.length : 0
|
|
719
|
-
});
|
|
720
|
-
|
|
721
764
|
// 加载3D家具模型
|
|
722
765
|
return self._loadFurnitureModels(kidataObj);
|
|
723
766
|
})
|
|
724
767
|
.then(function(result) {
|
|
725
|
-
console.log('✅
|
|
768
|
+
console.log('✅ 家具加载完成:成功 ' + result.loaded + ' 个,失败 ' + result.failed + ' 个');
|
|
726
769
|
|
|
727
770
|
return { success: true, loaded: result.loaded, failed: result.failed };
|
|
728
771
|
})
|
|
729
772
|
.catch(function(error) {
|
|
730
|
-
console.error('❌
|
|
773
|
+
console.error('❌ 家具加载失败:', error.message);
|
|
731
774
|
return { success: false, error: error.message };
|
|
732
775
|
});
|
|
733
776
|
};
|
|
@@ -787,8 +830,6 @@ KimapSDK.prototype._loadFurnitureModels = function(kidataObj) {
|
|
|
787
830
|
var loadedCount = 0;
|
|
788
831
|
var failedCount = 0;
|
|
789
832
|
|
|
790
|
-
console.log('📦 开始加载', kidataObj.furnitures.length, '个家具模型');
|
|
791
|
-
|
|
792
833
|
// 加载每个家具模型
|
|
793
834
|
kidataObj.furnitures.forEach(function(furniture) {
|
|
794
835
|
var promise = self._loadSingleFurniture(furniture, serverUrl)
|
|
@@ -801,7 +842,6 @@ KimapSDK.prototype._loadFurnitureModels = function(kidataObj) {
|
|
|
801
842
|
}
|
|
802
843
|
})
|
|
803
844
|
.catch(function(error) {
|
|
804
|
-
console.error('加载家具模型失败:', furniture.type, error);
|
|
805
845
|
failedCount++;
|
|
806
846
|
});
|
|
807
847
|
|
|
@@ -888,8 +928,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
888
928
|
// GLTF/GLB格式返回的是gltf对象,需要提取scene
|
|
889
929
|
var obj = (ext === '.glb' || ext === '.gltf') ? result.scene : result;
|
|
890
930
|
|
|
891
|
-
console.log('🔧 [家具模型加载] 开始处理:', furniture.type);
|
|
892
|
-
|
|
893
931
|
// ========== 修复1: 分别计算X、Y、Z轴的缩放因子 ==========
|
|
894
932
|
// 计算模型的边界框
|
|
895
933
|
var box = new THREE.Box3().setFromObject(obj);
|
|
@@ -918,16 +956,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
918
956
|
var finalScaleY = scaleY * userScaleY;
|
|
919
957
|
var finalScaleZ = scaleZ * userScaleZ;
|
|
920
958
|
|
|
921
|
-
console.log('🔧 [家具缩放] 原始模型尺寸:', { x: size.x.toFixed(4), y: size.y.toFixed(4), z: size.z.toFixed(4) });
|
|
922
|
-
console.log('🔧 [家具缩放] 目标尺寸:', { width: targetWidth.toFixed(4), height: targetHeight.toFixed(4), depth: targetDepth.toFixed(4) });
|
|
923
|
-
console.log('🔧 [家具缩放] 缩放因子(预览一致):', { scaleX: scaleX.toFixed(4), scaleY: scaleY.toFixed(4), scaleZ: scaleZ.toFixed(4) });
|
|
924
|
-
console.log('🔧 [家具缩放] 用户缩放:', { x: userScaleX, y: userScaleY, z: userScaleZ });
|
|
925
|
-
console.log('🔧 [家具缩放] 最终缩放(预览一致):', {
|
|
926
|
-
x: finalScaleX.toFixed(4),
|
|
927
|
-
y: finalScaleY.toFixed(4),
|
|
928
|
-
z: finalScaleZ.toFixed(4)
|
|
929
|
-
});
|
|
930
|
-
|
|
931
959
|
// 应用与预览一致的非等比缩放
|
|
932
960
|
obj.scale.set(finalScaleX, finalScaleY, finalScaleZ);
|
|
933
961
|
|
|
@@ -950,11 +978,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
950
978
|
var scaledBottomY = scaledBox.min.y;
|
|
951
979
|
var elevation = furniture.position.y; // 离地高度(米)
|
|
952
980
|
|
|
953
|
-
console.log('🔧 [家具] scaledCenter:', scaledCenter);
|
|
954
|
-
console.log('🔧 [家具] scaledBottomY:', scaledBottomY);
|
|
955
|
-
console.log('🔧 [家具] elevation:', elevation);
|
|
956
|
-
console.log('🔧 [家具] furniture.position:', furniture.position);
|
|
957
|
-
|
|
958
981
|
// ========== 旋转处理:使用Group包装(围绕家具中心旋转)==========
|
|
959
982
|
var hasRotation = furniture.rotation && (
|
|
960
983
|
furniture.rotation.x !== 0 ||
|
|
@@ -980,8 +1003,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
980
1003
|
-scaledCenter.z
|
|
981
1004
|
);
|
|
982
1005
|
|
|
983
|
-
console.log('🔧 [家具位置] obj.position(中心偏移):', obj.position);
|
|
984
|
-
|
|
985
1006
|
// 2. 将obj添加到Group
|
|
986
1007
|
furnitureGroup.add(obj);
|
|
987
1008
|
|
|
@@ -993,21 +1014,16 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
993
1014
|
furniture.position.z
|
|
994
1015
|
);
|
|
995
1016
|
|
|
996
|
-
console.log('🔧 [家具位置] furnitureGroup.position(世界位置):', furnitureGroup.position);
|
|
997
|
-
|
|
998
1017
|
// 4. 应用旋转到Group(围绕Group原点,即家具中心)
|
|
999
1018
|
// 注意:kidata JSON中 rotation 存储的是弧度值,直接使用
|
|
1000
1019
|
if (furniture.rotation.y) {
|
|
1001
1020
|
furnitureGroup.rotation.y = furniture.rotation.y;
|
|
1002
|
-
console.log('🔧 [家具旋转] 应用Y轴旋转:', furniture.rotation.y.toFixed(4), 'rad =', (furniture.rotation.y * 180 / Math.PI).toFixed(1) + '°');
|
|
1003
1021
|
}
|
|
1004
1022
|
if (furniture.rotation.x) {
|
|
1005
1023
|
furnitureGroup.rotation.x = furniture.rotation.x;
|
|
1006
|
-
console.log('🔧 [家具旋转] 应用X轴旋转:', furniture.rotation.x.toFixed(4), 'rad =', (furniture.rotation.x * 180 / Math.PI).toFixed(1) + '°');
|
|
1007
1024
|
}
|
|
1008
1025
|
if (furniture.rotation.z) {
|
|
1009
1026
|
furnitureGroup.rotation.z = furniture.rotation.z;
|
|
1010
|
-
console.log('🔧 [家具旋转] 应用Z轴旋转:', furniture.rotation.z.toFixed(4), 'rad =', (furniture.rotation.z * 180 / Math.PI).toFixed(1) + '°');
|
|
1011
1027
|
}
|
|
1012
1028
|
|
|
1013
1029
|
// =====================================================
|
|
@@ -1028,12 +1044,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1028
1044
|
}
|
|
1029
1045
|
});
|
|
1030
1046
|
|
|
1031
|
-
console.log('[KimapSDK] ✅ 家具模型层级设置:', {
|
|
1032
|
-
id: furniture.id,
|
|
1033
|
-
renderOrder: furnitureGroup.renderOrder,
|
|
1034
|
-
depthWriteDisabled: true
|
|
1035
|
-
});
|
|
1036
|
-
|
|
1037
1047
|
// 应用颜色
|
|
1038
1048
|
if (furniture.color) {
|
|
1039
1049
|
var color = new THREE.Color(furniture.color);
|
|
@@ -1050,7 +1060,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1050
1060
|
});
|
|
1051
1061
|
}
|
|
1052
1062
|
|
|
1053
|
-
console.log('✅ 家具模型加载成功(有旋转):', furniture.type);
|
|
1054
1063
|
resolveLoad(furnitureGroup);
|
|
1055
1064
|
} else {
|
|
1056
1065
|
// 无旋转时直接设置obj的世界位置
|
|
@@ -1061,8 +1070,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1061
1070
|
furniture.position.z - scaledCenter.z
|
|
1062
1071
|
);
|
|
1063
1072
|
|
|
1064
|
-
console.log('🔧 [家具位置] obj.position(世界位置):', obj.position);
|
|
1065
|
-
|
|
1066
1073
|
// =====================================================
|
|
1067
1074
|
// 层级系统:解决多区域与3D家具叠加时的频闪问题
|
|
1068
1075
|
// =====================================================
|
|
@@ -1092,13 +1099,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1092
1099
|
}
|
|
1093
1100
|
});
|
|
1094
1101
|
|
|
1095
|
-
console.log('[KimapSDK] ✅ 家具模型层级设置:', {
|
|
1096
|
-
id: furniture.id,
|
|
1097
|
-
renderOrder: obj.renderOrder,
|
|
1098
|
-
yOffset: totalYOffset.toFixed(6) + 'm',
|
|
1099
|
-
depthWriteDisabled: true
|
|
1100
|
-
});
|
|
1101
|
-
|
|
1102
1102
|
// 应用颜色
|
|
1103
1103
|
if (furniture.color) {
|
|
1104
1104
|
var color = new THREE.Color(furniture.color);
|
|
@@ -1121,7 +1121,6 @@ KimapSDK.prototype._loadSingleFurniture = function(furniture, serverUrl) {
|
|
|
1121
1121
|
furnitureType: furniture.type
|
|
1122
1122
|
};
|
|
1123
1123
|
|
|
1124
|
-
console.log('✅ 家具模型加载成功(无旋转):', furniture.type);
|
|
1125
1124
|
resolveLoad(obj);
|
|
1126
1125
|
}
|
|
1127
1126
|
},
|
|
@@ -1161,27 +1160,18 @@ KimapSDK.prototype.loadKidataForFurniture = function(kidataContent) {
|
|
|
1161
1160
|
|
|
1162
1161
|
// 如果kidata包含楼层数据,设置为projectLayers
|
|
1163
1162
|
if (kidataObj.floors && Array.isArray(kidataObj.floors)) {
|
|
1164
|
-
console.log('[KimapSDK] kidata包含楼层数据,楼层数量:', kidataObj.floors.length);
|
|
1165
1163
|
if (!self.projectLayers && kidataObj.floors.length > 0) {
|
|
1166
1164
|
self.projectLayers = kidataObj.floors[0].layers;
|
|
1167
|
-
console.log('[KimapSDK] 从kidata设置楼层数据,图层数量:', self.projectLayers.length);
|
|
1168
1165
|
}
|
|
1169
1166
|
}
|
|
1170
1167
|
|
|
1171
|
-
console.log('[KimapSDK] ✅ Kidata文件解密成功:', {
|
|
1172
|
-
version: kidataObj.version,
|
|
1173
|
-
furnitureCount: kidataObj.furnitures ? kidataObj.furnitures.length : 0,
|
|
1174
|
-
floorCount: kidataObj.floors ? kidataObj.floors.length : 0
|
|
1175
|
-
});
|
|
1176
|
-
|
|
1177
1168
|
// 只加载3D家具模型
|
|
1178
1169
|
return self._loadFurnitureModels(kidataObj)
|
|
1179
1170
|
.then(function(result) {
|
|
1180
|
-
console.log('[KimapSDK] ✅ 3D家具模型加载完成:', result);
|
|
1181
1171
|
return { success: true, loaded: result.loaded, failed: result.failed };
|
|
1182
1172
|
});
|
|
1183
1173
|
} catch (error) {
|
|
1184
|
-
console.error('
|
|
1174
|
+
console.error('❌ Kidata加载失败:', error.message);
|
|
1185
1175
|
return Promise.reject(error);
|
|
1186
1176
|
}
|
|
1187
1177
|
};
|