Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

How to costumize options and style in Autodesk Forge Viewer Extensions

I'm using Autodesk forge Section Extension and I see that there are some kind of options and style that I can change. For example when the extension is loaded it expects some options (this code is the Autodesk.Forge/SectionTool.js):

    export var SectionTool = function(viewer, options)
{
    var _viewer  = viewer.impl;

    var _names = ["section"];
    ...
    var _tintColor = options.tintColor;
    var _tintIntensity = options.tintIntensity;
    ...
    var _gizmoOffsetRight = isNaN(options.gizmoOffsetRight) ? 200 : options.gizmoOffsetRight; 

However there is no way of change that values, I try to add an option object when I load the extension:

const options = {tintColor: {r: 0, g: 1, b: 0},gizmoOffsetRight:10}
this.section = await this.viewer.loadExtension('Autodesk.Section',options);

But I can't, anything I do at the end options object has the same value: {tintColor:r:1,g:1,b:0},and I dont know where it takes that values etc...

All this is because I dont like the gizmo looking and i'd like to maybe place it in a different position for example.

Any help please :(

question from:https://stackoverflow.com/questions/65846452/how-to-costumize-options-and-style-in-autodesk-forge-viewer-extensions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Be careful about the difference between Section extension and Section tool. You are passing the custom options to the extension itself, but the extension does not pass them on to the tool. This is what the extension's load method looks like:

proto.load = function() {
    var that = this;
    var viewer = this.viewer;

    this.tool = new SectionTool(viewer, {
        tintColor: { r: 1, g: 1, b: 0 },
        tintIntensity: 0.2
    });

    viewer.toolController.registerTool(this.tool, this.setActive.bind(this));
    this.sectionStyle = null;
    this.supportedStyles = ["X", "Y", "Z", "BOX"];
    // ...
}

As you can see, the tool options were not meant to be publicly accessible. You could try and hack it, though, by overriding the extension's tool property after it's been loaded. You'd probably also need to deregister the original SectionTool instance, and register the new one.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...