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

Autodesk Forge动画开发:getFragmentProxy未找到问题及教程咨询

Forge Viewer中getFragmentProxy找不到的问题解决及动画教程推荐

问题概述

尝试在Autodesk Forge中实现组件动画时,始终遇到找不到getFragmentProxy的错误。参考旧教程开发,尝试过相关解决方案但无效,怀疑是@types相关问题,已完成SDK配置和类型路径设置但问题依旧。

当前tsconfig.json配置

{
  "compileOnSave": false,
  "compilerOptions": {
    "typeRoots": [
      "node_modules/@types"
    ],
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "lib": [
      "es2018",
      "dom"
    ],
    "types": [ "forge-viewer" ]
  },
  "exclude": [
      "node_modules"
    ],
    
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

错误截图

getFragmentProxy找不到错误

解决方案建议

1. 手动补充类型声明

创建自定义类型扩展文件(如src/types/forge-extensions.d.ts),补充getFragmentProxy的类型定义:

declare module 'forge-viewer' {
    interface Autodesk.Viewing.Model {
        getFragmentProxy(fragId: number): Autodesk.Viewing.FragmentProxy;
    }
}

修改tsconfig.json的typeRoots,添加自定义类型目录:

"typeRoots": [
  "node_modules/@types",
  "./src/types"
]

2. 临时绕过类型检查

如果需要快速验证功能,可通过以下方式跳过类型错误:

// 类型断言为any
const proxy = (model as any).getFragmentProxy(fragId);

// 或直接忽略类型检查
// @ts-ignore
const proxy = model.getFragmentProxy(fragId);

3. 匹配SDK与类型版本

确保@types/forge-viewer版本与使用的Forge Viewer SDK版本完全匹配,若版本不一致,卸载现有类型包后重新安装对应版本:

npm uninstall @types/forge-viewer
npm install @types/forge-viewer@<SDK版本号>

4. 升级Viewer SDK

部分旧版本Viewer可能存在类型定义缺失问题,建议升级到最新稳定版,同时更新对应的类型包。

可用动画开发教程推荐

  • 官方文档模型变换章节:涵盖组件平移、旋转等基础变换,以及动画循环的实现,内容同步最新API
  • 官方示例库:查找包含动画功能的实战示例,参考官方维护的代码实现,适配最新Viewer版本
  • AnimationController API:使用官方提供的动画控制器,可更高效地实现复杂动画逻辑,无需直接操作FragmentProxy底层方法

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 23:16:00