diff --git a/.eslintrc.json b/.eslintrc.json index f5733a5..db5ea0e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,6 +25,7 @@ "no-prototype-builtins": "error", "no-eval": "error", "no-useless-escape": "error", + "prefer-arrow-callback" : "error", "quotes": ["error", "single"], "block-scoped-var": "error", "no-loop-func": "error", diff --git a/source/core/taskrunner.js b/source/core/taskrunner.js index 1e19c99..511dab1 100644 --- a/source/core/taskrunner.js +++ b/source/core/taskrunner.js @@ -26,7 +26,7 @@ OV.TaskRunner = class stepCount = parseInt ((count - 1) / batchCount, 10) + 1; } this.Run (stepCount, { - runTask : function (index, ready) { + runTask : (index, ready) => { const firstIndex = index * batchCount; const lastIndex = Math.min ((index + 1) * batchCount, count) - 1; callbacks.runTask (firstIndex, lastIndex, ready); @@ -37,9 +37,8 @@ OV.TaskRunner = class RunOnce () { - let obj = this; - setTimeout (function () { - obj.callbacks.runTask (obj.current, obj.TaskReady.bind (obj)); + setTimeout (() => { + this.callbacks.runTask (this.current, this.TaskReady.bind (this)); }, 0); } @@ -58,7 +57,7 @@ OV.TaskRunner = class OV.RunTaskAsync = function (task) { - setTimeout (function () { + setTimeout (() => { task (); }, 0); }; diff --git a/source/export/exporter.js b/source/export/exporter.js index 54eb751..752f0e1 100644 --- a/source/export/exporter.js +++ b/source/export/exporter.js @@ -31,7 +31,7 @@ OV.Exporter = class return; } - exporter.Export (model, format, function (files) { + exporter.Export (model, format, (files) => { if (files.length === 0) { callbacks.onError (); } else { diff --git a/source/export/exporterbase.js b/source/export/exporterbase.js index 889505e..092dff1 100644 --- a/source/export/exporterbase.js +++ b/source/export/exporterbase.js @@ -42,7 +42,7 @@ OV.ExporterBase = class Export (model, format, onFinish) { let files = []; - this.ExportContent (model, format, files, function () { + this.ExportContent (model, format, files, () => { onFinish (files); }); } diff --git a/source/export/exportergltf.js b/source/export/exportergltf.js index dce8a91..5f8432d 100644 --- a/source/export/exportergltf.js +++ b/source/export/exportergltf.js @@ -46,7 +46,7 @@ OV.ExporterGltf = class extends OV.ExporterBase }); let fileNameToIndex = []; - this.ExportMaterials (model, mainJson, function (texture) { + this.ExportMaterials (model, mainJson, (texture) => { let fileName = OV.GetFileName (texture.name); let textureIndex = fileNameToIndex[fileName]; if (textureIndex === undefined) { @@ -100,7 +100,7 @@ OV.ExporterGltf = class extends OV.ExporterBase let textureOffset = mainBuffer.byteLength; let fileNameToIndex = []; - this.ExportMaterials (model, mainJson, function (texture) { + this.ExportMaterials (model, mainJson, (texture) => { let fileName = OV.GetFileName (texture.name); let extension = OV.GetFileExtension (texture.name); let textureIndex = fileNameToIndex[fileName]; diff --git a/source/export/exporterobj.js b/source/export/exporterobj.js index be56287..08dbc50 100644 --- a/source/export/exporterobj.js +++ b/source/export/exporterobj.js @@ -20,7 +20,7 @@ OV.ExporterObj = class extends OV.ExporterBase let fileName = OV.GetFileName (texture.name); mtlWriter.WriteArrayLine ([keyword, fileName]); - let fileIndex = files.findIndex (function (file) { + let fileIndex = files.findIndex ((file) => { return file.GetName () === fileName; }); if (fileIndex === -1) { diff --git a/source/export/exporterstl.js b/source/export/exporterstl.js index 6541947..904a764 100644 --- a/source/export/exporterstl.js +++ b/source/export/exporterstl.js @@ -27,7 +27,7 @@ OV.ExporterStl = class extends OV.ExporterBase let stlWriter = new OV.TextWriter (); stlWriter.WriteLine ('solid Model'); - OV.EnumerateTrianglesWithNormals (model, function (v0, v1, v2, normal) { + OV.EnumerateTrianglesWithNormals (model, (v0, v1, v2, normal) => { stlWriter.WriteArrayLine (['facet', 'normal', normal.x, normal.y, normal.z]); stlWriter.Indent (1); stlWriter.WriteLine ('outer loop'); @@ -60,7 +60,7 @@ OV.ExporterStl = class extends OV.ExporterBase } stlWriter.WriteUnsignedInteger32 (triangleCount); - OV.EnumerateTrianglesWithNormals (model, function (v0, v1, v2, normal) { + OV.EnumerateTrianglesWithNormals (model, (v0, v1, v2, normal) => { stlWriter.WriteFloat32 (normal.x); stlWriter.WriteFloat32 (normal.y); stlWriter.WriteFloat32 (normal.z); diff --git a/source/external/ifcimporter.js b/source/external/ifcimporter.js index 685e41f..a3397f1 100644 --- a/source/external/ifcimporter.js +++ b/source/external/ifcimporter.js @@ -38,16 +38,15 @@ OV.ImporterIfc = class extends OV.ImporterBase ImportContent (fileContent, onFinish) { if (this.ifc === null) { - let obj = this; OV.LoadExternalLibrary ('web-ifc-api.js', { - success : function () { - obj.ifc = new IfcAPI (); - obj.ifc.Init ().then (function () { - obj.ImportIfcContent (fileContent); + success : () => { + this.ifc = new IfcAPI (); + this.ifc.Init ().then (() => { + this.ImportIfcContent (fileContent); onFinish (); }); }, - error : function () { + error : () => { onFinish (); } }); @@ -118,19 +117,18 @@ OV.ImporterIfc = class extends OV.ImporterBase ImportProperties (modelID) { - let obj = this; // TODO: var IFCRELDEFINESBYPROPERTIES = 4186316022; // TODO: var IFCBUILDING = 4031249490; const lines = this.ifc.GetLineIDsWithType (modelID, 4186316022); for (let i = 0; i < lines.size (); i++) { const relID = lines.get (i); const rel = this.ifc.GetLine (modelID, relID); - rel.RelatedObjects.forEach (function (objectRelID) { - let element = obj.expressIDToMesh[objectRelID.value]; + rel.RelatedObjects.forEach ((objectRelID) => { + let element = this.expressIDToMesh[objectRelID.value]; if (element === undefined) { - let propSetOwner = obj.ifc.GetLine (modelID, objectRelID.value, true); + let propSetOwner = this.ifc.GetLine (modelID, objectRelID.value, true); if (propSetOwner.type === 4031249490) { - element = obj.model; + element = this.model; } else { return; } @@ -139,22 +137,22 @@ OV.ImporterIfc = class extends OV.ImporterBase return; } let propSetDef = rel.RelatingPropertyDefinition; - let propSet = obj.ifc.GetLine (modelID, propSetDef.value, true); + let propSet = this.ifc.GetLine (modelID, propSetDef.value, true); if (!propSet || !propSet.HasProperties) { return; } let propertyGroup = new OV.PropertyGroup (propSet.Name.value); - propSet.HasProperties.forEach (function (property) { + propSet.HasProperties.forEach ((property) => { if (!property || !property.Name || !property.NominalValue) { return; } let elemProperty = null; - let propertyName = obj.GetIFCString (property.Name.value); + let propertyName = this.GetIFCString (property.Name.value); switch (property.NominalValue.label) { case 'IFCTEXT': case 'IFCLABEL': case 'IFCIDENTIFIER': - elemProperty = new OV.Property (OV.PropertyType.Text, propertyName, obj.GetIFCString (property.NominalValue.value)); + elemProperty = new OV.Property (OV.PropertyType.Text, propertyName, this.GetIFCString (property.NominalValue.value)); break; case 'IFCBOOLEAN': elemProperty = new OV.Property (OV.PropertyType.Boolean, propertyName, property.NominalValue.value === 'T' ? true : false); diff --git a/source/external/rhinoexporter.js b/source/external/rhinoexporter.js index 376de9f..dd608bc 100644 --- a/source/external/rhinoexporter.js +++ b/source/external/rhinoexporter.js @@ -14,15 +14,14 @@ OV.Exporter3dm = class extends OV.ExporterBase ExportContent (model, format, files, onFinish) { if (this.rhino === null) { - let obj = this; OV.LoadExternalLibrary ('rhino3dm.min.js', { - success : function () { - rhino3dm ().then (function (rhino) { - obj.rhino = rhino; - obj.ExportRhinoContent (model, files, onFinish); + success : () => { + rhino3dm ().then ((rhino) => { + this.rhino = rhino; + this.ExportRhinoContent (model, files, onFinish); }); }, - error : function () { + error : () => { onFinish (); } }); diff --git a/source/external/rhinoimporter.js b/source/external/rhinoimporter.js index ede4a1d..5a5f897 100644 --- a/source/external/rhinoimporter.js +++ b/source/external/rhinoimporter.js @@ -38,16 +38,15 @@ OV.Importer3dm = class extends OV.ImporterBase ImportContent (fileContent, onFinish) { if (this.rhino === null) { - let obj = this; OV.LoadExternalLibrary ('rhino3dm.min.js', { - success : function () { - rhino3dm ().then (function (rhino) { - obj.rhino = rhino; - obj.ImportRhinoContent (fileContent); + success : () => { + rhino3dm ().then ((rhino) => { + this.rhino = rhino; + this.ImportRhinoContent (fileContent); onFinish (); }); }, - error : function () { + error : () => { onFinish (); } }); diff --git a/source/external/threeconverter.js b/source/external/threeconverter.js index e97e34b..6df8854 100644 --- a/source/external/threeconverter.js +++ b/source/external/threeconverter.js @@ -35,7 +35,7 @@ OV.ConvertModelToThreeMeshes = function (model, params, result, callbacks) return; } let loader = new THREE.TextureLoader (); - loader.load (texture.url, function (threeTexture) { + loader.load (texture.url, (threeTexture) => { SetTextureParameters (texture, threeTexture); threeTexture.image = OV.ResizeImageToPowerOfTwoSides (threeTexture.image); threeMaterial.needsUpdate = true; @@ -66,26 +66,26 @@ OV.ConvertModelToThreeMeshes = function (model, params, result, callbacks) } let threeMaterial = new THREE.MeshPhongMaterial (materialParams); - LoadTexture (threeMaterial, material.diffuseMap, function (threeTexture) { + LoadTexture (threeMaterial, material.diffuseMap, (threeTexture) => { if (!material.multiplyDiffuseMap) { threeMaterial.color.setRGB (1.0, 1.0, 1.0); } threeMaterial.map = threeTexture; callbacks.onTextureLoaded (); }); - LoadTexture (threeMaterial, material.specularMap, function (threeTexture) { + LoadTexture (threeMaterial, material.specularMap, (threeTexture) => { threeMaterial.specularMap = threeTexture; callbacks.onTextureLoaded (); }); - LoadTexture (threeMaterial, material.bumpMap, function (threeTexture) { + LoadTexture (threeMaterial, material.bumpMap, (threeTexture) => { threeMaterial.bumpMap = threeTexture; callbacks.onTextureLoaded (); }); - LoadTexture (threeMaterial, material.normalMap, function (threeTexture) { + LoadTexture (threeMaterial, material.normalMap, (threeTexture) => { threeMaterial.normalMap = threeTexture; callbacks.onTextureLoaded (); }); - LoadTexture (threeMaterial, material.emissiveMap, function (threeTexture) { + LoadTexture (threeMaterial, material.emissiveMap, (threeTexture) => { threeMaterial.emissiveMap = threeTexture; callbacks.onTextureLoaded (); }); @@ -109,7 +109,7 @@ OV.ConvertModelToThreeMeshes = function (model, params, result, callbacks) for (let i = 0; i < triangleCount; i++) { triangleIndices.push (i); } - triangleIndices.sort (function (a, b) { + triangleIndices.sort ((a, b) => { let aTriangle = mesh.GetTriangle (a); let bTriangle = mesh.GetTriangle (b); return aTriangle.mat - bTriangle.mat; diff --git a/source/external/threemodelloader.js b/source/external/threemodelloader.js index 2614a34..34033d3 100644 --- a/source/external/threemodelloader.js +++ b/source/external/threemodelloader.js @@ -22,11 +22,10 @@ OV.ThreeModelLoader = class return; } - let obj = this; this.inProgress = true; this.callbacks.onLoadStart (); - this.importer.LoadFilesFromUrls (urls, function () { - obj.OnFilesLoaded (settings); + this.importer.LoadFilesFromUrls (urls, () => { + this.OnFilesLoaded (settings); }); } @@ -36,11 +35,10 @@ OV.ThreeModelLoader = class return; } - let obj = this; this.inProgress = true; this.callbacks.onLoadStart (); - this.importer.LoadFilesFromFileObjects (files, function () { - obj.OnFilesLoaded (settings); + this.importer.LoadFilesFromFileObjects (files, () => { + this.OnFilesLoaded (settings); }); } @@ -57,16 +55,15 @@ OV.ThreeModelLoader = class OnFilesLoaded (settings) { - let obj = this; this.callbacks.onImportStart (); - OV.RunTaskAsync (function () { - obj.importer.Import (settings, { - onSuccess : function (importResult) { - obj.OnModelImported (importResult); + OV.RunTaskAsync (() => { + this.importer.Import (settings, { + onSuccess : (importResult) => { + this.OnModelImported (importResult); }, - onError : function (importError) { - obj.callbacks.onLoadError (importError); - obj.inProgress = false; + onError : (importError) => { + this.callbacks.onLoadError (importError); + this.inProgress = false; } }); }); @@ -74,19 +71,18 @@ OV.ThreeModelLoader = class OnModelImported (importResult) { - let obj = this; this.callbacks.onVisualizationStart (); let params = new OV.ModelToThreeConversionParams (); params.forceMediumpForMaterials = this.hasHighpDriverIssue; let result = new OV.ModelToThreeConversionResult (); OV.ConvertModelToThreeMeshes (importResult.model, params, result, { - onTextureLoaded : function () { - obj.callbacks.onTextureLoaded (); + onTextureLoaded : () => { + this.callbacks.onTextureLoaded (); }, - onModelLoaded : function (meshes) { - obj.defaultMaterial = result.defaultMaterial; - obj.callbacks.onModelFinished (importResult, meshes); - obj.inProgress = false; + onModelLoaded : (meshes) => { + this.defaultMaterial = result.defaultMaterial; + this.callbacks.onModelFinished (importResult, meshes); + this.inProgress = false; } }); } diff --git a/source/import/importer.js b/source/import/importer.js index 7e5c156..76d5c61 100644 --- a/source/import/importer.js +++ b/source/import/importer.js @@ -53,11 +53,10 @@ OV.FileList = class GetContent (onReady) { - let obj = this; let taskRunner = new OV.TaskRunner (); taskRunner.Run (this.files.length, { - runTask : function (index, complete) { - obj.GetFileContent (obj.files[index], complete); + runTask : (index, complete) => { + this.GetFileContent (this.files[index], complete); }, onReady : onReady }); @@ -132,13 +131,13 @@ OV.FileList = class GetFileContent (file, complete) { let callbacks = { - success : function (content) { + success : (content) => { file.content = content; }, - error : function () { + error : () => { }, - complete : function () { + complete : () => { complete (); } }; @@ -303,50 +302,49 @@ OV.Importer = class this.missingFiles = []; this.usedFiles.push (mainFile.file.name); - let obj = this; let importer = mainFile.importer; - let buffers = new OV.ImportBuffers (function (fileName) { + let buffers = new OV.ImportBuffers ((fileName) => { let fileBuffer = null; - let file = obj.fileList.FindFileByPath (fileName); + let file = this.fileList.FindFileByPath (fileName); if (file === null || file.content === null) { - obj.missingFiles.push (fileName); + this.missingFiles.push (fileName); fileBuffer = null; } else { fileBuffer = file.content; - obj.usedFiles.push (fileName); + this.usedFiles.push (fileName); } return fileBuffer; }); importer.Import (mainFile.file.content, mainFile.file.extension, { - getDefaultMaterial : function () { + getDefaultMaterial : () => { let material = new OV.Material (); material.diffuse = settings.defaultColor; return material; }, - getFileBuffer : function (filePath) { + getFileBuffer : (filePath) => { return buffers.GetFileBuffer (filePath); }, - getTextureBuffer : function (filePath) { + getTextureBuffer : (filePath) => { return buffers.GetTextureBuffer (filePath); }, - onSuccess : function () { - obj.model = importer.GetModel (); - obj.model.SetName (mainFile.file.name); + onSuccess : () => { + this.model = importer.GetModel (); + this.model.SetName (mainFile.file.name); let result = new OV.ImportResult (); result.mainFile = mainFile.file.name; - result.model = obj.model; - result.usedFiles = obj.usedFiles; - result.missingFiles = obj.missingFiles; + result.model = this.model; + result.usedFiles = this.usedFiles; + result.missingFiles = this.missingFiles; result.upVector = importer.GetUpDirection (); callbacks.onSuccess (result); }, - onError : function () { + onError : () => { let message = importer.GetMessage (); callbacks.onError (new OV.ImportError (OV.ImportErrorCode.ImportFailed, message)); }, - onComplete : function () { + onComplete : () => { importer.Clear (); } }); @@ -382,7 +380,7 @@ OV.Importer = class if (reset) { this.fileList = newFileList; } - this.fileList.GetContent (function () { + this.fileList.GetContent (() => { onReady (); }); } @@ -404,7 +402,7 @@ OV.Importer = class } for (let i = 0; i < this.model.MaterialCount (); i++) { let material = this.model.GetMaterial (i); - material.EnumerateTextureMaps (function (texture) { + material.EnumerateTextureMaps ((texture) => { if (texture.url !== null) { OV.RevokeObjectUrl (texture.url); } diff --git a/source/import/importer3ds.js b/source/import/importer3ds.js index fffe23d..4a4bfab 100644 --- a/source/import/importer3ds.js +++ b/source/import/importer3ds.js @@ -94,76 +94,72 @@ OV.Importer3ds = class extends OV.ImporterBase ProcessBinary (fileContent) { - let obj = this; let reader = new OV.BinaryReader (fileContent, true); let endByte = reader.GetByteLength (); - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.MAIN3DS) { - obj.ReadMainChunk (reader, chunkLength); + this.ReadMainChunk (reader, chunkLength); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); } ReadMainChunk (reader, length) { - let obj = this; let endByte = this.GetChunkEnd (reader, length); - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.EDIT3DS) { - obj.ReadEditorChunk (reader, chunkLength); + this.ReadEditorChunk (reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.KF3DS) { - obj.ReadKeyFrameChunk (reader, chunkLength); + this.ReadKeyFrameChunk (reader, chunkLength); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); } ReadEditorChunk (reader, length) { - let obj = this; let endByte = this.GetChunkEnd (reader, length); - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.EDIT_MATERIAL) { - obj.ReadMaterialChunk (reader, chunkLength); + this.ReadMaterialChunk (reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.EDIT_OBJECT) { - obj.ReadObjectChunk (reader, chunkLength); + this.ReadObjectChunk (reader, chunkLength); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); } ReadMaterialChunk (reader, length) { - let obj = this; let material = new OV.Material (); let endByte = this.GetChunkEnd (reader, length); let shininess = null; let shininessStrength = null; - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.MAT_NAME) { - material.name = obj.ReadName (reader); + material.name = this.ReadName (reader); } else if (chunkId === OV.CHUNK3DS.MAT_AMBIENT) { - material.ambient = obj.ReadColorChunk (reader, chunkLength); + material.ambient = this.ReadColorChunk (reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.MAT_DIFFUSE) { - material.diffuse = obj.ReadColorChunk (reader, chunkLength); + material.diffuse = this.ReadColorChunk (reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.MAT_SPECULAR) { - material.specular = obj.ReadColorChunk (reader, chunkLength); + material.specular = this.ReadColorChunk (reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.MAT_SHININESS) { - shininess = obj.ReadPercentageChunk (reader, chunkLength); + shininess = this.ReadPercentageChunk (reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.MAT_SHININESS_STRENGTH) { - shininessStrength = obj.ReadPercentageChunk (reader, chunkLength); + shininessStrength = this.ReadPercentageChunk (reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.MAT_TRANSPARENCY) { - material.opacity = 1.0 - obj.ReadPercentageChunk (reader, chunkLength); + material.opacity = 1.0 - this.ReadPercentageChunk (reader, chunkLength); OV.UpdateMaterialTransparency (material); } else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP) { - material.diffuseMap = obj.ReadTextureMapChunk (reader, chunkLength); + material.diffuseMap = this.ReadTextureMapChunk (reader, chunkLength); OV.UpdateMaterialTransparency (material); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); @@ -176,13 +172,12 @@ OV.Importer3ds = class extends OV.ImporterBase ReadTextureMapChunk (reader, length) { - let obj = this; let texture = new OV.TextureMap (); let endByte = this.GetChunkEnd (reader, length); - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.MAT_TEXMAP_NAME) { - let textureName = obj.ReadName (reader); - let textureBuffer = obj.callbacks.getTextureBuffer (textureName); + let textureName = this.ReadName (reader); + let textureBuffer = this.callbacks.getTextureBuffer (textureName); texture.name = textureName; if (textureBuffer !== null) { texture.url = textureBuffer.url; @@ -199,7 +194,7 @@ OV.Importer3ds = class extends OV.ImporterBase } else if (chunkId === OV.CHUNK3DS.MAT_TEXMAP_ROTATION) { texture.rotation = reader.ReadFloat32 () * OV.DegRad; } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); return texture; @@ -207,11 +202,10 @@ OV.Importer3ds = class extends OV.ImporterBase ReadColorChunk (reader, length) { - let obj = this; let color = new OV.Color (0, 0, 0); let endByte = this.GetChunkEnd (reader, length); let hasLinColor = false; - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.MAT_COLOR) { if (!hasLinColor) { color.r = reader.ReadUnsignedCharacter8 (); @@ -235,7 +229,7 @@ OV.Importer3ds = class extends OV.ImporterBase color.b = parseInt (reader.ReadFloat32 () * 255.0, 10); hasLinColor = true; } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); return color; @@ -243,16 +237,15 @@ OV.Importer3ds = class extends OV.ImporterBase ReadPercentageChunk (reader, length) { - let obj = this; let percentage = 0.0; let endByte = this.GetChunkEnd (reader, length); - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.PERCENTAGE) { percentage = reader.ReadUnsignedInteger16 () / 100.0; } else if (chunkId === OV.CHUNK3DS.PERCENTAGE_F) { percentage = reader.ReadFloat32 (); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); return percentage; @@ -260,42 +253,39 @@ OV.Importer3ds = class extends OV.ImporterBase ReadObjectChunk (reader, length) { - let obj = this; let endByte = this.GetChunkEnd (reader, length); let objectName = this.ReadName (reader); - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.OBJ_TRIMESH) { - obj.ReadMeshChunk (reader, chunkLength, objectName); + this.ReadMeshChunk (reader, chunkLength, objectName); } else if (chunkId === OV.CHUNK3DS.OBJ_LIGHT) { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.OBJ_CAMERA) { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); } ReadMeshChunk (reader, length, objectName) { - let obj = this; - let mesh = new OV.Mesh (); mesh.SetName (objectName); let endByte = this.GetChunkEnd (reader, length); let transformation = null; - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.TRI_VERTEX) { - obj.ReadVerticesChunk (mesh, reader); + this.ReadVerticesChunk (mesh, reader); } else if (chunkId === OV.CHUNK3DS.TRI_TEXVERTEX) { - obj.ReadTextureVerticesChunk (mesh, reader); + this.ReadTextureVerticesChunk (mesh, reader); } else if (chunkId === OV.CHUNK3DS.TRI_FACE) { - obj.ReadFacesChunk (mesh, reader, chunkLength); + this.ReadFacesChunk (mesh, reader, chunkLength); } else if (chunkId === OV.CHUNK3DS.TRI_TRANSFORMATION) { - transformation = obj.ReadTransformationChunk (reader); + transformation = this.ReadTransformationChunk (reader); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); @@ -348,14 +338,13 @@ OV.Importer3ds = class extends OV.ImporterBase mesh.AddTriangle (new OV.Triangle (v0, v1, v2)); } - let obj = this; - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.TRI_MATERIAL) { - obj.ReadFaceMaterialsChunk (mesh, reader); + this.ReadFaceMaterialsChunk (mesh, reader); } else if (chunkId === OV.CHUNK3DS.TRI_SMOOTH) { - obj.ReadFaceSmoothingGroupsChunk (mesh, faceCount, reader); + this.ReadFaceSmoothingGroupsChunk (mesh, faceCount, reader); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); } @@ -408,12 +397,11 @@ OV.Importer3ds = class extends OV.ImporterBase }; let endByte = this.GetChunkEnd (reader, length); - let obj = this; - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.OBJECT_NODE) { - obj.ReadObjectNodeChunk (nodeHierarchy, reader, chunkLength); + this.ReadObjectNodeChunk (nodeHierarchy, reader, chunkLength); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); @@ -606,27 +594,26 @@ OV.Importer3ds = class extends OV.ImporterBase matrix : null }; - let obj = this; let endByte = this.GetChunkEnd (reader, length); - this.ReadChunks (reader, endByte, function (chunkId, chunkLength) { + this.ReadChunks (reader, endByte, (chunkId, chunkLength) => { if (chunkId === OV.CHUNK3DS.OBJECT_HIERARCHY) { - objectNode.name = obj.ReadName (reader); + objectNode.name = this.ReadName (reader); objectNode.flags = reader.ReadUnsignedInteger32 (); objectNode.userId = reader.ReadUnsignedInteger16 (); } else if (chunkId === OV.CHUNK3DS.OBJECT_INSTANCE_NAME) { - objectNode.instanceName = obj.ReadName (reader); + objectNode.instanceName = this.ReadName (reader); } else if (chunkId === OV.CHUNK3DS.OBJECT_PIVOT) { - objectNode.pivot = obj.ReadVector (reader); + objectNode.pivot = this.ReadVector (reader); } else if (chunkId === OV.CHUNK3DS.OBJECT_POSITION) { - objectNode.positions = ReadTrackVector (obj, reader, OV.CHUNK3DS.OBJECT_POSITION); + objectNode.positions = ReadTrackVector (this, reader, OV.CHUNK3DS.OBJECT_POSITION); } else if (chunkId === OV.CHUNK3DS.OBJECT_ROTATION) { - objectNode.rotations = ReadTrackVector (obj, reader, OV.CHUNK3DS.OBJECT_ROTATION); + objectNode.rotations = ReadTrackVector (this, reader, OV.CHUNK3DS.OBJECT_ROTATION); } else if (chunkId === OV.CHUNK3DS.OBJECT_SCALE) { - objectNode.scales = ReadTrackVector (obj, reader, OV.CHUNK3DS.OBJECT_SCALE); + objectNode.scales = ReadTrackVector (this, reader, OV.CHUNK3DS.OBJECT_SCALE); } else if (chunkId === OV.CHUNK3DS.OBJECT_ID) { objectNode.nodeId = reader.ReadUnsignedInteger16 (); } else { - obj.SkipChunk (reader, chunkLength); + this.SkipChunk (reader, chunkLength); } }); diff --git a/source/import/importerbase.js b/source/import/importerbase.js index f9bb20d..119a32d 100644 --- a/source/import/importerbase.js +++ b/source/import/importerbase.js @@ -15,10 +15,8 @@ OV.ImporterBase = class this.error = false; this.message = null; this.ResetContent (); - - let obj = this; - this.ImportContent (content, function () { - obj.CreateResult (callbacks); + this.ImportContent (content, () => { + this.CreateResult (callbacks); }); } diff --git a/source/import/importergltf.js b/source/import/importergltf.js index 763d86c..c79c534 100644 --- a/source/import/importergltf.js +++ b/source/import/importergltf.js @@ -613,9 +613,8 @@ OV.ImporterGltf = class extends OV.ImporterBase } } - let obj = this; - this.gltfExtensions.ProcessMaterial (gltfMaterial, material, function (textureRef) { - return obj.ImportTexture (gltf, textureRef); + this.gltfExtensions.ProcessMaterial (gltfMaterial, material, (textureRef) => { + return this.ImportTexture (gltf, textureRef); }); this.model.AddMaterial (material); } @@ -810,7 +809,7 @@ OV.ImporterGltf = class extends OV.ImporterBase if (reader === null) { return; } - reader.EnumerateData (function (data) { + reader.EnumerateData ((data) => { mesh.AddVertex (data); }); } else { @@ -823,7 +822,7 @@ OV.ImporterGltf = class extends OV.ImporterBase if (reader === null) { return; } - reader.EnumerateData (function (data) { + reader.EnumerateData ((data) => { mesh.AddNormal (data); }); } @@ -834,7 +833,7 @@ OV.ImporterGltf = class extends OV.ImporterBase if (reader === null) { return; } - reader.EnumerateData (function (data) { + reader.EnumerateData ((data) => { data.y = -data.y; mesh.AddTextureUV (data); }); @@ -847,7 +846,7 @@ OV.ImporterGltf = class extends OV.ImporterBase if (reader === null) { return; } - reader.EnumerateData (function (data) { + reader.EnumerateData ((data) => { vertexIndices.push (data); }); } else { diff --git a/source/import/importerobj.js b/source/import/importerobj.js index cedcac1..472050b 100644 --- a/source/import/importerobj.js +++ b/source/import/importerobj.js @@ -55,10 +55,9 @@ OV.ImporterObj = class extends OV.ImporterBase ImportContent (fileContent, onFinish) { - let obj = this; - OV.ReadLines (fileContent, function (line) { - if (!obj.IsError ()) { - obj.ProcessLine (line); + OV.ReadLines (fileContent, (line) => { + if (!this.IsError ()) { + this.ProcessLine (line); } }); onFinish (); @@ -183,7 +182,6 @@ OV.ImporterObj = class extends OV.ImporterBase return texture; } - let obj = this; if (keyword === 'newmtl') { if (parameters.length === 0) { return true; @@ -214,9 +212,9 @@ OV.ImporterObj = class extends OV.ImporterBase let fileName = OV.NameFromLine (line, keyword.length, '#'); let fileBuffer = this.callbacks.getFileBuffer (fileName); if (fileBuffer !== null) { - OV.ReadLines (fileBuffer, function (line) { - if (!obj.IsError ()) { - obj.ProcessLine (line); + OV.ReadLines (fileBuffer, (line) => { + if (!this.IsError ()) { + this.ProcessLine (line); } }); } @@ -313,21 +311,21 @@ OV.ImporterObj = class extends OV.ImporterBase function GetLocalVertexIndex (obj, mesh, globalIndex) { - return GetLocalIndex (obj.globalVertices, obj.currentMeshData.globalToCurrentVertices, globalIndex, function (val) { + return GetLocalIndex (obj.globalVertices, obj.currentMeshData.globalToCurrentVertices, globalIndex, (val) => { return mesh.AddVertex (new OV.Coord3D (val.x, val.y, val.z)); }); } function GetLocalNormalIndex (obj, mesh, globalIndex) { - return GetLocalIndex (obj.globalNormals, obj.currentMeshData.globalToCurrentNormals, globalIndex, function (val) { + return GetLocalIndex (obj.globalNormals, obj.currentMeshData.globalToCurrentNormals, globalIndex, (val) => { return mesh.AddNormal (new OV.Coord3D (val.x, val.y, val.z)); }); } function GetLocalUVIndex (obj, mesh, globalIndex) { - return GetLocalIndex (obj.globalUvs, obj.currentMeshData.globalToCurrentUvs, globalIndex, function (val) { + return GetLocalIndex (obj.globalUvs, obj.currentMeshData.globalToCurrentUvs, globalIndex, (val) => { return mesh.AddTextureUV (new OV.Coord2D (val.x, val.y)); }); } diff --git a/source/import/importeroff.js b/source/import/importeroff.js index 9e7d9e6..ca3596d 100644 --- a/source/import/importeroff.js +++ b/source/import/importeroff.js @@ -42,10 +42,9 @@ OV.ImporterOff = class extends OV.ImporterBase ImportContent (fileContent, onFinish) { - let obj = this; - OV.ReadLines (fileContent, function (line) { - if (!obj.IsError ()) { - obj.ProcessLine (line); + OV.ReadLines (fileContent, (line) => { + if (!this.IsError ()) { + this.ProcessLine (line); } }); onFinish (); diff --git a/source/import/importerply.js b/source/import/importerply.js index 5c966a0..e0eb83b 100644 --- a/source/import/importerply.js +++ b/source/import/importerply.js @@ -164,7 +164,7 @@ OV.ImporterPly = class extends OV.ImporterBase ReadHeader (headerContent) { let header = new OV.PlyHeader (); - OV.ReadLines (headerContent, function (line) { + OV.ReadLines (headerContent, (line) => { let parameters = OV.ParametersFromLine (line, null); if (parameters.length === 0 || parameters[0] === 'comment') { return; @@ -190,13 +190,12 @@ OV.ImporterPly = class extends OV.ImporterBase ReadAsciiContent (header, fileContent) { - let obj = this; let vertex = header.GetElement ('vertex'); let face = header.GetElement ('face'); let foundVertex = 0; let foundFace = 0; - OV.ReadLines (fileContent, function (line) { - if (obj.IsError ()) { + OV.ReadLines (fileContent, (line) => { + if (this.IsError ()) { return; } @@ -207,7 +206,7 @@ OV.ImporterPly = class extends OV.ImporterBase if (foundVertex < vertex.count) { if (parameters.length >= 3) { - obj.mesh.AddVertex (new OV.Coord3D ( + this.mesh.AddVertex (new OV.Coord3D ( parseFloat (parameters[0]), parseFloat (parameters[1]), parseFloat (parameters[2]) @@ -228,7 +227,7 @@ OV.ImporterPly = class extends OV.ImporterBase let v1 = parseInt (parameters[i + 2]); let v2 = parseInt (parameters[i + 3]); let triangle = new OV.Triangle (v0, v1, v2); - obj.mesh.AddTriangle (triangle); + this.mesh.AddTriangle (triangle); } foundFace += 1; } diff --git a/source/import/importerstl.js b/source/import/importerstl.js index 0141a71..5f6e2c3 100644 --- a/source/import/importerstl.js +++ b/source/import/importerstl.js @@ -40,11 +40,10 @@ OV.ImporterStl = class extends OV.ImporterBase if (this.IsBinaryStlFile (fileContent)) { this.ProcessBinary (fileContent); } else { - let obj = this; let textContent = OV.ArrayBufferToUtf8String (fileContent); - OV.ReadLines (textContent, function (line) { - if (!obj.IsError ()) { - obj.ProcessLine (line); + OV.ReadLines (textContent, (line) => { + if (!this.IsError ()) { + this.ProcessLine (line); } }); } diff --git a/source/model/meshbuffer.js b/source/model/meshbuffer.js index a2d0185..7016320 100644 --- a/source/model/meshbuffer.js +++ b/source/model/meshbuffer.js @@ -142,7 +142,7 @@ OV.ConvertMeshToMeshBuffer = function (mesh) for (let i = 0; i < triangleCount; i++) { triangleIndices.push (i); } - triangleIndices.sort (function (a, b) { + triangleIndices.sort ((a, b) => { let aTriangle = mesh.GetTriangle (a); let bTriangle = mesh.GetTriangle (b); return aTriangle.mat - bTriangle.mat; diff --git a/source/model/modelutils.js b/source/model/modelutils.js index 331daeb..1d8f5d1 100644 --- a/source/model/modelutils.js +++ b/source/model/modelutils.js @@ -170,7 +170,7 @@ OV.EnumerateModelVerticesAndTriangles = function (model, callbacks) OV.EnumerateTrianglesWithNormals = function (element, onTriangle) { - element.EnumerateTriangles (function (v0, v1, v2) { + element.EnumerateTriangles ((v0, v1, v2) => { let normal = OV.CalculateTriangleNormal (v0, v1, v2); onTriangle (v0, v1, v2, normal); }); @@ -179,7 +179,7 @@ OV.EnumerateTrianglesWithNormals = function (element, onTriangle) OV.GetBoundingBox = function (element) { let calculator = new OV.BoundingBoxCalculator3D (); - element.EnumerateVertices (function (vertex) { + element.EnumerateVertices ((vertex) => { calculator.AddPoint (vertex); }); return calculator.GetBox (); @@ -201,7 +201,7 @@ OV.GetTopology = function (element) let octree = new OV.Octree (boundingBox); let topology = new OV.Topology (); - element.EnumerateTriangles (function (v0, v1, v2) { + element.EnumerateTriangles ((v0, v1, v2) => { let v0Index = GetVertexIndex (v0, octree, topology); let v1Index = GetVertexIndex (v1, octree, topology); let v2Index = GetVertexIndex (v2, octree, topology); diff --git a/source/model/quantities.js b/source/model/quantities.js index 2126b20..814d288 100644 --- a/source/model/quantities.js +++ b/source/model/quantities.js @@ -22,7 +22,7 @@ OV.CalculateVolume = function (element) return null; } let volume = 0.0; - element.EnumerateTriangles (function (v0, v1, v2) { + element.EnumerateTriangles ((v0, v1, v2) => { volume += OV.GetTetrahedronSignedVolume (v0, v1, v2); }); return volume; @@ -31,7 +31,7 @@ OV.CalculateVolume = function (element) OV.CalculateSurfaceArea = function (element) { let surface = 0.0; - element.EnumerateTriangles (function (v0, v1, v2) { + element.EnumerateTriangles ((v0, v1, v2) => { surface += OV.GetTriangleArea (v0, v1, v2); }); return surface; diff --git a/source/viewer/domviewer.js b/source/viewer/domviewer.js index 04f3ee1..67a7471 100644 --- a/source/viewer/domviewer.js +++ b/source/viewer/domviewer.js @@ -31,7 +31,7 @@ OV.Init3DViewerElements = function (onReady) element.removeChild (progressDiv); canvas.style.display = 'inherit'; viewer.AddMeshes (threeMeshes); - let boundingSphere = viewer.GetBoundingSphere (function (meshUserData) { + let boundingSphere = viewer.GetBoundingSphere ((meshUserData) => { return true; }); viewer.AdjustClippingPlanes (boundingSphere); @@ -90,7 +90,7 @@ OV.Init3DViewerElements = function (onReady) } let viewerElements = []; - window.addEventListener ('load', function () { + window.addEventListener ('load', () => { let elements = document.getElementsByClassName ('online_3d_viewer'); for (let i = 0; i < elements.length; i++) { let element = elements[i]; @@ -102,7 +102,7 @@ OV.Init3DViewerElements = function (onReady) } }); - window.addEventListener ('resize', function () { + window.addEventListener ('resize', () => { for (let i = 0; i < viewerElements.length; i++) { let viewerElement = viewerElements[i]; let width = viewerElement.element.clientWidth; diff --git a/source/viewer/navigation.js b/source/viewer/navigation.js index 00a92c7..2def81b 100644 --- a/source/viewer/navigation.js +++ b/source/viewer/navigation.js @@ -301,7 +301,7 @@ OV.Navigation = class obj.Update (); if (index < count - 1) { - requestAnimationFrame (function () { + requestAnimationFrame (() => { Step (obj, steps, count, index + 1); }); } @@ -324,14 +324,13 @@ OV.Navigation = class } let tweenFunc = OV.ParabolicTweenFunction; - let obj = this; let steps = { eye : OV.TweenCoord3D (this.camera.eye, newCamera.eye, stepCount, tweenFunc), center : OV.TweenCoord3D (this.camera.center, newCamera.center, stepCount, tweenFunc), up : OV.TweenCoord3D (this.camera.up, newCamera.up, stepCount, tweenFunc) }; - requestAnimationFrame (function () { - Step (obj, steps, stepCount, 0); + requestAnimationFrame (() => { + Step (this, steps, stepCount, 0); }); this.Update (); } diff --git a/source/viewer/viewer.js b/source/viewer/viewer.js index 811246f..6a72b02 100644 --- a/source/viewer/viewer.js +++ b/source/viewer/viewer.js @@ -320,7 +320,7 @@ OV.Viewer = class SetMeshesVisibility (isVisible) { - this.geometry.EnumerateModelMeshes (function (mesh) { + this.geometry.EnumerateModelMeshes ((mesh) => { let visible = isVisible (mesh.userData); if (mesh.visible !== visible) { mesh.visible = visible; @@ -340,7 +340,7 @@ OV.Viewer = class return highlightMaterials; } - this.geometry.EnumerateModelMeshes (function (mesh) { + this.geometry.EnumerateModelMeshes ((mesh) => { let highlighted = isHighlighted (mesh.userData); if (highlighted) { if (mesh.userData.threeMaterials === null) { @@ -376,7 +376,7 @@ OV.Viewer = class { let hasMesh = false; let boundingBox = new THREE.Box3 (); - this.geometry.EnumerateModelMeshes (function (mesh) { + this.geometry.EnumerateModelMeshes ((mesh) => { if (needToProcess (mesh.userData)) { boundingBox.union (new THREE.Box3 ().setFromObject (mesh)); hasMesh = true; @@ -403,7 +403,7 @@ OV.Viewer = class EnumerateMeshesUserData (enumerator) { - this.geometry.EnumerateModelMeshes (function (mesh) { + this.geometry.EnumerateModelMeshes ((mesh) => { enumerator (mesh.userData); }); } @@ -416,10 +416,9 @@ OV.Viewer = class let canvasElem = this.renderer.domElement; let camera = OV.GetDefaultCamera (OV.Direction.Z); - let obj = this; this.navigation = new OV.Navigation (canvasElem, camera); - this.navigation.SetUpdateHandler (function () { - obj.Render (); + this.navigation.SetUpdateHandler (() => { + this.Render (); }); this.upVector = new OV.UpVector (); diff --git a/website/o3dv/detailssidebarpanel.js b/website/o3dv/detailssidebarpanel.js index e335f7a..431adf0 100644 --- a/website/o3dv/detailssidebarpanel.js +++ b/website/o3dv/detailssidebarpanel.js @@ -21,14 +21,14 @@ OV.DetailsSidebarPanel = class extends OV.SidebarPanel this.AddProperty (table, new OV.Property (OV.PropertyType.Number, 'Size X', size.x)); this.AddProperty (table, new OV.Property (OV.PropertyType.Number, 'Size Y', size.y)); this.AddProperty (table, new OV.Property (OV.PropertyType.Number, 'Size Z', size.z)); - this.AddCalculatedProperty (table, 'Volume', function () { + this.AddCalculatedProperty (table, 'Volume', () => { const volume = OV.CalculateVolume (element); if (volume === null) { return null; } return new OV.Property (OV.PropertyType.Number, null, volume); }); - this.AddCalculatedProperty (table, 'Surface Area', function () { + this.AddCalculatedProperty (table, 'Surface Area', () => { const volume = OV.CalculateSurfaceArea (element); if (volume === null) { return null; @@ -102,17 +102,16 @@ OV.DetailsSidebarPanel = class extends OV.SidebarPanel let valueColumn = $('