You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

React环境下Autodesk Forge Viewer通过SVF路径加载AEC扩展求助

Solution for Loading AEC Extensions with Direct SVF Path in Forge Viewer

Got it, let's tackle this problem together! The core issue here is that AEC.LevelsExtension and AEC.MinimapExtension depend on the AEC model metadata (like floor levels, spatial boundaries) that's usually auto-fetched when loading via a model URN. When you load an SVF directly from a local path, the Viewer doesn't know where to pull this metadata by default, so the extensions can't initialize properly.

Here's how to fix it step by step:

Step 1: Make Sure You Have the AEC Model Data File

When you generate the SVF derivative for an AEC model (like Revit), there's an accompanying modelData.json file that holds all the critical AEC metadata. Ensure this file is hosted alongside your SVF files and accessible via a valid URL.

Step 2: Adjust Your Loading Logic

Instead of declaring extensions upfront in the viewer config, we'll wait for the model to load, fetch the modelData.json manually, then initialize the extensions with this data explicitly.

Here's the updated code tailored to your React project:

const Autodesk = window.Autodesk;
const options = { env: 'Local' };
const init_div = document.getElementById('init_div');
// Skip declaring AEC extensions in the initial config
const config3d = {}; 
const viewer = new Autodesk.Viewing.Private.GuiViewer3D(init_div, config3d);

// Parse SVF path and derive the path to modelData.json
const url = window.location.search;
const svf_path = `/${url.replace('?', 'storage/').replace(/%20/g, ' ')}`;
// Assume modelData.json is in the same folder as your SVF
const modelDataPath = svf_path.replace(/\/[^\/]+.svf$/, '/modelData.json');

// Helper to fetch AEC model metadata
async function fetchModelData() {
  try {
    const response = await fetch(modelDataPath);
    return await response.json();
  } catch (err) {
    console.error('Failed to load AEC model data:', err);
    return null;
  }
}

Autodesk.Viewing.Initializer(options, async () => {
  // Start loading the SVF model
  viewer.start(svf_path, options);

  // Wait for model geometry to fully load before initializing extensions
  viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, async () => {
    const modelData = await fetchModelData();
    if (!modelData) return;

    // Load and initialize Levels Extension
    const levelsExt = await viewer.loadExtension('Autodesk.AEC.LevelsExtension');
    levelsExt.setModelData(modelData);
    levelsExt.activate();

    // Load and initialize Minimap Extension
    const minimapExt = await viewer.loadExtension('Autodesk.AEC.MinimapExtension');
    minimapExt.setModelData(modelData);
    minimapExt.activate();
  });
});

Key Details to Note

  • Model Data Path: Adjust modelDataPath if your modelData.json is stored in a different location relative to the SVF. For example, if it's in a parent folder, tweak the path string accordingly.
  • Event Listener: Using GEOMETRY_LOADED_EVENT ensures we only initialize extensions after the model's geometry is fully loaded, avoiding race conditions where extensions try to access unready data.
  • Manual Extension Setup: By loading extensions post-model-load and passing the model data directly, we bypass the URN-dependent metadata fetch that the extensions rely on by default.

Troubleshooting Tips

  • If you don't have modelData.json, re-run your Forge Model Derivative job for the AEC model — this file is included by default for Revit models, so ensure you didn't exclude it in the job settings.
  • Check the browser console for CORS errors or 404s related to modelData.json — make sure the path is correct and your hosting allows cross-origin requests if needed.

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

火山引擎 最新活动