问题
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