如下图所示,我的精灵位于房间的中心。我使用相同的位置作为设备坐标:
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
) => {
// The `SurfaceShadingPoint.id` property matches one of the identifiers passed
// to `generateSurfaceShadingData` function. In our case above, this will either
// be "cafeteria-entrance-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
);
};
dataVizExtn.renderSurfaceShading(
"lobby-01",
sensorType,
getSensorValue
);
const rooms =
await structureInfo.getRoomList(
"Rooms"
);
console.log(shadingData, rooms);
我什至使用这些命令检查了房间的节点名称是否与“Rooms”相同:
NOP_VIEWER.model.getInstanceTree().getNodeParentId(19967); NOP_VIEWER.model.getInstanceTree().getNodeName(19966,false);