diff --git a/sandbox/embed_selfhost_errors.html b/sandbox/embed_selfhost_errors.html index 1ab0c80..a445dde 100644 --- a/sandbox/embed_selfhost_errors.html +++ b/sandbox/embed_selfhost_errors.html @@ -51,6 +51,7 @@ + diff --git a/sandbox/embed_selfhost_externallibs.html b/sandbox/embed_selfhost_externallibs.html index 70700ab..3cdae34 100644 --- a/sandbox/embed_selfhost_externallibs.html +++ b/sandbox/embed_selfhost_externallibs.html @@ -51,6 +51,7 @@ + diff --git a/sandbox/embed_selfhost_fullscreen.html b/sandbox/embed_selfhost_fullscreen.html index bdf8e29..1a8fb0d 100644 --- a/sandbox/embed_selfhost_fullscreen.html +++ b/sandbox/embed_selfhost_fullscreen.html @@ -50,6 +50,7 @@ + diff --git a/sandbox/embed_selfhost_manual.html b/sandbox/embed_selfhost_manual.html index 23dae24..161915c 100644 --- a/sandbox/embed_selfhost_manual.html +++ b/sandbox/embed_selfhost_manual.html @@ -51,6 +51,7 @@ + diff --git a/sandbox/embed_selfhost_multiple.html b/sandbox/embed_selfhost_multiple.html index 673d510..f3638b3 100644 --- a/sandbox/embed_selfhost_multiple.html +++ b/sandbox/embed_selfhost_multiple.html @@ -51,6 +51,7 @@ + diff --git a/sandbox/embed_selfhost_single.html b/sandbox/embed_selfhost_single.html index 53b0691..7c203e9 100644 --- a/sandbox/embed_selfhost_single.html +++ b/sandbox/embed_selfhost_single.html @@ -50,6 +50,7 @@ + diff --git a/sandbox/embed_selfhost_single_scroll.html b/sandbox/embed_selfhost_single_scroll.html index 0e56fef..cf400e9 100644 --- a/sandbox/embed_selfhost_single_scroll.html +++ b/sandbox/embed_selfhost_single_scroll.html @@ -50,6 +50,7 @@ + diff --git a/source/import/filelist.js b/source/import/filelist.js new file mode 100644 index 0000000..0152e43 --- /dev/null +++ b/source/import/filelist.js @@ -0,0 +1,137 @@ +OV.File = class +{ + constructor (file, source) + { + this.source = source; + if (source === OV.FileSource.Url) { + this.fileUrl = file; + this.fileObject = null; + this.name = OV.GetFileName (file); + this.extension = OV.GetFileExtension (file); + } else if (source === OV.FileSource.File) { + this.fileUrl = null; + this.fileObject = file; + this.name = OV.GetFileName (file.name); + this.extension = OV.GetFileExtension (file.name); + } + this.content = null; + } + + SetContent (content) + { + this.content = content; + } +}; + +OV.FileList = class +{ + constructor () + { + this.files = []; + } + + FillFromFileUrls (fileList) + { + this.Fill (fileList, OV.FileSource.Url); + } + + FillFromFileObjects (fileList) + { + this.Fill (fileList, OV.FileSource.File); + } + + ExtendFromFileList (files) + { + for (let i = 0; i < files.length; i++) { + let file = files[i]; + if (!this.ContainsFileByPath (file.name)) { + this.files.push (file); + } + } + } + + GetFiles () + { + return this.files; + } + + GetContent (onReady) + { + let taskRunner = new OV.TaskRunner (); + taskRunner.Run (this.files.length, { + runTask : (index, complete) => { + this.GetFileContent (this.files[index], complete); + }, + onReady : onReady + }); + } + + ContainsFileByPath (filePath) + { + return this.FindFileByPath (filePath) !== null; + } + + FindFileByPath (filePath) + { + let fileName = OV.GetFileName (filePath).toLowerCase (); + for (let fileIndex = 0; fileIndex < this.files.length; fileIndex++) { + let file = this.files[fileIndex]; + if (file.name.toLowerCase () === fileName) { + return file; + } + } + return null; + } + + IsOnlyUrlSource () + { + if (this.files.length === 0) { + return false; + } + for (let i = 0; i < this.files.length; i++) { + let file = this.files[i]; + if (file.source === OV.FileSource.File) { + return false; + } + } + return true; + } + + Fill (fileList, fileSource) + { + this.files = []; + for (let fileIndex = 0; fileIndex < fileList.length; fileIndex++) { + let fileObject = fileList[fileIndex]; + let file = new OV.File (fileObject, fileSource); + this.AddFile (file); + } + } + + AddFile (file) + { + this.files.push (file); + } + + GetFileContent (file, complete) + { + if (file.content !== null) { + complete (); + return; + } + let loaderPromise = null; + if (file.source === OV.FileSource.Url) { + loaderPromise = OV.RequestUrl (file.fileUrl, OV.FileFormat.Binary); + } else if (file.source === OV.FileSource.File) { + loaderPromise = OV.ReadFile (file.fileObject, OV.FileFormat.Binary); + } else { + complete (); + return; + } + loaderPromise.then ((content) => { + file.SetContent (content); + }).catch (() => { + }).finally (() => { + complete (); + }); + } +}; diff --git a/source/import/importer.js b/source/import/importer.js index 534b453..514ca8d 100644 --- a/source/import/importer.js +++ b/source/import/importer.js @@ -1,141 +1,3 @@ -OV.File = class -{ - constructor (file, source) - { - this.source = source; - if (source === OV.FileSource.Url) { - this.fileUrl = file; - this.fileObject = null; - this.name = OV.GetFileName (file); - this.extension = OV.GetFileExtension (file); - } else if (source === OV.FileSource.File) { - this.fileUrl = null; - this.fileObject = file; - this.name = OV.GetFileName (file.name); - this.extension = OV.GetFileExtension (file.name); - } - this.content = null; - } - - SetContent (content) - { - this.content = content; - } -}; - -OV.FileList = class -{ - constructor () - { - this.files = []; - } - - FillFromFileUrls (fileList) - { - this.Fill (fileList, OV.FileSource.Url); - } - - FillFromFileObjects (fileList) - { - this.Fill (fileList, OV.FileSource.File); - } - - ExtendFromFileList (files) - { - for (let i = 0; i < files.length; i++) { - let file = files[i]; - if (!this.ContainsFileByPath (file.name)) { - this.files.push (file); - } - } - } - - GetFiles () - { - return this.files; - } - - GetContent (onReady) - { - let taskRunner = new OV.TaskRunner (); - taskRunner.Run (this.files.length, { - runTask : (index, complete) => { - this.GetFileContent (this.files[index], complete); - }, - onReady : onReady - }); - } - - ContainsFileByPath (filePath) - { - return this.FindFileByPath (filePath) !== null; - } - - FindFileByPath (filePath) - { - let fileName = OV.GetFileName (filePath).toLowerCase (); - for (let fileIndex = 0; fileIndex < this.files.length; fileIndex++) { - let file = this.files[fileIndex]; - if (file.name.toLowerCase () === fileName) { - return file; - } - } - return null; - } - - IsOnlySource (source) - { - if (this.files.length === 0) { - return false; - } - for (let i = 0; i < this.files.length; i++) { - let file = this.files[i]; - if (file.source !== source) { - return false; - } - } - return true; - } - - Fill (fileList, fileSource) - { - this.files = []; - for (let fileIndex = 0; fileIndex < fileList.length; fileIndex++) { - let fileObject = fileList[fileIndex]; - let file = new OV.File (fileObject, fileSource); - this.AddFile (file); - } - } - - AddFile (file) - { - this.files.push (file); - } - - GetFileContent (file, complete) - { - if (file.content !== null) { - complete (); - return; - } - let loaderPromise = null; - if (file.source === OV.FileSource.Url) { - loaderPromise = OV.RequestUrl (file.fileUrl, OV.FileFormat.Binary); - } else if (file.source === OV.FileSource.File) { - loaderPromise = OV.ReadFile (file.fileObject, OV.FileFormat.Binary); - } else { - complete (); - return; - } - loaderPromise.then ((content) => { - file.SetContent (content); - }).catch (() => { - }).finally (() => { - complete (); - }); - } -}; - OV.ImportSettings = class { constructor () @@ -351,11 +213,6 @@ OV.Importer = class return this.fileList; } - IsOnlyFileSource (source) - { - return this.fileList.IsOnlySource (source); - } - HasMainFile (fileList) { return this.GetMainFile (fileList) !== null; diff --git a/tools/config.json b/tools/config.json index 21b237e..2e27703 100644 --- a/tools/config.json +++ b/tools/config.json @@ -47,6 +47,7 @@ "source/import/importerthree.js", "source/import/importer3dm.js", "source/import/importerifc.js", + "source/import/filelist.js", "source/import/importer.js", "source/export/exporterbase.js", "source/export/exporterobj.js", diff --git a/website/embed.html b/website/embed.html index be424e3..5643112 100644 --- a/website/embed.html +++ b/website/embed.html @@ -60,6 +60,7 @@ + diff --git a/website/index.html b/website/index.html index 13e2559..d419f72 100644 --- a/website/index.html +++ b/website/index.html @@ -60,6 +60,7 @@ + diff --git a/website/o3dv/js/sharingdialog.js b/website/o3dv/js/sharingdialog.js index 34fecda..cc84802 100644 --- a/website/o3dv/js/sharingdialog.js +++ b/website/o3dv/js/sharingdialog.js @@ -90,7 +90,7 @@ OV.ShowSharingDialog = function (importer, settings, camera) embeddingCodeInput.val (GetEmbeddingCode (embeddingCodeParams)); } - if (!importer.IsOnlyFileSource (OV.FileSource.Url)) { + if (!importer.GetFileList ().IsOnlyUrlSource ()) { return OV.ShowMessageDialog ( 'Sharing Failed', 'Sharing works only if you load files by url. Please upload your model files to a web server, open them by url, and try embedding again.', diff --git a/website/o3dv/js/website.js b/website/o3dv/js/website.js index 1fa10ac..c847bc5 100644 --- a/website/o3dv/js/website.js +++ b/website/o3dv/js/website.js @@ -269,7 +269,7 @@ OV.Website = class ClearHashIfNotOnlyUrlList () { let importer = this.modelLoader.GetImporter (); - let isOnlyUrl = importer.IsOnlyFileSource (OV.FileSource.Url); + let isOnlyUrl = importer.GetFileList ().IsOnlyUrlSource (); if (!isOnlyUrl && this.hashHandler.HasHash ()) { this.hashHandler.SkipNextEventHandler (); this.hashHandler.ClearHash ();