Skip to content

Commit

Permalink
Move CDN handling to a common place.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacsv committed Apr 28, 2024
1 parent 0c4df9f commit 6311e69
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
4 changes: 2 additions & 2 deletions source/engine/export/exporter3dm.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions source/engine/import/importer3dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions source/engine/import/importergltf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 =
{
Expand Down Expand Up @@ -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 ();
Expand Down
4 changes: 2 additions & 2 deletions source/engine/import/importerifc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions source/engine/import/importerutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ export function CreateOcctWorker (worker)
});
}

export function LoadRhinoLibrary ()
export function LoadExternalLibrary (libraryName)
{
return LoadExternalLibraryFromUrl ('https://cdn.jsdelivr.net/npm/[email protected]/rhino3dm.min.js');
if (libraryName === 'rhino3dm') {
return LoadExternalLibraryFromUrl ('https://cdn.jsdelivr.net/npm/[email protected]/rhino3dm.min.js');
} else if (libraryName === 'draco3d') {
return LoadExternalLibraryFromUrl ('https://cdn.jsdelivr.net/npm/[email protected]/draco_decoder_nodejs.min.js');
} else {
return null;
}
}
2 changes: 1 addition & 1 deletion source/engine/io/externallibs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions source/engine/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -194,6 +194,7 @@ export {
NextPowerOfTwo,
UpdateMaterialTransparency,
CreateOcctWorker,
LoadExternalLibrary,
BinaryReader,
BinaryWriter,
ArrayBufferToUtf8String,
Expand All @@ -207,7 +208,7 @@ export {
RevokeObjectUrl,
SetExternalLibLocation,
GetExternalLibPath,
LoadExternalLibrary,
LoadExternalLibraryFromLibs,
LoadExternalLibraryFromUrl,
GetFileName,
GetFileExtension,
Expand Down

0 comments on commit 6311e69

Please sign in to comment.