From 6311e69163b4a25a7f2ffca3b9d97e30ae78dc31 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sun, 28 Apr 2024 08:34:22 +0200 Subject: [PATCH] Move CDN handling to a common place. --- source/engine/export/exporter3dm.js | 4 ++-- source/engine/import/importer3dm.js | 4 ++-- source/engine/import/importergltf.js | 4 ++-- source/engine/import/importerifc.js | 4 ++-- source/engine/import/importerutils.js | 10 ++++++++-- source/engine/io/externallibs.js | 2 +- source/engine/main.js | 7 ++++--- 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/source/engine/export/exporter3dm.js b/source/engine/export/exporter3dm.js index fcf7f358..fe5822d1 100644 --- a/source/engine/export/exporter3dm.js +++ b/source/engine/export/exporter3dm.js @@ -1,4 +1,4 @@ -import { LoadRhinoLibrary } from '../import/importerutils.js'; +import { LoadExternalLibrary } from '../import/importerutils.js'; import { FileFormat } from '../io/fileutils.js'; import { MaterialType } from '../model/material.js'; import { ConvertMeshToMeshBuffer } from '../model/meshbuffer.js'; @@ -20,7 +20,7 @@ export class Exporter3dm extends ExporterBase ExportContent (exporterModel, format, files, onFinish) { if (this.rhino === null) { - LoadRhinoLibrary ().then (() => { + LoadExternalLibrary ('rhino3dm').then (() => { rhino3dm ().then ((rhino) => { this.rhino = rhino; this.ExportRhinoContent (exporterModel, files, onFinish); diff --git a/source/engine/import/importer3dm.js b/source/engine/import/importer3dm.js index 80f8633a..f20908a9 100644 --- a/source/engine/import/importer3dm.js +++ b/source/engine/import/importer3dm.js @@ -8,7 +8,7 @@ import { IsModelEmpty } from '../model/modelutils.js'; import { Property, PropertyGroup, PropertyType } from '../model/property.js'; import { ConvertThreeGeometryToMesh } from '../threejs/threeutils.js'; import { ImporterBase } from './importerbase.js'; -import { LoadRhinoLibrary, UpdateMaterialTransparency } from './importerutils.js'; +import { LoadExternalLibrary, UpdateMaterialTransparency } from './importerutils.js'; import { TextureMap } from '../model/material.js'; import { Mesh } from '../model/mesh.js'; import { Line } from '../model/line.js'; @@ -48,7 +48,7 @@ export class Importer3dm extends ImporterBase ImportContent (fileContent, onFinish) { if (this.rhino === null) { - LoadRhinoLibrary ().then (() => { + LoadExternalLibrary ('rhino3dm').then (() => { rhino3dm ().then ((rhino) => { this.rhino = rhino; this.ImportRhinoContent (fileContent); diff --git a/source/engine/import/importergltf.js b/source/engine/import/importergltf.js index f9ef6de7..a9aa5206 100644 --- a/source/engine/import/importergltf.js +++ b/source/engine/import/importergltf.js @@ -7,7 +7,6 @@ import { ArrayToQuaternion } from '../geometry/quaternion.js'; import { Transformation } from '../geometry/transformation.js'; import { BinaryReader } from '../io/binaryreader.js'; import { ArrayBufferToUtf8String, Base64DataURIToArrayBuffer, GetFileExtensionFromMimeType } from '../io/bufferutils.js'; -import { LoadExternalLibraryFromUrl } from '../io/externallibs.js'; import { RGBColor, ColorComponentFromFloat, RGBColorFromFloatComponents, LinearToSRGB } from '../model/color.js'; import { PhongMaterial, PhysicalMaterial, TextureMap } from '../model/material.js'; import { Mesh } from '../model/mesh.js'; @@ -16,6 +15,7 @@ import { Property, PropertyGroup, PropertyType } from '../model/property.js'; import { Triangle } from '../model/triangle.js'; import { ImporterBase } from './importerbase.js'; import { Loc, FLoc } from '../core/localization.js'; +import { LoadExternalLibrary } from './importerutils.js'; const GltfComponentType = { @@ -282,7 +282,7 @@ class GltfExtensions return; } if (this.draco === null && extensionsRequired.indexOf ('KHR_draco_mesh_compression') !== -1) { - LoadExternalLibraryFromUrl ('https://cdn.jsdelivr.net/npm/draco3d@1.5.7/draco_decoder_nodejs.min.js').then (() => { + LoadExternalLibrary ('draco3d').then (() => { DracoDecoderModule ().then ((draco) => { this.draco = draco; callbacks.onSuccess (); diff --git a/source/engine/import/importerifc.js b/source/engine/import/importerifc.js index 6cb63bf0..1b6a15b5 100644 --- a/source/engine/import/importerifc.js +++ b/source/engine/import/importerifc.js @@ -2,7 +2,7 @@ import { Coord3D } from '../geometry/coord3d.js'; import { Direction } from '../geometry/geometry.js'; import { Matrix } from '../geometry/matrix.js'; import { Transformation } from '../geometry/transformation.js'; -import { LoadExternalLibrary } from '../io/externallibs.js'; +import { LoadExternalLibraryFromLibs } from '../io/externallibs.js'; import { RGBColorFromFloatComponents } from '../model/color.js'; import { Mesh } from '../model/mesh.js'; import { Property, PropertyGroup, PropertyType } from '../model/property.js'; @@ -44,7 +44,7 @@ export class ImporterIfc extends ImporterBase ImportContent (fileContent, onFinish) { if (this.ifc === null) { - LoadExternalLibrary ('web-ifc-api-browser.js').then (() => { + LoadExternalLibraryFromLibs ('web-ifc-api-browser.js').then (() => { this.ifc = new WebIFC.IfcAPI (); this.ifc.Init ().then (() => { this.ImportIfcContent (fileContent); diff --git a/source/engine/import/importerutils.js b/source/engine/import/importerutils.js index 38b97d34..8ebef7fe 100644 --- a/source/engine/import/importerutils.js +++ b/source/engine/import/importerutils.js @@ -131,7 +131,13 @@ export function CreateOcctWorker (worker) }); } -export function LoadRhinoLibrary () +export function LoadExternalLibrary (libraryName) { - return LoadExternalLibraryFromUrl ('https://cdn.jsdelivr.net/npm/rhino3dm@8.4.0/rhino3dm.min.js'); + if (libraryName === 'rhino3dm') { + return LoadExternalLibraryFromUrl ('https://cdn.jsdelivr.net/npm/rhino3dm@8.4.0/rhino3dm.min.js'); + } else if (libraryName === 'draco3d') { + return LoadExternalLibraryFromUrl ('https://cdn.jsdelivr.net/npm/draco3d@1.5.7/draco_decoder_nodejs.min.js'); + } else { + return null; + } } diff --git a/source/engine/io/externallibs.js b/source/engine/io/externallibs.js index 14c3e750..d39e32c7 100644 --- a/source/engine/io/externallibs.js +++ b/source/engine/io/externallibs.js @@ -20,7 +20,7 @@ export function GetExternalLibPath (libName) return externalLibLocation + '/' + libName; } -export function LoadExternalLibrary (libName) +export function LoadExternalLibraryFromLibs (libName) { return new Promise ((resolve, reject) => { if (externalLibLocation === null) { diff --git a/source/engine/main.js b/source/engine/main.js index 9a37d50d..3afb9932 100644 --- a/source/engine/main.js +++ b/source/engine/main.js @@ -39,11 +39,11 @@ import { ImporterPly } from './import/importerply.js'; import { ImporterStl } from './import/importerstl.js'; import { ImporterThreeSvg } from './import/importersvg.js'; import { ImporterThreeBase, ImporterThreeFbx, ImporterThreeDae, ImporterThreeWrl, ImporterThree3mf, ImporterThreeAmf } from './import/importerthree.js'; -import { ColorToMaterialConverter, NameFromLine, ParametersFromLine, ReadLines, IsPowerOfTwo, NextPowerOfTwo, UpdateMaterialTransparency, CreateOcctWorker } from './import/importerutils.js'; +import { ColorToMaterialConverter, NameFromLine, ParametersFromLine, ReadLines, IsPowerOfTwo, NextPowerOfTwo, UpdateMaterialTransparency, CreateOcctWorker, LoadExternalLibrary } from './import/importerutils.js'; import { BinaryReader } from './io/binaryreader.js'; import { BinaryWriter } from './io/binarywriter.js'; import { ArrayBufferToUtf8String, ArrayBufferToAsciiString, AsciiStringToArrayBuffer, Utf8StringToArrayBuffer, Base64DataURIToArrayBuffer, GetFileExtensionFromMimeType, CreateObjectUrl, CreateObjectUrlWithMimeType, RevokeObjectUrl } from './io/bufferutils.js'; -import { SetExternalLibLocation, GetExternalLibPath, LoadExternalLibrary, LoadExternalLibraryFromUrl } from './io/externallibs.js'; +import { SetExternalLibLocation, GetExternalLibPath, LoadExternalLibraryFromLibs, LoadExternalLibraryFromUrl } from './io/externallibs.js'; import { GetFileName, GetFileExtension, RequestUrl, ReadFile, TransformFileHostUrls, IsUrl, FileSource, FileFormat } from './io/fileutils.js'; import { TextWriter } from './io/textwriter.js'; import { RGBColor, RGBAColor, ColorComponentFromFloat, ColorComponentToFloat, RGBColorFromFloatComponents, SRGBToLinear, LinearToSRGB, IntegerToHexString, RGBColorToHexString, RGBAColorToHexString, HexStringToRGBColor, HexStringToRGBAColor, ArrayToRGBColor, RGBColorIsEqual } from './model/color.js'; @@ -194,6 +194,7 @@ export { NextPowerOfTwo, UpdateMaterialTransparency, CreateOcctWorker, + LoadExternalLibrary, BinaryReader, BinaryWriter, ArrayBufferToUtf8String, @@ -207,7 +208,7 @@ export { RevokeObjectUrl, SetExternalLibLocation, GetExternalLibPath, - LoadExternalLibrary, + LoadExternalLibraryFromLibs, LoadExternalLibraryFromUrl, GetFileName, GetFileExtension,