如何使 Forge 数据可视化扩展与 IFC 文件一起使用?

How to make the Forge Data Visualization extension work with IFC files?

我遵循了 Forge 数据可视化扩展文档中的教程:https://forge.autodesk.com/en/docs/dataviz/v1/developers_guide/quickstart/ 在 IFC 文件上,一切似乎都正常,除了房间的颜色,如下图所示,而不是被着色。

我还在 Revit 文件上进行了测试,房间的颜色正确,所以这个问题是 IFC 文件特有的。

问题是 IFC 文件出现这种行为的原因是什么,我该如何解决?

编辑:解决方案在已接受的post.

的评论中

抱歉回复晚了。经过一番搜索,我设法重现了与您类似的行为,并找到了修复它的解决方案。

在我的例子中,我传递给 DataVisualization#registerSurfaceShadingColors, DataVisualization#renderSurfaceShading, and devices' sensorType in my levelRoomMap manually created by this tutorialsensorType 值没有使用相同的字符大小写。例如,温度与 temperature。修复字符大小写问题后,我的热图按预期重新显示。这是快照:

这是我的代码片段供您参考:

async function getBoxAsync(dbId) {
    return new Promise((resolve, reject) => {
        const tree = viewer.model.getInstanceTree();
        const frags = viewer.model.getFragmentList();
        tree.enumNodeFragments(dbId, function(fragid) {
            let bounds = new THREE.Box3();
            frags.getWorldBounds(fragid, bounds);
            return resolve(bounds);
        }, true);
    });
}

function getLevel(box) {
    const floors = viewer.getExtension("Autodesk.AEC.LevelsExtension").floorSelector.floorData;
    const currentElevation = box.min.z;

    if (currentElevation < floors[0].zMin) {
        return floors[0];
    } else if (currentElevation > floors[floors.length - 1].zMax) {
        return floors[floors.length - 1];
    } else {
        return floors.find(f => f.zMin <= currentElevation && f.zMax >= currentElevation );
    }
}

async function getPropAsync(dbId) {
    return new Promise((resolve, reject) => {
        viewer.getProperties(dbId, result => resolve(result));
    });
}

async function getRoomName(dbId) {
    const result = await getPropAsync(dbId);
    const nameProp = result.properties.find(p => p.attributeName === 'lcldrevit_parameter_Pset_ProductRequirements_tab:lcldrevit_parameter_Name(Pset_ProductRequirements)_PG_IFC');

    return nameProp.displayValue;
}

async function getRoomDbIds() {
    return new Promise((resolve, reject) => {
        viewer.search( 'Rooms', resolve, reject, ['lcldrevit_parameter_Pset_SpaceCommon_tab:lcldrevit_parameter_Category(Pset_SpaceCommon)_PG_IFC'])
    });
}

async function buildRoomMap() {
    const dbIds = await getRoomDbIds();
    const DataVizCore = Autodesk.DataVisualization.Core;
    let levelRoomsMap = new DataVizCore.LevelRoomsMap();


    for ( let i = dbIds.length - 1; i >= 0; i-- ) {
        const dbId = dbIds[i];
        const box = await getBoxAsync( dbId );
        const level = getLevel( box );
        const name = await getRoomName( dbId );

        let room = new DataVizCore.Room(
            dbId, //Room's DbId
            name,
            box
        );

        levelRoomsMap.addRoomToLevel(level.name, room);
    }

    return levelRoomsMap;
}

async function initHeatmap() {
    const DataVizCore = Autodesk.DataVisualization.Core;
    const dataVizExtn = viewer.getExtension('Autodesk.DataVisualization');
    const levelRoomsMap = await buildRoomMap();
    const devices = [];

    for(let lvl in levelRoomsMap) {
        const rooms = levelRoomsMap[lvl];
        for (let i = rooms.length - 1; i >= 0; i--) {
            const room = rooms[i];
            const center = room.bounds.center();
            const device = {
                id: `${room.name} Device`, // An ID to identify this device
                position: center, // World coordinates of this device
                sensorTypes: ["temperature"], // The types/properties this device exposes
            }

            devices.push(device);
            room.addDevice(device);
        }
    }

    const structureInfo = new DataVizCore.ModelStructureInfo(viewer.model);
    let shadingData = await structureInfo.generateSurfaceShadingData(devices, levelRoomsMap);

    await dataVizExtn.setupSurfaceShading(viewer.model, shadingData);

    // Set heatmap colors for temperature
    dataVizExtn.registerSurfaceShadingColors("temperature", [0x00ff00, 0xff0000]);

    function getSensorValue() {
        return Math.random(); // Your random function 
    }

    // Generate the heatmap graphics (do this one time, this is heavier)
    dataVizExtn.renderSurfaceShading(Object.keys(levelRoomsMap), "temperature", getSensorValue);
    // Do this as many times as you want (this is lightweight)
    dataVizExtn.updateSurfaceShading(getSensorValue);

    viewer.getExtension("Autodesk.AEC.LevelsExtension").floorSelector.selectFloor(0);
}

await initHeatmap();