You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Autodesk Forge Viewer中NWC文件楼层最值获取方案咨询

Getting Min/Max Floor Levels for NWC Files in Autodesk Forge Viewer

Since the Autodesk.AEC.LevelsExtension relies on AEC metadata that’s usually stripped out when exporting to NWC files, we need to work around this limitation with alternative approaches. Here are three practical, reliable methods to get those min/max floor values:

1. Calculate Bounds from All Model Fragments

NWC files still retain the geometric position data of every object, so we can iterate through each fragment’s world bounds to extract the global Z-axis min and max (assuming your floor levels align with the Z-axis, which is standard for most models).

Here’s a code snippet to implement this:

async function getFloorMinMax(viewer) {
  const model = viewer.model;
  const fragList = model.getFragmentList();
  let minZ = Infinity;
  let maxZ = -Infinity;
  const box = new THREE.Box3();

  // Loop through all fragments in the model
  for (let fragId = 0; fragId < fragList.getNumFragments(); fragId++) {
    fragList.getWorldBounds(fragId, box);
    // Update our min/max Z values
    if (box.min.z < minZ) minZ = box.min.z;
    if (box.max.z > maxZ) maxZ = box.max.z;
  }

  return { minFloor: minZ, maxFloor: maxZ };
}

// Run this after the model's geometry finishes loading
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, async () => {
  const levels = await getFloorMinMax(viewer);
  console.log(`Min floor Z: ${levels.minFloor}, Max floor Z: ${levels.maxFloor}`);
});

Note: For large models, this loop might take a few seconds—you can optimize by processing fragments in batches or adding a loading indicator for users.

2. Extract from Object Properties (If Available)

If the NWC file was exported with object properties enabled (a setting in Navisworks when exporting), you might find elevation or level-related attributes attached to objects. You can search for these properties and compute the min/max values directly.

Example workflow:

  • Use viewer.search() to look for property keys like "Elevation", "Level Elevation", or custom level-specific fields unique to your model.
  • For each search result, extract the numerical value and track the min/max.

Sample code snippet:

async function getLevelsFromProperties(viewer) {
  // Adjust the search term to match your model's actual property names
  const results = await viewer.search('Elevation');
  const elevations = [];

  for (const result of results) {
    const props = await viewer.getProperties(result.dbId);
    const elevationProp = props.properties.find(p => p.displayName === 'Elevation');
    if (elevationProp && !isNaN(parseFloat(elevationProp.displayValue))) {
      elevations.push(parseFloat(elevationProp.displayValue));
    }
  }

  if (elevations.length === 0) return null;
  return {
    minFloor: Math.min(...elevations),
    maxFloor: Math.max(...elevations)
  };
}

Heads up: Property names can vary based on the original model software and export settings—you may need to inspect a few objects first to find the correct key.

3. Optimize NWC Export Settings

Before exporting from Navisworks, tweak the export options to preserve more data that can help with level detection:

  • Ensure "Export object properties" is checked in the NWC export dialog.
  • Enable options to preserve hierarchy or geometric metadata that might include level references.
  • Avoid stripping out non-essential attributes unless necessary—this gives the Forge Viewer more data to work with.

While this doesn’t directly solve the problem in the Viewer, it can make the other two methods more reliable or even enable limited level metadata access.

内容的提问来源于stack exchange,提问作者Ronak Shetiya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:18:23