如何添加扩展
How to add an extension
我是 Forge Viewer 的新手,刚开始创建我的 Basic Application。
现在,我想尝试添加这个 extension。我做了一些搜索并将其添加到我的 HTML:
forge.run
(
// divId
'ForgeViewerContainer',
// config
{
extensions:[
'./Viewer.Skybox'
'Viewing.Extension.Showcase'
]
},
现在我要加载扩展程序。我不太明白它的窍门。任何帮助将不胜感激。
抱歉这个基本问题!
此扩展是用 ES6 编写的,因此很遗憾,您不能直接在 html 中引用脚本并将其加载到查看器中,它需要一个转换步骤才能将其转换为 ES5。您需要了解一些有关现代 Web 开发工具的概念,例如 Babel and Webpack。
或者,测试该代码的一种快速方法是使用我的 React Forge boiler,它已经使用所有这些工具进行了设置,您需要的设置步骤最少。
如果目前这对您来说是太多的新东西,这里有一个 ES5 兼容的扩展,您可以简单地将它放入 .js 文件并从您的 html 中引用,这将适用于您在问题中使用的方法:
(function(){
'use strict';
function BasicExtension(viewer, options) {
Autodesk.Viewing.Extension.call(this, viewer, options)
}
BasicExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype)
BasicExtension.prototype.constructor = BasicExtension
var proto = BasicExtension.prototype
proto.load = function () {
console.log('Basic Extension loaded!')
return true
}
proto.unload = function () {
console.log('Basic Extension unloaded!')
return true
}
proto.sayHello = function (name) {
console.log('Hi ' + name + '!')
return true
}
Autodesk.Viewing.theExtensionManager.registerExtension(
'Basic.Extension.Id',
BasicExtension)
})()
然后在您的查看器引导代码中:
forge.run
(
// divId
'ForgeViewerContainer',
// config
{
extensions:[
'Basic.Extension.Id'
]
},
我是 Forge Viewer 的新手,刚开始创建我的 Basic Application。
现在,我想尝试添加这个 extension。我做了一些搜索并将其添加到我的 HTML:
forge.run
(
// divId
'ForgeViewerContainer',
// config
{
extensions:[
'./Viewer.Skybox'
'Viewing.Extension.Showcase'
]
},
现在我要加载扩展程序。我不太明白它的窍门。任何帮助将不胜感激。
抱歉这个基本问题!
此扩展是用 ES6 编写的,因此很遗憾,您不能直接在 html 中引用脚本并将其加载到查看器中,它需要一个转换步骤才能将其转换为 ES5。您需要了解一些有关现代 Web 开发工具的概念,例如 Babel and Webpack。
或者,测试该代码的一种快速方法是使用我的 React Forge boiler,它已经使用所有这些工具进行了设置,您需要的设置步骤最少。
如果目前这对您来说是太多的新东西,这里有一个 ES5 兼容的扩展,您可以简单地将它放入 .js 文件并从您的 html 中引用,这将适用于您在问题中使用的方法:
(function(){
'use strict';
function BasicExtension(viewer, options) {
Autodesk.Viewing.Extension.call(this, viewer, options)
}
BasicExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype)
BasicExtension.prototype.constructor = BasicExtension
var proto = BasicExtension.prototype
proto.load = function () {
console.log('Basic Extension loaded!')
return true
}
proto.unload = function () {
console.log('Basic Extension unloaded!')
return true
}
proto.sayHello = function (name) {
console.log('Hi ' + name + '!')
return true
}
Autodesk.Viewing.theExtensionManager.registerExtension(
'Basic.Extension.Id',
BasicExtension)
})()
然后在您的查看器引导代码中:
forge.run
(
// divId
'ForgeViewerContainer',
// config
{
extensions:[
'Basic.Extension.Id'
]
},