diff --git a/source/import/importer3dm.js b/source/import/importer3dm.js index a364318..9f1cdca 100644 --- a/source/import/importer3dm.js +++ b/source/import/importer3dm.js @@ -57,14 +57,12 @@ OV.Importer3dm = class extends OV.ImporterBase { let rhinoDoc = this.rhino.File3dm.fromByteArray (fileContent); if (rhinoDoc === null) { - this.SetError (); - this.SetMessage ('Failed to read Rhino file.'); + this.SetError ('Failed to read Rhino file.'); return; } this.ImportRhinoDocument (rhinoDoc); if (OV.IsModelEmpty (this.model)) { - this.SetError (); - this.SetMessage ('The model doesn\'t contain any 3D meshes. Try to save the model while you are in shaded view in Rhino.'); + this.SetError ('The model doesn\'t contain any 3D meshes. Try to save the model while you are in shaded view in Rhino.'); } } diff --git a/source/import/importerbase.js b/source/import/importerbase.js index 119a32d..23c01f3 100644 --- a/source/import/importerbase.js +++ b/source/import/importerbase.js @@ -85,21 +85,19 @@ OV.ImporterBase = class return this.model; } - SetError () + SetError (message) { this.error = true; + if (message !== undefined && message !== null) { + this.message = message; + } } - IsError () + WasError () { return this.error; } - SetMessage (message) - { - this.message = message; - } - GetMessage () { return this.message; diff --git a/source/import/importergltf.js b/source/import/importergltf.js index c7541a6..55056f1 100644 --- a/source/import/importergltf.js +++ b/source/import/importergltf.js @@ -522,8 +522,7 @@ OV.ImporterGltf = class extends OV.ImporterBase { let gltf = JSON.parse (fileContent); if (gltf.asset.version !== '2.0') { - this.SetError (); - this.SetMessage ('Invalid glTF version.'); + this.SetError ('Invalid glTF version.'); onFinish (); return; } @@ -541,8 +540,7 @@ OV.ImporterGltf = class extends OV.ImporterBase } } if (buffer === null) { - this.SetError (); - this.SetMessage ('One of the requested buffers is missing.'); + this.SetError ('One of the requested buffers is missing.'); onFinish (); return; } @@ -568,22 +566,19 @@ OV.ImporterGltf = class extends OV.ImporterBase let reader = new OV.BinaryReader (fileContent, true); let magic = reader.ReadUnsignedInteger32 (); if (magic !== OV.GltfConstants.GLTF_STRING) { - this.SetError (); - this.SetMessage ('Invalid glTF file.'); + this.SetError ('Invalid glTF file.'); onFinish (); return; } let version = reader.ReadUnsignedInteger32 (); if (version !== 2) { - this.SetError (); - this.SetMessage ('Invalid glTF version.'); + this.SetError ('Invalid glTF version.'); onFinish (); return; } let length = reader.ReadUnsignedInteger32 (); if (length !== reader.GetByteLength ()) { - this.SetError (); - this.SetMessage ('Invalid glTF file.'); + this.SetError ('Invalid glTF file.'); onFinish (); return; } @@ -608,8 +603,7 @@ OV.ImporterGltf = class extends OV.ImporterBase { let unsupportedExtensions = this.gltfExtensions.GetUnsupportedExtensions (gltf.extensionsRequired); if (unsupportedExtensions.length > 0) { - this.SetError (); - this.SetMessage ('Unsupported extension: ' + unsupportedExtensions.join (', ') + '.'); + this.SetError ('Unsupported extension: ' + unsupportedExtensions.join (', ') + '.'); onFinish (); return; } @@ -620,8 +614,7 @@ OV.ImporterGltf = class extends OV.ImporterBase onFinish (); }, onError : () => { - this.SetError (); - this.SetMessage ('Failed to load draco decoder.'); + this.SetError ('Failed to load draco decoder.'); onFinish (); } }); @@ -631,8 +624,7 @@ OV.ImporterGltf = class extends OV.ImporterBase { let defaultScene = this.GetDefaultScene (gltf); if (defaultScene === null) { - this.SetError (); - this.SetMessage ('No default scene found.'); + this.SetError ('No default scene found.'); return; } diff --git a/source/import/importerobj.js b/source/import/importerobj.js index 35607dd..3aaa5ef 100644 --- a/source/import/importerobj.js +++ b/source/import/importerobj.js @@ -56,7 +56,7 @@ OV.ImporterObj = class extends OV.ImporterBase ImportContent (fileContent, onFinish) { OV.ReadLines (fileContent, (line) => { - if (!this.IsError ()) { + if (!this.WasError ()) { this.ProcessLine (line); } }); @@ -213,7 +213,7 @@ OV.ImporterObj = class extends OV.ImporterBase let fileBuffer = this.callbacks.getFileBuffer (fileName); if (fileBuffer !== null) { OV.ReadLines (fileBuffer, (line) => { - if (!this.IsError ()) { + if (!this.WasError ()) { this.ProcessLine (line); } }); @@ -354,8 +354,7 @@ OV.ImporterObj = class extends OV.ImporterBase let v1 = GetLocalVertexIndex (this, this.currentMesh, vertices[i + 1]); let v2 = GetLocalVertexIndex (this, this.currentMesh, vertices[i + 2]); if (v0 === null || v1 === null || v2 === null) { - this.SetError (); - this.SetMessage ('Invalid vertex index.'); + this.SetError ('Invalid vertex index.'); break; } let triangle = new OV.Triangle (v0, v1, v2); @@ -364,8 +363,7 @@ OV.ImporterObj = class extends OV.ImporterBase let n1 = GetLocalNormalIndex (this, this.currentMesh, normals[i + 1]); let n2 = GetLocalNormalIndex (this, this.currentMesh, normals[i + 2]); if (n0 === null || n1 === null || n2 === null) { - this.SetError (); - this.SetMessage ('Invalid normal index.'); + this.SetError ('Invalid normal index.'); break; } triangle.SetNormals (n0, n1, n2); @@ -375,8 +373,7 @@ OV.ImporterObj = class extends OV.ImporterBase let u1 = GetLocalUVIndex (this, this.currentMesh, uvs[i + 1]); let u2 = GetLocalUVIndex (this, this.currentMesh, uvs[i + 2]); if (u0 === null || u1 === null || u2 === null) { - this.SetError (); - this.SetMessage ('Invalid uv index.'); + this.SetError ('Invalid uv index.'); break; } triangle.SetTextureUVs (u0, u1, u2); diff --git a/source/import/importeroff.js b/source/import/importeroff.js index ca3596d..fc23777 100644 --- a/source/import/importeroff.js +++ b/source/import/importeroff.js @@ -43,7 +43,7 @@ OV.ImporterOff = class extends OV.ImporterBase ImportContent (fileContent, onFinish) { OV.ReadLines (fileContent, (line) => { - if (!this.IsError ()) { + if (!this.WasError ()) { this.ProcessLine (line); } }); diff --git a/source/import/importerply.js b/source/import/importerply.js index 32d3cd5..c799760 100644 --- a/source/import/importerply.js +++ b/source/import/importerply.js @@ -1,3 +1,11 @@ +OV.PlyHeaderCheckResult = +{ + Ok : 1, + NoVertices : 2, + NoFaces : 3, + UnknownError : 4 +}; + OV.PlyHeader = class { constructor () @@ -61,26 +69,26 @@ OV.PlyHeader = class { let vertex = this.GetElement ('vertex'); if (vertex === null || vertex.length === 0 || vertex.format.length < 3) { - return false; + return OV.PlyHeaderCheckResult.NoVertices; } let face = this.GetElement ('face'); if (this.format === 'ascii') { if (face === null || face.count === 0 || face.format.length < 0) { - return false; + return OV.PlyHeaderCheckResult.NoFaces; } } else if (this.format === 'binary_little_endian' || this.format === 'binary_big_endian') { let triStrips = this.GetElement ('tristrips'); let hasFaces = (face !== null && face.count > 0 && face.format.length > 0); let hasTriStrips = (triStrips !== null && triStrips.count > 0 && triStrips.format.length > 0); if (!hasFaces && !hasTriStrips) { - return false; + return OV.PlyHeaderCheckResult.NoFaces; } } else { - return false; + return OV.PlyHeaderCheckResult.UnknownError; } - return true; + return OV.PlyHeaderCheckResult.Ok; } }; @@ -183,7 +191,8 @@ OV.ImporterPly = class extends OV.ImporterBase { let headerString = this.GetHeaderContent (fileContent); let header = this.ReadHeader (headerString); - if (header.Check ()) { + let checkResult = header.Check (); + if (checkResult === OV.PlyHeaderCheckResult.Ok) { if (header.format === 'ascii') { let contentString = OV.ArrayBufferToUtf8String (fileContent); contentString = contentString.substr (headerString.length); @@ -192,8 +201,13 @@ OV.ImporterPly = class extends OV.ImporterBase this.ReadBinaryContent (header, fileContent, headerString.length); } } else { - this.SetError (); - this.SetMessage ('Invalid header information.'); + if (checkResult === OV.PlyHeaderCheckResult.NoVertices) { + this.SetError ('The model contains no vertices.'); + } else if (checkResult === OV.PlyHeaderCheckResult.NoFaces) { + this.SetError ('The model contains no faces.'); + } else { + this.SetError ('Invalid header information.'); + } } onFinish (); } @@ -255,7 +269,7 @@ OV.ImporterPly = class extends OV.ImporterBase let foundVertex = 0; let foundFace = 0; OV.ReadLines (fileContent, (line) => { - if (this.IsError ()) { + if (this.WasError ()) { return; } diff --git a/source/import/importerstl.js b/source/import/importerstl.js index 5f6e2c3..8b22b7c 100644 --- a/source/import/importerstl.js +++ b/source/import/importerstl.js @@ -42,7 +42,7 @@ OV.ImporterStl = class extends OV.ImporterBase } else { let textContent = OV.ArrayBufferToUtf8String (fileContent); OV.ReadLines (textContent, (line) => { - if (!this.IsError ()) { + if (!this.WasError ()) { this.ProcessLine (line); } }); diff --git a/source/threejs/threeimporter.js b/source/threejs/threeimporter.js index e4786ce..c5c1344 100644 --- a/source/threejs/threeimporter.js +++ b/source/threejs/threeimporter.js @@ -343,8 +343,7 @@ OV.ThreeImporter = class extends OV.ImporterBase () => { }, (err) => { - this.SetError (); - this.SetMessage (err); + this.SetError (err); onFinish (); } );