Load external libraries only once.

This commit is contained in:
kovacsv 2021-06-12 18:04:21 +02:00
parent 094189ce4f
commit dde3e08687
2 changed files with 23 additions and 5 deletions

View File

@ -1,15 +1,26 @@
OV.ExternalLibLocation = null;
OV.LoadedExternalLibs = {};
OV.LoadExternalLibrary = function (libName, callbacks)
{
if (OV.ExternalLibLocation === null) {
callbacks.error ();
return;
}
if (OV.LoadedExternalLibs[libName] !== undefined) {
callbacks.success ();
return;
}
let scriptElement = document.createElement ('script');
scriptElement.type = 'text/javascript';
scriptElement.src = OV.ExternalLibLocation + '/' + libName;
scriptElement.onload = callbacks.success;
scriptElement.onload = function () {
callbacks.success ();
OV.LoadedExternalLibs[libName] = true;
};
scriptElement.onerror = callbacks.error;
document.head.appendChild (scriptElement);
};

View File

@ -15,10 +15,17 @@ OV.Exporter3dm = class extends OV.ExporterBase
{
if (this.rhino === null) {
let obj = this;
rhino3dm ().then (function (rhino) {
obj.rhino = rhino;
obj.ExportRhinoContent (model, files, onFinish);
});
OV.LoadExternalLibrary ('rhino3dm.min.js', {
success : function () {
rhino3dm ().then (function (rhino) {
obj.rhino = rhino;
obj.ExportRhinoContent (model, files, onFinish);
});
},
error : function () {
onFinish ();
}
});
} else {
this.ExportRhinoContent (model, files, onFinish);
}