How to create new Markup Tool in Markups Core Extension?

▼魔方 西西 提交于 2021-01-28 18:15:38

问题


I have a markup extension in Autodesk Forge Viewer for 3D models. I need to create a new extension tool into Markups Core to add in my model but I read the docs to create a new Markup Tool and it not help me, the only thing i found is it:

Advance concepts
Create a new drawing tool (a new EditMode)
Developers are encourage to implement drawing tools not included in the Markups extension.
Every drawing tool must have a set of classes to handle them. Let's say for example we are implementing a
Panda tool. For a Panda tool we would need to add the following files/classes:

MarkupPanda.js
EditModePanda.js
CreatePanda.js (Action)
DeletePanda.js (Action)
SetPanda.js (Action)
MarkupPanda.js would contain the class MarkupPanda which extends
Markup and provides the code to render the
markups as an Svg and in a href="http://www.w3.org/TR/2dcontext/">www.w3.org/TR/2dcontext/ canvas 2d context.

EditModePanda.js would contain the class EditModePanda which extends
EditMode and provides the code
to handle user-input for creating a MarkupPanda onscreen.

CreatePanda, DeletePanda and SetPanda are classes that extend
EditAction and provide mechanisms to
author markups of type MarkupPanda.
By encapsulating these operations in actions, the Markups extension is able to make sure
that the undo and redo system handles them gracefully.

But this not help me, I didn't find any examples of code about How to create a new EditMode like the docs say above. Anyone can help me?


回答1:


There's a brief tutorial and some extra doc on the Markup tool available here ...

And you may refer to the full version of its source code here ...

Not knowing the precise issues you've got at hand now generally you can extend the markup tool following the pattern below:

function YourExtension(){
//...
this.viewer.loadExtension("Autodesk.Viewing.MarkupsCore").then(ext=>{
YourExtension.prototype = Autodesk.Viewing.Extensions.Markups.Core.prototype;  
YourExtension.prototype.constructor = Autodesk.Viewing.Extensions.Markups.Core.prototype;
//...
}

Or you can simply creeate a reference to the markup tool in your extension just to keep your own extension independent:

function YourExtension(){
//...
   this.viewer.loadExtension("Autodesk.Viewing.MarkupsCore").then(ext=>{
   this.markupTool = ext
   }
//...
}


来源:https://stackoverflow.com/questions/60871333/how-to-create-new-markup-tool-in-markups-core-extension

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