How to change object names in Forge Viewer?

主宰稳场 提交于 2019-12-11 18:10:47

问题


How can I change the names of objects and parent nodes in Forge Viewer?

In version 6.1 and below, there was a blog post that worked: by altering the ModelStructureTreeDelegate class, reloading it as an extension, effectively overriding it. That doesn't work on 6.2 and later (current is 6.3.3), because now that class is not accessible anymore, or otherwise doesn't work.

What I found was that, by accessing the InstanceTreeStorage.prototype.processName method, I could change the name of objects in the tree, but that class is not available externally. It seems to be used only during Model loading.

I found no other class that changes the name, or any other function that lets me do it.

Has anyone done something similar with the most recent version of the Viewer?


回答1:


You can create your own model structure panel by deriving from the Autodesk.Viewing.Extensions.ViewerModelStructurePanel class, overriding the getNodeLabel method, and setting an instance of the class as the model structure UI for the viewer:

class CustomModelStructurePanel extends Autodesk.Viewing.Extensions.ViewerModelStructurePanel {
    constructor(viewer, title, options) {
        super(viewer, title, options);
    }

    getNodeLabel(node) {
        return 'custom node name';
    }
}

viewer.setModelStructurePanel(new CustomModelStructurePanel(viewer, 'Custom Model Structure', options));


来源:https://stackoverflow.com/questions/53652819/how-to-change-object-names-in-forge-viewer

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