diff --git a/source/external/rhino.importer.js b/source/external/rhino.importer.js index f03791f..9d84c73 100644 --- a/source/external/rhino.importer.js +++ b/source/external/rhino.importer.js @@ -4,16 +4,8 @@ OV.Importer3dm = class extends OV.ImporterBase { super (); this.rhino = null; - this.instanceObjects = null; - this.instanceDefinitions = null; } - - ResetState () - { - this.instanceObjects = {}; - this.instanceDefinitions = {}; - } - + CanImportExtension (extension) { return extension === '3dm'; @@ -31,6 +23,18 @@ OV.Importer3dm = class extends OV.ImporterBase return OV.Direction.Z; } + ClearContent () + { + this.instanceObjects = null; + this.instanceDefinitions = null; + } + + ResetContent () + { + this.instanceObjects = {}; + this.instanceDefinitions = {}; + } + ImportContent (fileContent, onFinish) { if (this.rhino === null) { diff --git a/source/import/importer3ds.js b/source/import/importer3ds.js index 3ebeff5..2ea3236 100644 --- a/source/import/importer3ds.js +++ b/source/import/importer3ds.js @@ -49,21 +49,6 @@ OV.Importer3ds = class extends OV.ImporterBase constructor () { super (); - - this.materialNameToIndex = null; - this.meshNameToIndex = null; - - this.meshTransformations = null; - this.defaultMaterialIndex = null; - } - - ResetState () - { - this.materialNameToIndex = {}; - this.meshNameToIndex = {}; - - this.meshTransformations = []; - this.defaultMaterialIndex = null; } CanImportExtension (extension) @@ -81,6 +66,24 @@ OV.Importer3ds = class extends OV.ImporterBase GetUpDirection () { return OV.Direction.Z; + } + + ClearContent () + { + this.materialNameToIndex = null; + this.meshNameToIndex = null; + + this.meshTransformations = null; + this.defaultMaterialIndex = null; + } + + ResetContent () + { + this.materialNameToIndex = {}; + this.meshNameToIndex = {}; + + this.meshTransformations = []; + this.defaultMaterialIndex = null; } ImportContent (fileContent, onFinish) diff --git a/source/import/importerbase.js b/source/import/importerbase.js index debaa14..01e2371 100644 --- a/source/import/importerbase.js +++ b/source/import/importerbase.js @@ -2,15 +2,13 @@ OV.ImporterBase = class { constructor () { - this.extension = null; - this.callbacks = null; - this.model = null; - this.error = null; - this.message = null; + } Import (content, extension, callbacks) { + this.Clear (); + this.extension = extension; this.callbacks = callbacks; this.model = new OV.Model (); @@ -18,12 +16,22 @@ OV.ImporterBase = class this.message = null; let obj = this; - obj.ResetState (); - obj.ImportContent (content, function () { + this.ResetContent (); + this.ImportContent (content, function () { obj.CreateResult (callbacks); }); } + Clear () + { + this.extension = null; + this.callbacks = null; + this.model = null; + this.error = null; + this.message = null; + this.ClearContent (); + } + CreateResult (callbacks) { if (this.error) { @@ -41,11 +49,6 @@ OV.ImporterBase = class callbacks.onSuccess (); } - ResetState () - { - - } - CanImportExtension (extension) { return false; @@ -61,6 +64,16 @@ OV.ImporterBase = class return OV.Direction.Z; } + ClearContent () + { + + } + + ResetContent () + { + + } + ImportContent (fileContent, onFinish) { diff --git a/source/import/importergltf.js b/source/import/importergltf.js index e2ed638..cb975f6 100644 --- a/source/import/importergltf.js +++ b/source/import/importergltf.js @@ -348,17 +348,6 @@ OV.ImporterGltf = class extends OV.ImporterBase constructor () { super (); - - this.bufferContents = null; - this.gltfExtensions = null; - this.imageIndexToTextureParams = null; - } - - ResetState () - { - this.bufferContents = []; - this.gltfExtensions = new OV.GltfExtensions (); - this.imageIndexToTextureParams = {}; } CanImportExtension (extension) @@ -380,6 +369,20 @@ OV.ImporterGltf = class extends OV.ImporterBase return OV.Direction.Y; } + ClearContent () + { + this.bufferContents = null; + this.gltfExtensions = null; + this.imageIndexToTextureParams = null; + } + + ResetContent () + { + this.bufferContents = []; + this.gltfExtensions = new OV.GltfExtensions (); + this.imageIndexToTextureParams = {}; + } + ImportContent (fileContent, onFinish) { if (this.extension === 'gltf') { diff --git a/source/import/importerobj.js b/source/import/importerobj.js index 198bc28..c0ab107 100644 --- a/source/import/importerobj.js +++ b/source/import/importerobj.js @@ -3,33 +3,6 @@ OV.ImporterObj = class extends OV.ImporterBase constructor () { super (); - - this.globalVertices = null; - this.globalNormals = null; - this.globalUvs = null; - - this.currentMesh = null; - this.currentMeshData = null; - this.currentMaterial = null; - this.currentMaterialIndex = null; - - this.meshNameToMeshData = null; - this.materialNameToIndex = null; - } - - ResetState () - { - this.globalVertices = []; - this.globalNormals = []; - this.globalUvs = []; - - this.currentMesh = null; - this.currentMeshData = null; - this.currentMaterial = null; - this.currentMaterialIndex = null; - - this.meshNameToMeshData = {}; - this.materialNameToIndex = {}; } CanImportExtension (extension) @@ -50,6 +23,36 @@ OV.ImporterObj = class extends OV.ImporterBase return OV.Direction.Y; } + ClearContent () + { + this.globalVertices = null; + this.globalNormals = null; + this.globalUvs = null; + + this.currentMesh = null; + this.currentMeshData = null; + this.currentMaterial = null; + this.currentMaterialIndex = null; + + this.meshNameToMeshData = null; + this.materialNameToIndex = null; + } + + ResetContent () + { + this.globalVertices = []; + this.globalNormals = []; + this.globalUvs = []; + + this.currentMesh = null; + this.currentMeshData = null; + this.currentMaterial = null; + this.currentMaterialIndex = null; + + this.meshNameToMeshData = {}; + this.materialNameToIndex = {}; + } + ImportContent (fileContent, onFinish) { let obj = this; diff --git a/source/import/importeroff.js b/source/import/importeroff.js index 2cbadb9..30dbef4 100644 --- a/source/import/importeroff.js +++ b/source/import/importeroff.js @@ -3,23 +3,8 @@ OV.ImporterOff = class extends OV.ImporterBase constructor () { super (); - this.model = null; - this.mesh = null; - this.status = null; } - ResetState () - { - this.mesh = new OV.Mesh (); - this.model.AddMesh (this.mesh); - this.status = { - vertexCount : 0, - faceCount : 0, - foundVertex : 0, - foundFace : 0 - }; - } - CanImportExtension (extension) { return extension === 'off'; @@ -36,6 +21,25 @@ OV.ImporterOff = class extends OV.ImporterBase { return OV.Direction.Y; } + + ClearContent () + { + this.model = null; + this.mesh = null; + this.status = null; + } + + ResetContent () + { + this.mesh = new OV.Mesh (); + this.model.AddMesh (this.mesh); + this.status = { + vertexCount : 0, + faceCount : 0, + foundVertex : 0, + foundFace : 0 + }; + } ImportContent (fileContent, onFinish) { diff --git a/source/import/importerply.js b/source/import/importerply.js index afeae6a..4de747c 100644 --- a/source/import/importerply.js +++ b/source/import/importerply.js @@ -89,16 +89,8 @@ OV.ImporterPly = class extends OV.ImporterBase constructor () { super (); - this.model = null; - this.mesh = null; } - ResetState () - { - this.mesh = new OV.Mesh (); - this.model.AddMesh (this.mesh); - } - CanImportExtension (extension) { return extension === 'ply'; @@ -115,6 +107,18 @@ OV.ImporterPly = class extends OV.ImporterBase { return OV.Direction.Y; } + + ClearContent () + { + this.model = null; + this.mesh = null; + } + + ResetContent () + { + this.mesh = new OV.Mesh (); + this.model.AddMesh (this.mesh); + } ImportContent (fileContent, onFinish) { diff --git a/source/import/importerstl.js b/source/import/importerstl.js index bea4d72..0141a71 100644 --- a/source/import/importerstl.js +++ b/source/import/importerstl.js @@ -3,15 +3,6 @@ OV.ImporterStl = class extends OV.ImporterBase constructor () { super (); - this.mesh = null; - this.triangle = null; - } - - ResetState () - { - this.mesh = new OV.Mesh (); - this.model.AddMesh (this.mesh); - this.triangle = null; } CanImportExtension (extension) @@ -29,6 +20,19 @@ OV.ImporterStl = class extends OV.ImporterBase GetUpDirection () { return OV.Direction.Z; + } + + ClearContent () + { + this.mesh = null; + this.triangle = null; + } + + ResetContent () + { + this.mesh = new OV.Mesh (); + this.model.AddMesh (this.mesh); + this.triangle = null; } ImportContent (fileContent, onFinish)