Autodesk DataVisualization API问题:getRoomList返回空数组,热图无法渲染
问题排查:Autodesk DataVisualization API 设备未映射到房间/热图无法渲染
问题现象
- 调用
ModelStructureInfo.getRoomList("Rooms")返回空数组 - 控制台报错
devices did not map to a room - 热图无法渲染
- 设备坐标取自房间中心,且已通过
NOP_VIEWER.model.getInstanceTree()确认房间节点名称为"Rooms"
现有代码实现
const structureInfo = new Autodesk.DataVisualization.Core.ModelStructureInfo(model); const devices = [ { id: "lobby-01", position: { x: -160.19818878173828, y: 23.581119537353516, z: -4.738031387329102, }, sensorTypes: ["temperature", "humidity"], }, ]; const shadingData = await structureInfo.generateSurfaceShadingData(devices); await dataVizExtn.setupSurfaceShading(model, shadingData); const sensorColors = [0x0000ff, 0x00ff00, 0xffff00, 0xff0000]; const sensorType = "temperature"; dataVizExtn.registerSurfaceShadingColors(sensorType, sensorColors); const getSensorValue = (surfaceShadingPoint, sensorType) => { const deviceId = surfaceShadingPoint.id; let sensorValue = readSensorValue(deviceId, sensorType); const maxSensorValue = getMaxSensorValue(sensorType); const minSensorValue = getMinSensorValue(sensorType); sensorValue = (sensorValue - minSensorValue) / (maxSensorValue - minSensorValue); return clamp(sensorValue, 0.0, 1.0); }; dataVizExtn.renderSurfaceShading("lobby-01", sensorType, getSensorValue); const rooms = await structureInfo.getRoomList("Rooms"); console.log(shadingData, rooms);
排查方向与解决方案
1. 模型加载时机与ModelStructureInfo初始化
ModelStructureInfo需要在模型几何完全加载后初始化,否则无法正确解析房间结构。修改代码等待模型加载完成:
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, async () => { const structureInfo = new Autodesk.DataVisualization.Core.ModelStructureInfo(viewer.model); // 后续设备、热图代码移至此处 });
2. 设备坐标坐标系匹配问题
Revit内部坐标系与Viewer世界坐标系可能存在偏移,需转换设备坐标:
// 转换本地坐标到Viewer世界坐标 const deviceLocal = new THREE.Vector3(-160.19818878173828, 23.581119537353516, -4.738031387329102); const deviceWorld = viewer.model.transformPoint(deviceLocal); const devices = [ { id: "lobby-01", position: { x: deviceWorld.x, y: deviceWorld.y, z: deviceWorld.z }, sensorTypes: ["temperature", "humidity"], }, ];
3. 验证设备是否在房间几何范围内
手动检查设备坐标是否落在房间的 bounding box 内:
const roomId = 19967; // 已确认的房间节点ID const bbox = viewer.model.getBoundingBox(roomId); const deviceVec = new THREE.Vector3(-160.19818878173828, 23.581119537353516, -4.738031387329102); console.log("设备是否在房间范围内:", bbox.containsPoint(deviceVec));
如果返回false,说明坐标仍存在问题,或房间几何未正确加载。
4. 确认房间节点的类别属性
检查该"Rooms"节点是否属于官方定义的房间类别:
const roomNodeId = 19966; // 已确认的房间父节点ID viewer.model.getInstanceTree().enumNodeChildren(roomNodeId, (childId) => { const categoryId = viewer.model.getCategoryId(childId); console.log("房间类别:", viewer.model.getCategoryName(categoryId)); });
正常情况下应返回Rooms或Revit Rooms,否则说明该节点只是普通分组,并非API可识别的房间结构。
5. 检查模型是否包含房间几何
在Viewer中隔离房间节点(ID:19967),查看是否能看到房间的实体或轮廓。若无法显示,说明模型导出时未包含房间几何,需重新导出模型并确保勾选"房间几何"选项。
内容的提问来源于stack exchange,提问作者MiguelG
相关产品推荐
相关产品推荐

