您好,我正试图在我的查看器中添加一个伪造扩展,但我不知道我错过了什么。
我关注了这篇文章:https://forge.autodesk.com/blog/loading-external-extensions-forge-viewer
这是我的代码:
<body>
<div id="MyViewerDiv"></div>
<script>
var myViewerDiv = document.getElementById('MyViewerDiv');
var viewer = new Autodesk.Viewing.Private.GuiViewer3D(myViewerDiv);
var options = {
'env' : 'Local',
'document' : './modelV4/hahahah/4/output.svf',
};
Autodesk.Viewing.Initializer(options, function() {
viewer.start(options.document, options);
});
Autodesk.Viewing.theExtensionManager.registerExternalExtension(
'MyExternal.Extension.Id',
'http://localhost:3000/js/external.js')
viewer.addEventListener(
Autodesk.Viewing.GEOMETRY_LOADED_EVENT, () => {
viewer.loadExtension('MyExternal.Extension.Id').then(
function(externalExtension) {
externalExtension.sayHello('Bob')
})
})
</script>
</body>这就是我的道路:

发布于 2020-04-21 16:44:28
对于更新版本的查看器,该文章中描述的方法不再有效-您需要直接传入扩展类/函数,而不是指向扩展脚本的链接:
/**
* Registers a new extension with the given id.
*
* @param {string} extensionId - The string id of the extension.
* @param {Extension} extension - The Extension-derived class representing the extension.
* @returns {boolean} - True if the extension was successfully registered.
* @alias Autodesk.Viewing.ExtensionManager#registerExtension
*/
function registerExtension(extensionId, extension) {按照本教程here开始...
如果您想要将扩展代码包装在另一个脚本中,只需在查看器库之后使用脚本标记加载它...:
<script src='https://developer.api.autodesk.com/modelderivative/v2/viewers/viewer3D.min.js'></script>
<script src='path/to/your/extension.js'></script>https://stackoverflow.com/questions/61338735
复制相似问题