Autodesk Platform Services中的动画 | Autodesk Forge

huangapple go评论57阅读模式
英文:

animations in Autodesk Platform Services | Autodesk Forge

问题

以下是您提供的内容的翻译部分:

我正在尝试在 Autodesk Forge 中创建动画,但每次以不同方式创建它时都会遇到相同的错误。

问题在于无法找到 getFragmentProxy。因为我试图实施以下教程:

https://aps.autodesk.com/blog/know-how-complex-component-transformations-viewer-part-1-basics

在互联网上搜索,我找到了一个遇到相同问题的人。下面是答案的链接。

https://stackoverflow.com/questions/63369599/typescript-definitions-for-forge-viewer-missing-getfragmentproxy

在这个链接中,他提供了多个答案,但对我来说都没有起作用。稍微阅读后,我发现这可能是由于 @types 的问题,但即使我进行了 SDK 配置并添加了类型路径,也无法解决问题。

所以我的问题是,解决这个问题的最佳方法是什么,或者我可以按照哪个教程来制作 Autodesk Forge 中的动画,因为我认为许多教程可能已经停止维护。非常感谢。

我附上下面的图片

图片描述

{
  "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
  }
}
英文:

I am trying to create an animation in autodesk forge. but every time I create it by different means I get the same error.

The problem is that getFragmentProxy is not found. Since I am trying to implement the following tutorial:

https://aps.autodesk.com/blog/know-how-complex-component-transformations-viewer-part-1-basics

Searching the internet I find a person with the same problem. Below I leave the link to the answer.

https://stackoverflow.com/questions/63369599/typescript-definitions-for-forge-viewer-missing-getfragmentproxy

In this one he gives multiple answers but none of them worked for me. Reading a little I could find that it may be because of @types issues but even though I did the SDK configuration and putting the type paths I have not been able to solve the problem.

So my question is. What is the best way to solve this problem or what tutorial could I follow to make animations in autodesk forge since many I think are discontinued. Thank you very much

I am attaching images below

enter image description here

{
  "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
  }
}

答案1

得分: 0

这篇博客文章是2017年的,但其中的代码应该仍然按预期工作。只需确保您不要尝试在"太早"的时候执行动画。几何数据是随时间加载的,对于复杂的模型,可能需要一些时间,因此您应该等待直到所有几何数据可用,例如通过监听Autodesk.Viewing.GEOMETRY_LOADED_EVENT事件。

以下是一个简化的实用函数,可按给定的增量移动特定对象:

function moveObject(viewer, model, dbId, dX, dY, dZ) {
    const tree = model.getInstanceTree();
    tree.enumNodeFragments(dbId, function (fragId) {
        const frag = viewer.impl.getFragmentProxy(model, fragId);
        frag.getAnimTransform();
        frag.position.x += dX;
        frag.position.y += dY;
        frag.position.z += dZ;
        frag.updateAnimTransform();
    }, true);
}

要测试它,访问 https://aps-simple-viewer-nodejs.autodesk.io/#dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGV0cmJyb3otc2FtcGxlcy9yYWNfYWR2YW5jZWRfc2FtcGxlX3Byb2plY3QucnZ0,并尝试将以下代码粘贴到控制台中:

NOP_VIEWER.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, function (ev) {
    function moveObject(viewer, model, dbId, dX, dY, dZ) {
        const tree = model.getInstanceTree();
        tree.enumNodeFragments(dbId, function (fragId) {
            const frag = viewer.impl.getFragmentProxy(model, fragId);
            frag.getAnimTransform();
            frag.position.x += dX;
            frag.position.y += dY;
            frag.position.z += dZ;
            frag.updateAnimTransform();
        }, true);
    }

    const viewer = ev.target;
    const model = ev.model;
    viewer.setProgressiveRendering(false); // 禁用渐进式渲染以避免动画期间的闪烁
    const dbids = viewer.getSelection();
    if (dbids.length === 1) {
        viewer.select([]);
        setInterval(function () {
            moveObject(viewer, model, dbids[0], 0, 0, 1.0);
            viewer.impl.invalidate(true, true);
        }, 100);
    }
});

现在,每当选择任何设计元素时,它都会以100毫秒的间隔开始向上移动。

英文:

The blog post is from 2017 but the code there should still be working as expected. Just make sure that you're not trying to animate the fragments "too early". The geometry data is loaded over time, and for complex models it may take a while, so you should wait until all geometries are available, for example, by listening to the Autodesk.Viewing.GEOMETRY_LOADED_EVENT.

Here's a simplified version of a utility function that will shift a specific object by given deltas:

function moveObject(viewer, model, dbId, dX, dY, dZ) {
    const tree = model.getInstanceTree();
    tree.enumNodeFragments(dbId, function (fragId) {
        const frag = viewer.impl.getFragmentProxy(model, fragId);
        frag.getAnimTransform();
        frag.position.x += dX;
        frag.position.y += dY;
        frag.position.z += dZ;
        frag.updateAnimTransform();
    }, true);
}

To test it out, go to https://aps-simple-viewer-nodejs.autodesk.io/#dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGV0cmJyb3otc2FtcGxlcy9yYWNfYWR2YW5jZWRfc2FtcGxlX3Byb2plY3QucnZ0, and try pasting the following code in the console:

NOP_VIEWER.addEventListener(Autodesk.Viewing.SELECTION_CHANGED_EVENT, function (ev) {
    function moveObject(viewer, model, dbId, dX, dY, dZ) {
        const tree = model.getInstanceTree();
        tree.enumNodeFragments(dbId, function (fragId) {
            const frag = viewer.impl.getFragmentProxy(model, fragId);
            frag.getAnimTransform();
            frag.position.x += dX;
            frag.position.y += dY;
            frag.position.z += dZ;
            frag.updateAnimTransform();
        }, true);
    }

    const viewer = ev.target;
    const model = ev.model;
    viewer.setProgressiveRendering(false); // Disable progressive rendering to avoid blinking during animation
    const dbids = viewer.getSelection();
    if (dbids.length === 1) {
        viewer.select([]);
        setInterval(function () {
            moveObject(viewer, model, dbids[0], 0, 0, 1.0);
            viewer.impl.invalidate(true, true);
        }, 100);
    }
});

Now, whenever you select any design element, it'll start moving upwards in 100ms intervals.

huangapple
  • 本文由 发表于 2023年2月24日 05:03:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75550305.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定