首页 > 解决方案 > 将 Autodesk Forge 热图映射到房间 - 数据可视化 API

问题描述

好的,所以我一直在尝试使用 DataViz api 将一些热图映射到 Revit 房间。我能够从 Revit 获得房间内传感器的 XYZ,我已经减去viewer.model.getGlobalOffset()并设法在这些点上显示一些精灵。我知道这些精灵/点在房间内的事实,但是每当我尝试使用相同的点来加载热图时,我都会收到Some devices did not map to a room:警告并且没有显示热图。

根据 API 文档,当点中没有房间信息时会出现此警告。我错过了什么吗?这是“我的”代码:

async function loadHeatmaps(model){
  
  const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization"); 
  // Given a model loaded from Forge
const structureInfo = new Autodesk.DataVisualization.Core.ModelStructureInfo(model);

const devices = [
    {
        id: "Oficina 6", // An ID to identify this device
        name:"Oficina-",
        position: { x: 22.475382737884104, y: 7.4884431474006163, z: 3.0 }, // World coordinates of this device
        sensorTypes: ["temperature", "humidity"], // The types/properties this device exposes
    }
];
var offset = viewer.model.getGlobalOffset();
removeOffset(devices[0],offset)
// Generates `SurfaceShadingData` after assigning each device to a room.
const shadingData =  await structureInfo.generateSurfaceShadingData(devices);
  console.log(shadingData)
// Use the resulting shading data to generate heatmap from.
await dataVizExtn.setupSurfaceShading(model, shadingData);

// Register color stops for the heatmap. Along with the normalized sensor value
// in the range of [0.0, 1.0], `renderSurfaceShading` will interpolate the final
// heatmap color based on these specified colors.
const sensorColors = [0x0000ff, 0x00ff00, 0xffff00, 0xff0000];

// Set heatmap colors for temperature
const sensorType = "temperature";
dataVizExtn.registerSurfaceShadingColors(sensorType, sensorColors);
// Function that provides sensor value in the range of [0.0, 1.0]
function getSensorValue(surfaceShadingPoint, sensorType) {
  // The `SurfaceShadingPoint.id` property matches one of the identifiers passed
  // to `generateSurfaceShadingData` function. In our case above, this will either
  // be "cafeteria-entrace-01" or "cafeteria-exit-01".
  const deviceId = surfaceShadingPoint.id;

  // Read the sensor data, along with its possible value range
  let sensorValue = readSensorValue(deviceId, sensorType);
  const maxSensorValue = getMaxSensorValue(sensorType);
  const minSensorValue = getMinSensorValue(sensorType);

  // Normalize sensor value to [0, 1.0]
  sensorValue = (sensorValue - minSensorValue) / (maxSensorValue - minSensorValue);
  return clamp(sensorValue, 0.0, 1.0);
}

// This value can also be a room instead of a floor
const floorName = "01 - Entry Level";
dataVizExtn.renderSurfaceShading(floorName, sensorType, getSensorValue);


} 

function removeOffset(pos, offset) {
  pos.position.x = pos.position.x - offset.x;
  pos.position.y = pos.position.y - offset.y;
  pos.position.z = pos.position.z - offset.z;
}

我在回调中调用loadHeatmaps()函数。onDocumentLoadSuccess

精灵和房间,但没有热图

标签: javascriptautodesk-forge

解决方案


编辑:看起来在这种特殊情况下,floorName没有设置正确的值是一个问题。请注意,此值(第一个参数dataVizExtn.renderSurfaceShading)应该设置为房间的名称,或者设置为您要更新的楼层的名称。

偏移量有点棘手,所以我建议调试该区域,例如:

  • 传感器定义在什么坐标系中?如果它们与建筑模型本身位于同一坐标系中,则不应为它们减去或添加任何偏移量。每当模型的元数据中包含“全局偏移”时,这基本上意味着模型衍生服务将模型移动到原点以避免浮点精度问题,然后查看器将在加载时将全局偏移添加回每个几何图形.

  • 尝试使用查看器 API 获取设备应映射到的其中一个房间的边界框,并查看边界框是否实际包含您尝试传递到 DataViz 扩展的设备的 XYZ 点。可以像这样找到任何对象的边界:

function getObjectBounds(model, dbid) {
    const tree = model.getInstanceTree();
    const frags = model.getFragmentList();
    let bounds = new THREE.Box3();
    tree.enumNodeFragments(dbid, function (fragid) {
        let _bounds = new THREE.Box3();
        frags.getWorldBounds(fragid, _bounds);
        bounds.union(_bounds);
    }, true);
    return bounds;
}

推荐阅读