Controlling the autodesk-forge viewer with external buttons

梦想与她 提交于 2020-06-29 03:55:28

问题


Currently I am adding forge to an internal company website where we can view all of the machines we have built or are building. The website works like this: The user selects a machine number and all the information about the machine will pop up. This includes stations within the machine, as well as all the individual parts within each station. My task was to add autodesk-forge to the website. Currently I have successfully used the autodesk-forge viewer so that whenever a machine is picked, the user can press a button, and the model of the entire machine will pop up to be viewed. The next step is to have the viewer be controlled by external buttons on the website. We want it to work as such:

  1. A machine is picked by the user. After this all the information such as stations, and parts within each station in the machine will pop up (this is completed).

  2. The user clicks a "view model" button which will use the forge viewer to make the machine pop up on the website (This has been completed by me).

  3. Once the forge viewer with the model is on the screen, we want the viewer to be able to be controlled by external buttons already on the site.

For example, if there is a machine with name MC-000, and in that machine there is a station named ST010, within that station there are many parts, for example a gear. When the machine MC-000 is being viewed by the user, we want to be able to click an external button which is already made (for example ST010) and the viewer will automatically zoom in and highlight that station within the machine. We also want the same for parts within the machine. When a machine is picked, its stations, as well as the parts within the stations are already printed out within our website. We now want to be able to click the stations, or parts and have the viewer automatically zoom into that part# or station#. I have found a similar code sample here. In this example, parts of the viewer are controlled by buttons not within the viewer. For example, when the 'engine' button is clicked, the viewer will automatically zoom into the engine. The problem with this example, is that all of the positions are hard-coded into the code, meaning that the position of the engine is already within the code. I cannot do this as we have many different machines with thousands of parts, so it would be impossible for me to hard-code them all in. Is something like this possible to do with autodesk-forge viewer. Any help or guidance would be greatly appreciated. Cheers!

EDIT**

Any guidance at all on how I can change where the viewer zooms into would be much appreciated and would help a lot. Currently, I have methods go get both the dbid, and the external objectId from the GET :urn/metadata/:guid http request. Thanks again!


回答1:


It seems you do have the specified engine dbid and you have a way to link viewer functions with your outside code. The default doubleclick behaviour of the viewer is to select the item the mousepointer collides with. The camera then zooms in (or out) to that item to fit it into the view.

You can use:

select

And

fitToView

To achieve a simular interaction.

For example in Typescript:

// Your dbid is for example 1234
this.viewer.select(1234);
this.viewer.fitToView([1234]);



回答2:


viewer.select(dbid);
viewer.utilities.fitToView();

Example: https://github.com/Autodesk-Forge/forge-extensions/tree/master/public/extensions/IconMarkupExtension



来源:https://stackoverflow.com/questions/62345225/controlling-the-autodesk-forge-viewer-with-external-buttons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!