使用自定义扩展查看器 Autodesk Forge
Use custom Extension Viewer Autodesk Forge
我正在尝试研究 Autodesk Forge。我正在尝试测试 this link 中的脚本以注册扩展程序,单击按钮时更改背景颜色。但是当点击时, alert("Autodesk.ADN.Viewing.Extension.Basic loaded") 是可见的,但对背景颜色并不满意。
知道的请告诉我为什么以及如何解决。
在此先致谢!
AutodeskNamespace("Autodesk.ADN.Viewing.Extension");
Autodesk.ADN.Viewing.Extension.Basic = function (viewer, options) {
Autodesk.Viewing.Extension.call(this, viewer, options);
var _this = this;
_this.load = function () {
alert("Autodesk.ADN.Viewing.Extension.Basic loaded");
viewer.setBackgroundColor(255, 0, 0, 255, 255, 255);
return true;
};
_this.unload = function () {
viewer.setBackgroundColor(160, 176, 184, 190, 207, 216);
alert("Autodesk.ADN.Viewing.Extension.Basic unloaded");
Autodesk.Viewing.theExtensionManager.unregisterExtension(
"Autodesk.ADN.Viewing.Extension.Basic");
return true;
};
};
Autodesk.ADN.Viewing.Extension.Basic.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
Autodesk.ADN.Viewing.Extension.Basic.prototype.constructor = Autodesk.ADN.Viewing.Extension.Basic;
Autodesk.Viewing.theExtensionManager.registerExtension("Autodesk.ADN.Viewing.Extension.Basic", Autodesk.ADN.Viewing.Extension.Basic);
$(document).ready(function(){
$("#button").click(function(){
viewer.loadExtension('Autodesk.ADN.Viewing.Extension.Basic');
})
})
您链接的博客文章是2016年的。Forge Viewer 仍然在快速发展,所以我担心这个博客post中的代码片段太out-dated。
如果您有兴趣了解有关 Forge 平台的更多信息,我建议您查看 https://learnforge.autodesk.io website. It contains various tutorials and we try and keep them up-to-date whenever the Forge services or the Forge Viewer API changes. There's also a tutorial about viewer extensions specifically: https://learnforge.autodesk.io/#/tutorials/extensions。
为了给你一个想法,下面是今天如何使用 viewer version 7.*:
实现一个简单的查看器扩展
class MyAwesomeExtension extends Autodesk.Viewing.Extension {
constructor(viewer, options) {
super(viewer, options);
}
load() {
console.log('MyAwesomeExtensions has been loaded');
viewer.setEnvMapBackground(null); // Hide background environment if there is one
viewer.setBackgroundColor(0, 64, 128); // Set background color
return true;
}
unload() {
console.log('MyAwesomeExtensions has been unloaded');
return true;
}
}
Autodesk.Viewing.theExtensionManager.registerExtension('MyAwesomeExtension', MyAwesomeExtension);
然后,在初始化查看器时,您将像这样加载您的扩展程序:
let viewer = new Autodesk.Viewing.GuiViewer3D(divElement, { extensions: ['MyAwesomeExtension'] });
我正在尝试研究 Autodesk Forge。我正在尝试测试 this link 中的脚本以注册扩展程序,单击按钮时更改背景颜色。但是当点击时, alert("Autodesk.ADN.Viewing.Extension.Basic loaded") 是可见的,但对背景颜色并不满意。 知道的请告诉我为什么以及如何解决。
在此先致谢!
AutodeskNamespace("Autodesk.ADN.Viewing.Extension");
Autodesk.ADN.Viewing.Extension.Basic = function (viewer, options) {
Autodesk.Viewing.Extension.call(this, viewer, options);
var _this = this;
_this.load = function () {
alert("Autodesk.ADN.Viewing.Extension.Basic loaded");
viewer.setBackgroundColor(255, 0, 0, 255, 255, 255);
return true;
};
_this.unload = function () {
viewer.setBackgroundColor(160, 176, 184, 190, 207, 216);
alert("Autodesk.ADN.Viewing.Extension.Basic unloaded");
Autodesk.Viewing.theExtensionManager.unregisterExtension(
"Autodesk.ADN.Viewing.Extension.Basic");
return true;
};
};
Autodesk.ADN.Viewing.Extension.Basic.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
Autodesk.ADN.Viewing.Extension.Basic.prototype.constructor = Autodesk.ADN.Viewing.Extension.Basic;
Autodesk.Viewing.theExtensionManager.registerExtension("Autodesk.ADN.Viewing.Extension.Basic", Autodesk.ADN.Viewing.Extension.Basic);
$(document).ready(function(){
$("#button").click(function(){
viewer.loadExtension('Autodesk.ADN.Viewing.Extension.Basic');
})
})
您链接的博客文章是2016年的。Forge Viewer 仍然在快速发展,所以我担心这个博客post中的代码片段太out-dated。
如果您有兴趣了解有关 Forge 平台的更多信息,我建议您查看 https://learnforge.autodesk.io website. It contains various tutorials and we try and keep them up-to-date whenever the Forge services or the Forge Viewer API changes. There's also a tutorial about viewer extensions specifically: https://learnforge.autodesk.io/#/tutorials/extensions。
为了给你一个想法,下面是今天如何使用 viewer version 7.*:
实现一个简单的查看器扩展class MyAwesomeExtension extends Autodesk.Viewing.Extension {
constructor(viewer, options) {
super(viewer, options);
}
load() {
console.log('MyAwesomeExtensions has been loaded');
viewer.setEnvMapBackground(null); // Hide background environment if there is one
viewer.setBackgroundColor(0, 64, 128); // Set background color
return true;
}
unload() {
console.log('MyAwesomeExtensions has been unloaded');
return true;
}
}
Autodesk.Viewing.theExtensionManager.registerExtension('MyAwesomeExtension', MyAwesomeExtension);
然后,在初始化查看器时,您将像这样加载您的扩展程序:
let viewer = new Autodesk.Viewing.GuiViewer3D(divElement, { extensions: ['MyAwesomeExtension'] });