Restructure libs.

This commit is contained in:
kovacsv 2021-08-10 19:24:59 +02:00
parent 294ae6a975
commit 1e6e6b65af
15 changed files with 1415 additions and 27 deletions

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@ OV.Importer3dm = class extends OV.ImporterBase
ImportContent (fileContent, onFinish) ImportContent (fileContent, onFinish)
{ {
if (this.rhino === null) { if (this.rhino === null) {
OV.LoadExternalLibrary ('rhino3dm.min.js').then (() => { OV.LoadExternalLibrary ('loaders/rhino3dm.min.js').then (() => {
rhino3dm ().then ((rhino) => { rhino3dm ().then ((rhino) => {
this.rhino = rhino; this.rhino = rhino;
this.ImportRhinoContent (fileContent); this.ImportRhinoContent (fileContent);

View File

@ -271,7 +271,7 @@ OV.GltfExtensions = class
return; return;
} }
if (this.draco === null && extensionsRequired.indexOf ('KHR_draco_mesh_compression') !== -1) { if (this.draco === null && extensionsRequired.indexOf ('KHR_draco_mesh_compression') !== -1) {
OV.LoadExternalLibrary ('draco_decoder.js').then (() => { OV.LoadExternalLibrary ('loaders/draco_decoder.js').then (() => {
DracoDecoderModule ().then ((draco) => { DracoDecoderModule ().then ((draco) => {
this.draco = draco; this.draco = draco;
callbacks.onSuccess (); callbacks.onSuccess ();

View File

@ -38,7 +38,7 @@ OV.ImporterIfc = class extends OV.ImporterBase
ImportContent (fileContent, onFinish) ImportContent (fileContent, onFinish)
{ {
if (this.ifc === null) { if (this.ifc === null) {
OV.LoadExternalLibrary ('web-ifc-api.js').then (() => { OV.LoadExternalLibrary ('loaders/web-ifc-api.js').then (() => {
this.ifc = new IfcAPI (); this.ifc = new IfcAPI ();
this.ifc.Init ().then (() => { this.ifc.Init ().then (() => {
this.ImportIfcContent (fileContent); this.ImportIfcContent (fileContent);

View File

@ -24,6 +24,11 @@ OV.ThreeLoader = class
{ {
} }
GetUpDirection ()
{
return null;
}
}; };
OV.ThreeLoaderFbx = class extends OV.ThreeLoader OV.ThreeLoaderFbx = class extends OV.ThreeLoader
@ -61,6 +66,11 @@ OV.ThreeLoaderFbx = class extends OV.ThreeLoader
} }
}); });
} }
GetUpDirection ()
{
return OV.Direction.Y;
}
}; };
OV.ThreeLoaderDae = class extends OV.ThreeLoader OV.ThreeLoaderDae = class extends OV.ThreeLoader
@ -97,6 +107,11 @@ OV.ThreeLoaderDae = class extends OV.ThreeLoader
} }
}); });
} }
GetUpDirection ()
{
return OV.Direction.Y;
}
}; };
OV.ThreeLoaderVrml = class extends OV.ThreeLoader OV.ThreeLoaderVrml = class extends OV.ThreeLoader
@ -145,6 +160,51 @@ OV.ThreeLoaderVrml = class extends OV.ThreeLoader
} }
}); });
} }
GetUpDirection ()
{
return OV.Direction.Y;
}
};
OV.ThreeLoader3mf = class extends OV.ThreeLoader
{
constructor ()
{
super ();
}
GetExtension ()
{
return '3mf';
}
GetExternalLibraries ()
{
return [
'three_loaders/fflate.min.js',
'three_loaders/3MFLoader.js'
];
}
CreateLoader (manager)
{
return new THREE.ThreeMFLoader (manager);
}
EnumerateMeshes (loadedObject, processor)
{
loadedObject.traverse ((child) => {
if (child.isMesh) {
processor (child);
}
});
}
GetUpDirection ()
{
return OV.Direction.Z;
}
}; };
OV.ThreeImporter = class extends OV.ImporterBase OV.ThreeImporter = class extends OV.ImporterBase
@ -155,7 +215,8 @@ OV.ThreeImporter = class extends OV.ImporterBase
this.loaders = [ this.loaders = [
new OV.ThreeLoaderFbx (), new OV.ThreeLoaderFbx (),
new OV.ThreeLoaderDae (), new OV.ThreeLoaderDae (),
new OV.ThreeLoaderVrml () new OV.ThreeLoaderVrml (),
new OV.ThreeLoader3mf ()
]; ];
} }
@ -182,17 +243,17 @@ OV.ThreeImporter = class extends OV.ImporterBase
GetUpDirection () GetUpDirection ()
{ {
return OV.Direction.Y; return this.loader.GetUpDirection ();
} }
ClearContent () ClearContent ()
{ {
this.loader = null;
} }
ResetContent () ResetContent ()
{ {
this.loader = null;
} }
ImportContent (fileContent, onFinish) ImportContent (fileContent, onFinish)
@ -209,20 +270,20 @@ OV.ThreeImporter = class extends OV.ImporterBase
onFinish (); onFinish ();
} }
const loader = this.FindLoader (); this.loader = this.FindLoader ();
if (loader === null) { if (this.loader === null) {
onFinish (); onFinish ();
return; return;
} }
const libraries = loader.GetExternalLibraries (); const libraries = this.loader.GetExternalLibraries ();
if (libraries === null) { if (libraries === null) {
onFinish (); onFinish ();
return; return;
} }
LoadLibraries (libraries, () => { LoadLibraries (libraries, () => {
this.LoadModel (loader, fileContent, onFinish); this.LoadModel (fileContent, onFinish);
}, () => { }, () => {
onFinish (); onFinish ();
}); });
@ -239,13 +300,13 @@ OV.ThreeImporter = class extends OV.ImporterBase
return null; return null;
} }
LoadModel (loader, fileContent, onFinish) LoadModel (fileContent, onFinish)
{ {
let loadedObject = null; let loadedObject = null;
let externalFileNames = {}; let externalFileNames = {};
let loadingManager = new THREE.LoadingManager (() => { let loadingManager = new THREE.LoadingManager (() => {
if (loadedObject !== null) { if (loadedObject !== null) {
this.OnThreeObjectsLoaded (loader, loadedObject, externalFileNames, onFinish); this.OnThreeObjectsLoaded (loadedObject, externalFileNames, onFinish);
} }
}); });
@ -269,8 +330,7 @@ OV.ThreeImporter = class extends OV.ImporterBase
return url; return url;
}); });
const threeLoader = loader.CreateLoader (loadingManager); const threeLoader = this.loader.CreateLoader (loadingManager);
if (threeLoader === null) { if (threeLoader === null) {
onFinish (); onFinish ();
return; return;
@ -290,7 +350,7 @@ OV.ThreeImporter = class extends OV.ImporterBase
); );
} }
OnThreeObjectsLoaded (loader, loadedObject, externalFileNames, onFinish) OnThreeObjectsLoaded (loadedObject, externalFileNames, onFinish)
{ {
function ConvertThreeMaterialToMaterial (threeMaterial, externalFileNames) function ConvertThreeMaterialToMaterial (threeMaterial, externalFileNames)
{ {
@ -378,7 +438,7 @@ OV.ThreeImporter = class extends OV.ImporterBase
} }
let materialIdToIndex = {}; let materialIdToIndex = {};
loader.EnumerateMeshes (loadedObject, (child) => { this.loader.EnumerateMeshes (loadedObject, (child) => {
let materialIndex = null; let materialIndex = null;
let mesh = null; let mesh = null;
if (Array.isArray (child.material)) { if (Array.isArray (child.material)) {

View File

@ -109,20 +109,12 @@ def CreatePackage (rootDir, websiteDir, packageDir, version):
'three.min-129.js', 'three.min-129.js',
'three.license.md' 'three.license.md'
] ]
externalLibs = [
'draco_decoder.js',
'draco_decoder.wasm',
'draco.license.md',
'rhino3dm.min.js',
'rhino3dm.wasm',
'rhino3dm.license.md'
]
zipPath = os.path.join (packageDir, 'o3dv_' + version + '.zip') zipPath = os.path.join (packageDir, 'o3dv_' + version + '.zip')
zip = zipfile.ZipFile (zipPath, mode = 'w', compression = zipfile.ZIP_DEFLATED) zip = zipfile.ZipFile (zipPath, mode = 'w', compression = zipfile.ZIP_DEFLATED)
for lib in libs: for lib in libs:
zip.write (os.path.join (websiteDir, 'libs', lib), lib) zip.write (os.path.join (websiteDir, 'libs', lib), lib)
for lib in externalLibs: for lib in os.listdir (os.path.join (websiteDir, 'libs', 'loaders')):
zip.write (os.path.join (websiteDir, 'libs', lib), 'libs/' + lib) zip.write (os.path.join (websiteDir, 'libs', 'loaders', lib), 'libs/loaders/' + lib)
for lib in os.listdir (os.path.join (websiteDir, 'libs', 'three_loaders')): for lib in os.listdir (os.path.join (websiteDir, 'libs', 'three_loaders')):
zip.write (os.path.join (websiteDir, 'libs', 'three_loaders', lib), 'libs/three_loaders/' + lib) zip.write (os.path.join (websiteDir, 'libs', 'three_loaders', lib), 'libs/three_loaders/' + lib)
zip.write (os.path.join (websiteDir, 'o3dv', 'o3dv.min.js'), 'o3dv.min-' + version + '.js') zip.write (os.path.join (websiteDir, 'o3dv', 'o3dv.min.js'), 'o3dv.min-' + version + '.js')