diff --git a/source/export/exporter3dm.js b/source/export/exporter3dm.js index a9c7f22..16b57a6 100644 --- a/source/export/exporter3dm.js +++ b/source/export/exporter3dm.js @@ -71,9 +71,11 @@ OV.Exporter3dm = class extends OV.ExporterBase let material = model.GetMaterial (primitive.material); let rhinoMaterial = new this.rhino.Material (); rhinoMaterial.name = this.GetExportedMaterialName (material.name); - rhinoMaterial.ambientColor = ColorToRhinoColor (material.ambient); + if (material.type === OV.MaterialType.Phong) { + rhinoMaterial.ambientColor = ColorToRhinoColor (material.ambient); + rhinoMaterial.specularColor = ColorToRhinoColor (material.specular); + } rhinoMaterial.diffuseColor = ColorToRhinoColor (material.color); - rhinoMaterial.specularColor = ColorToRhinoColor (material.specular); rhinoMaterial.transparency = 1.0 - material.opacity; let rhinoMaterialIndex = rhinoDoc.materials ().count (); diff --git a/source/export/exportergltf.js b/source/export/exportergltf.js index d398d09..c6a0ba5 100644 --- a/source/export/exportergltf.js +++ b/source/export/exportergltf.js @@ -426,12 +426,14 @@ OV.ExporterGltf = class extends OV.ExporterBase } jsonMaterial.pbrMetallicRoughness.baseColorTexture = baseColorTexture; } - let metallicTexture = GetTextureParams (mainJson, material.metalnessMap, addTexture); - if (metallicTexture !== null) { - jsonMaterial.pbrMetallicRoughness.metallicRoughnessTexture = metallicTexture; - } else { - jsonMaterial.pbrMetallicRoughness.metallicFactor = material.metalness; - jsonMaterial.pbrMetallicRoughness.roughnessFactor = material.roughness; + if (material.type === OV.MaterialType.Physical) { + let metallicTexture = GetTextureParams (mainJson, material.metalnessMap, addTexture); + if (metallicTexture !== null) { + jsonMaterial.pbrMetallicRoughness.metallicRoughnessTexture = metallicTexture; + } else { + jsonMaterial.pbrMetallicRoughness.metallicFactor = material.metalness; + jsonMaterial.pbrMetallicRoughness.roughnessFactor = material.roughness; + } } let normalTexture = GetTextureParams (mainJson, material.normalMap, addTexture); if (normalTexture !== null) { diff --git a/source/export/exporterobj.js b/source/export/exporterobj.js index 92f2514..95a74d2 100644 --- a/source/export/exporterobj.js +++ b/source/export/exporterobj.js @@ -41,13 +41,17 @@ OV.ExporterObj = class extends OV.ExporterBase for (let materialIndex = 0; materialIndex < model.MaterialCount (); materialIndex++) { let material = model.GetMaterial (materialIndex); mtlWriter.WriteArrayLine (['newmtl', this.GetExportedMaterialName (material.name)]); - mtlWriter.WriteArrayLine (['Ka', material.ambient.r / 255.0, material.ambient.g / 255.0, material.ambient.b / 255.0]); mtlWriter.WriteArrayLine (['Kd', material.color.r / 255.0, material.color.g / 255.0, material.color.b / 255.0]); - mtlWriter.WriteArrayLine (['Ks', material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0]); - mtlWriter.WriteArrayLine (['Ns', material.shininess * 1000.0]); mtlWriter.WriteArrayLine (['d', material.opacity]); + if (material.type === OV.MaterialType.Phong) { + mtlWriter.WriteArrayLine (['Ka', material.ambient.r / 255.0, material.ambient.g / 255.0, material.ambient.b / 255.0]); + mtlWriter.WriteArrayLine (['Ks', material.specular.r / 255.0, material.specular.g / 255.0, material.specular.b / 255.0]); + mtlWriter.WriteArrayLine (['Ns', material.shininess * 1000.0]); + } WriteTexture (mtlWriter, 'map_Kd', material.diffuseMap, files); - WriteTexture (mtlWriter, 'map_Ks', material.specularMap, files); + if (material.type === OV.MaterialType.Phong) { + WriteTexture (mtlWriter, 'map_Ks', material.specularMap, files); + } WriteTexture (mtlWriter, 'bump', material.bumpMap, files); } mtlFile.SetTextContent (mtlWriter.GetText ()); diff --git a/source/import/importer.js b/source/import/importer.js index c452c8d..868487a 100644 --- a/source/import/importer.js +++ b/source/import/importer.js @@ -203,7 +203,7 @@ OV.Importer = class importer.Import (mainFile.file.name, mainFile.file.extension, mainFile.file.content, { getDefaultMaterial : () => { - let material = new OV.Material (OV.MaterialType.Phong); + let material = new OV.PhongMaterial (); material.color = settings.defaultColor; return material; }, @@ -311,7 +311,7 @@ OV.Importer = class } for (let i = 0; i < this.model.MaterialCount (); i++) { let material = this.model.GetMaterial (i); - OV.EnumerateMaterialTextureMaps (material, (texture) => { + material.EnumerateTextureMaps ((texture) => { if (texture.url !== null) { OV.RevokeObjectUrl (texture.url); } diff --git a/source/import/importer3dm.js b/source/import/importer3dm.js index a2a1d6c..029e753 100644 --- a/source/import/importer3dm.js +++ b/source/import/importer3dm.js @@ -248,16 +248,16 @@ OV.Importer3dm = class extends OV.ImporterBase let material = null; if (rhinoMaterial === null) { - material = new OV.Material (OV.MaterialType.Phong); + material = new OV.PhongMaterial (); material.color.Set (255, 255, 255); } else { let physicallyBased = rhinoMaterial.physicallyBased (); if (physicallyBased.supported) { - material = new OV.Material (OV.MaterialType.Physical); + material = new OV.PhysicalMaterial (); material.metalness = physicallyBased.metallic ? 1.0 : 0.0; material.roughness = physicallyBased.roughness; } else { - material = new OV.Material (OV.MaterialType.Phong); + material = new OV.PhongMaterial (); SetColor (material.ambient, rhinoMaterial.ambientColor); SetColor (material.specular, rhinoMaterial.specularColor); } @@ -275,7 +275,7 @@ OV.Importer3dm = class extends OV.ImporterBase } for (let i = 0; i < model.MaterialCount (); i++) { let current = model.GetMaterial (i); - if (OV.MaterialIsEqual (current, material)) { + if (current.IsEqual (material)) { return i; } } diff --git a/source/import/importer3ds.js b/source/import/importer3ds.js index 5c2e173..56e417a 100644 --- a/source/import/importer3ds.js +++ b/source/import/importer3ds.js @@ -166,7 +166,7 @@ OV.Importer3ds = class extends OV.ImporterBase ReadMaterialChunk (reader, length) { - let material = new OV.Material (OV.MaterialType.Phong); + let material = new OV.PhongMaterial (); let endByte = this.GetChunkEnd (reader, length); let shininess = null; let shininessStrength = null; diff --git a/source/import/importergltf.js b/source/import/importergltf.js index 00a8589..97335c3 100644 --- a/source/import/importergltf.js +++ b/source/import/importergltf.js @@ -263,41 +263,46 @@ OV.GltfExtensions = class } if (gltfMaterial.extensions === undefined) { - return; + return null; } + let khrSpecularGlossiness = gltfMaterial.extensions.KHR_materials_pbrSpecularGlossiness; - if (khrSpecularGlossiness !== undefined) { - material.type = OV.MaterialType.Phong; - let diffuseColor = khrSpecularGlossiness.diffuseFactor; - if (diffuseColor !== undefined) { - material.color = new OV.Color ( - GetMaterialComponent (diffuseColor[0]), - GetMaterialComponent (diffuseColor[1]), - GetMaterialComponent (diffuseColor[2]) - ); - material.opacity = diffuseColor[3]; - } - let diffuseTexture = khrSpecularGlossiness.diffuseTexture; - if (diffuseTexture !== undefined) { - material.diffuseMap = imporTextureFn (diffuseTexture); - } - let specularColor = khrSpecularGlossiness.specularFactor; - if (specularColor !== undefined) { - material.specular = new OV.Color ( - GetMaterialComponent (specularColor[0]), - GetMaterialComponent (specularColor[1]), - GetMaterialComponent (specularColor[2]) - ); - } - let specularTexture = khrSpecularGlossiness.specularGlossinessTexture; - if (specularTexture !== undefined) { - material.specularMap = imporTextureFn (specularTexture); - } - let glossiness = khrSpecularGlossiness.glossinessFactor; - if (glossiness !== undefined) { - material.shininess = glossiness; - } + if (khrSpecularGlossiness === undefined) { + return null; } + + let phongMaterial = new OV.PhongMaterial (); + let diffuseColor = khrSpecularGlossiness.diffuseFactor; + if (diffuseColor !== undefined) { + phongMaterial.color = new OV.Color ( + GetMaterialComponent (diffuseColor[0]), + GetMaterialComponent (diffuseColor[1]), + GetMaterialComponent (diffuseColor[2]) + ); + phongMaterial.opacity = diffuseColor[3]; + } + let diffuseTexture = khrSpecularGlossiness.diffuseTexture; + if (diffuseTexture !== undefined) { + phongMaterial.diffuseMap = imporTextureFn (diffuseTexture); + } + let specularColor = khrSpecularGlossiness.specularFactor; + if (specularColor !== undefined) { + phongMaterial.specular = new OV.Color ( + GetMaterialComponent (specularColor[0]), + GetMaterialComponent (specularColor[1]), + GetMaterialComponent (specularColor[2]) + ); + } + let specularTexture = khrSpecularGlossiness.specularGlossinessTexture; + if (specularTexture !== undefined) { + phongMaterial.specularMap = imporTextureFn (specularTexture); + } + let glossiness = khrSpecularGlossiness.glossinessFactor; + if (glossiness !== undefined) { + phongMaterial.shininess = glossiness; + } + + return phongMaterial; } ProcessTexture (gltfTexture, texture) @@ -629,7 +634,7 @@ OV.ImporterGltf = class extends OV.ImporterBase return parseInt (Math.round (OV.LinearToSRGB (component) * 255.0), 10); } - let material = new OV.Material (OV.MaterialType.Physical); + let material = new OV.PhysicalMaterial (); if (gltfMaterial.name !== undefined) { material.name = gltfMaterial.name; } @@ -685,9 +690,12 @@ OV.ImporterGltf = class extends OV.ImporterBase } } - this.gltfExtensions.ProcessMaterial (gltfMaterial, material, (textureRef) => { + let newMaterial = this.gltfExtensions.ProcessMaterial (gltfMaterial, material, (textureRef) => { return this.ImportTexture (gltf, textureRef); }); + if (newMaterial !== null) { + material = newMaterial; + } this.model.AddMaterial (material); } diff --git a/source/import/importerifc.js b/source/import/importerifc.js index 0b8bdff..cd8b9b7 100644 --- a/source/import/importerifc.js +++ b/source/import/importerifc.js @@ -207,7 +207,7 @@ OV.ImporterIfc = class extends OV.ImporterBase let materialIndex = this.materialNameToIndex[materialName]; if (materialIndex === undefined) { - let material = new OV.Material (OV.MaterialType.Phong); + let material = new OV.PhongMaterial (); material.name = materialName; material.color = color; material.opacity = ifcColor.w; diff --git a/source/import/importero3dv.js b/source/import/importero3dv.js index 3cceff5..8d8d4c5 100644 --- a/source/import/importero3dv.js +++ b/source/import/importero3dv.js @@ -56,7 +56,7 @@ OV.ImporterO3dv = class extends OV.ImporterBase ImportMaterial (materialContent) { - let material = new OV.Material (OV.MaterialType.Physical); + let material = new OV.PhysicalMaterial (); material.color.Set (255, 255, 255); if (materialContent.name !== undefined) { material.name = materialContent.name; diff --git a/source/import/importerobj.js b/source/import/importerobj.js index 86e3dec..f18fa4d 100644 --- a/source/import/importerobj.js +++ b/source/import/importerobj.js @@ -220,7 +220,7 @@ OV.ImporterObj = class extends OV.ImporterBase return true; } - let material = new OV.Material (OV.MaterialType.Phong); + let material = new OV.PhongMaterial (); let materialName = OV.NameFromLine (line, keyword.length, '#'); let materialIndex = this.model.AddMaterial (material); material.name = materialName; diff --git a/source/import/importerply.js b/source/import/importerply.js index 5d6bb42..df802ec 100644 --- a/source/import/importerply.js +++ b/source/import/importerply.js @@ -139,7 +139,7 @@ OV.PlyMaterialHandler = class let materialIndex = this.colorToMaterial[materialName]; if (materialIndex === undefined) { - let material = new OV.Material (OV.MaterialType.Phong); + let material = new OV.PhongMaterial (); material.name = materialName; material.color = new OV.Color (color[0], color[1], color[2]); material.opacity = color[3] / 255.0; diff --git a/source/import/importerthree.js b/source/import/importerthree.js index af6a9d0..da0b83a 100644 --- a/source/import/importerthree.js +++ b/source/import/importerthree.js @@ -258,7 +258,7 @@ OV.ImporterThreeBase = class extends OV.ImporterBase } } - let material = new OV.Material (OV.MaterialType.Phong); + let material = new OV.PhongMaterial (); material.name = threeMaterial.name; SetColor (material.color, threeMaterial.color); material.opacity = threeMaterial.opacity; diff --git a/source/model/material.js b/source/model/material.js index c214e8c..7a3a50c 100644 --- a/source/model/material.js +++ b/source/model/material.js @@ -50,6 +50,39 @@ OV.TextureMap = class } return false; } + + IsEqual (rhs) + { + if (this.name !== rhs.name) { + return false; + } + if (this.name !== rhs.name) { + return false; + } + if (this.url !== rhs.url) { + return false; + } + if (!OV.CoordIsEqual2D (this.offset, rhs.offset)) { + return false; + } + if (!OV.CoordIsEqual2D (this.scale, rhs.scale)) { + return false; + } + if (!OV.IsEqual (this.rotation, rhs.rotation)) { + return false; + } + return true; + } +}; + +OV.TextureMapIsEqual = function (aTex, bTex) +{ + if (aTex === null && bTex === null) { + return true; + } else if (aTex === null || bTex === null) { + return false; + } + return aTex.IsEqual (bTex); }; OV.MaterialType = @@ -58,37 +91,182 @@ OV.MaterialType = Physical : 2 }; -OV.Material = class +OV.MaterialBase = class { constructor (type) { this.type = type; + this.isDefault = false; + this.name = ''; this.color = new OV.Color (0, 0, 0); + } + + IsEqual (rhs) + { + if (this.type !== rhs.type) { + return false; + } + if (this.isDefault !== rhs.isDefault) { + return false; + } + if (this.name !== rhs.name) { + return false; + } + if (!OV.ColorIsEqual (this.color, rhs.color)) { + return false; + } + return true; + } +}; + +OV.FaceMaterial = class extends OV.MaterialBase +{ + constructor (type) + { + super (type); - this.ambient = new OV.Color (0, 0, 0); - this.specular = new OV.Color (0, 0, 0); this.emissive = new OV.Color (0, 0, 0); - this.metalness = 0.0; - this.roughness = 1.0; - - this.shininess = 0.0; // 0.0 .. 1.0 this.opacity = 1.0; // 0.0 .. 1.0 + this.transparent = false; this.diffuseMap = null; - this.specularMap = null; this.bumpMap = null; this.normalMap = null; this.emissiveMap = null; - this.metalnessMap = null; this.alphaTest = 0.0; // 0.0 .. 1.0 - this.transparent = false; this.multiplyDiffuseMap = false; - this.multiplyMetallicMap = false; + } - this.isDefault = false; + IsEqual (rhs) + { + if (!super.IsEqual (rhs)) { + return false; + } + if (!OV.ColorIsEqual (this.emissive, rhs.emissive)) { + return false; + } + if (!OV.IsEqual (this.opacity, rhs.opacity)) { + return false; + } + if (this.transparent !== rhs.transparent) { + return false; + } + if (!OV.TextureMapIsEqual (this.diffuseMap, rhs.diffuseMap)) { + return false; + } + if (!OV.TextureMapIsEqual (this.bumpMap, rhs.bumpMap)) { + return false; + } + if (!OV.TextureMapIsEqual (this.normalMap, rhs.normalMap)) { + return false; + } + if (!OV.TextureMapIsEqual (this.emissiveMap, rhs.emissiveMap)) { + return false; + } + if (!OV.IsEqual (this.alphaTest, rhs.alphaTest)) { + return false; + } + if (this.multiplyDiffuseMap !== rhs.multiplyDiffuseMap) { + return false; + } + return true; + } + + EnumerateTextureMaps (enumerator) + { + if (this.diffuseMap !== null) { + enumerator (this.diffuseMap); + } + if (this.bumpMap !== null) { + enumerator (this.bumpMap); + } + if (this.normalMap !== null) { + enumerator (this.normalMap); + } + if (this.emissiveMap !== null) { + enumerator (this.emissiveMap); + } + } +}; + +OV.PhongMaterial = class extends OV.FaceMaterial +{ + constructor () + { + super (OV.MaterialType.Phong); + + this.ambient = new OV.Color (0, 0, 0); + this.specular = new OV.Color (0, 0, 0); + this.shininess = 0.0; // 0.0 .. 1.0 + this.specularMap = null; + } + + IsEqual (rhs) + { + if (!super.IsEqual (rhs)) { + return false; + } + if (!OV.ColorIsEqual (this.ambient, rhs.ambient)) { + return false; + } + if (!OV.ColorIsEqual (this.specular, rhs.specular)) { + return false; + } + if (!OV.IsEqual (this.shininess, rhs.shininess)) { + return false; + } + if (!OV.TextureMapIsEqual (this.specularMap, rhs.specularMap)) { + return false; + } + return true; + } + + EnumerateTextureMaps (enumerator) + { + super.EnumerateTextureMaps (enumerator); + if (this.specularMap !== null) { + enumerator (this.specularMap); + } + } +}; + +OV.PhysicalMaterial = class extends OV.FaceMaterial +{ + constructor () + { + super (OV.MaterialType.Physical); + + this.metalness = 0.0; // 0.0 .. 1.0 + this.roughness = 1.0; // 0.0 .. 1.0 + this.metalnessMap = null; + } + + IsEqual (rhs) + { + if (!super.IsEqual (rhs)) { + return false; + } + if (!OV.IsEqual (this.metalness, rhs.metalness)) { + return false; + } + if (!OV.IsEqual (this.roughness, rhs.roughness)) { + return false; + } + if (!OV.TextureMapIsEqual (this.metalnessMap, rhs.metalnessMap)) { + return false; + } + return true; + } + + EnumerateTextureMaps (enumerator) + { + super.EnumerateTextureMaps (enumerator); + if (this.metalnessMap !== null) { + enumerator (this.metalnessMap); + } } }; @@ -171,103 +349,3 @@ OV.TextureIsEqual = function (a, b) } return true; }; - -OV.MaterialIsEqual = function (a, b) -{ - function TextureIsEqual (aTex, bTex) - { - if (aTex === null && bTex === null) { - return true; - } else if (aTex === null || bTex === null) { - return false; - } - return OV.TextureIsEqual (aTex, bTex); - } - - if (a.type !== b.type) { - return false; - } - if (a.name !== b.name) { - return false; - } - if (!OV.ColorIsEqual (a.color, b.color)) { - return false; - } - if (!OV.ColorIsEqual (a.ambient, b.ambient)) { - return false; - } - if (!OV.ColorIsEqual (a.specular, b.specular)) { - return false; - } - if (!OV.ColorIsEqual (a.emissive, b.emissive)) { - return false; - } - if (!OV.IsEqual (a.metalness, b.metalness)) { - return false; - } - if (!OV.IsEqual (a.roughness, b.roughness)) { - return false; - } - if (!OV.IsEqual (a.shininess, b.shininess)) { - return false; - } - if (!OV.IsEqual (a.opacity, b.opacity)) { - return false; - } - if (!TextureIsEqual (a.diffuseMap, b.diffuseMap)) { - return false; - } - if (!TextureIsEqual (a.specularMap, b.specularMap)) { - return false; - } - if (!TextureIsEqual (a.bumpMap, b.bumpMap)) { - return false; - } - if (!TextureIsEqual (a.normalMap, b.normalMap)) { - return false; - } - if (!TextureIsEqual (a.emissiveMap, b.emissiveMap)) { - return false; - } - if (!TextureIsEqual (a.metalnessMap, b.metalnessMap)) { - return false; - } - if (!OV.IsEqual (a.alphaTest, b.alphaTest)) { - return false; - } - if (a.transparent !== b.transparent) { - return false; - } - if (a.multiplyDiffuseMap !== b.multiplyDiffuseMap) { - return false; - } - if (a.multiplyMetallicMap !== b.multiplyMetallicMap) { - return false; - } - if (a.isDefault !== b.isDefault) { - return false; - } - return true; -}; - -OV.EnumerateMaterialTextureMaps = function (material, enumerator) -{ - if (material.diffuseMap !== null) { - enumerator (material.diffuseMap); - } - if (material.specularMap !== null) { - enumerator (material.specularMap); - } - if (material.bumpMap !== null) { - enumerator (material.bumpMap); - } - if (material.normalMap !== null) { - enumerator (material.normalMap); - } - if (material.emissiveMap !== null) { - enumerator (material.emissiveMap); - } - if (material.metalnessMap !== null) { - enumerator (material.metalnessMap); - } -}; diff --git a/test/tests/exporter_test.js b/test/tests/exporter_test.js index c57220e..692bedb 100644 --- a/test/tests/exporter_test.js +++ b/test/tests/exporter_test.js @@ -4,7 +4,7 @@ function CreateTestModel () { let model = new OV.Model (); - let material1 = new OV.Material (OV.MaterialType.Phong); + let material1 = new OV.PhongMaterial (); material1.name = 'TestMaterial1'; material1.ambient = new OV.Color (0, 0, 0); material1.color = new OV.Color (255, 0, 0); @@ -23,7 +23,7 @@ function CreateTestModel () material1.bumpMap.buffer = new ArrayBuffer (3); model.AddMaterial (material1); - let material2 = new OV.Material (OV.MaterialType.Phong); + let material2 = new OV.PhongMaterial (); material2.name = 'TestMaterial2'; material2.ambient = new OV.Color (0, 0, 0); material2.color = new OV.Color (0, 255, 0); @@ -94,20 +94,20 @@ describe ('Exporter', function () { [ '# exported by https://3dviewer.net', 'newmtl TestMaterial1', - 'Ka 0 0 0', 'Kd 1 0 0', + 'd 1', + 'Ka 0 0 0', 'Ks 0.2 0.2 0.2', 'Ns 0', - 'd 1', 'map_Kd texture1.png', 'map_Ks texture2.png', 'bump texture3.png', 'newmtl TestMaterial2', - 'Ka 0 0 0', 'Kd 0 1 0', + 'd 1', + 'Ka 0 0 0', 'Ks 0.2 0.2 0.2', 'Ns 0', - 'd 1', '' ].join ('\n')); let objFile = result[1]; @@ -214,7 +214,7 @@ describe ('Exporter', function () { let importer = new OV.ImporterStl (); importer.Import (stlFile.GetName (), 'stl', contentBuffer, { getDefaultMaterial () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }, onSuccess () { let importedModel = importer.GetModel (); @@ -308,7 +308,7 @@ describe ('Exporter', function () { let importer = new OV.ImporterPly (); importer.Import (plyFile.GetName (), 'ply', contentBuffer, { getDefaultMaterial () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }, onSuccess () { let importedModel = importer.GetModel (); @@ -338,7 +338,7 @@ describe ('Exporter', function () { let importer = new OV.ImporterGltf (); importer.Import (gltfFile.GetName (), 'gltf', contentBuffer, { getDefaultMaterial () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }, getFileBuffer (filePath) { if (filePath == 'model.bin') { @@ -376,7 +376,7 @@ describe ('Exporter', function () { let importer = new OV.ImporterGltf (); importer.Import (glbFile.GetName (), 'glb', contentBuffer, { getDefaultMaterial () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }, getFileBuffer (filePath) { return null; diff --git a/test/tests/meshbuffer_test.js b/test/tests/meshbuffer_test.js index 495ebec..e23640e 100644 --- a/test/tests/meshbuffer_test.js +++ b/test/tests/meshbuffer_test.js @@ -46,7 +46,7 @@ describe ('Mesh Buffer', function () { assert.strictEqual (buffer.primitives[0].indices.length, 6); assert.strictEqual (buffer.primitives[0].vertices.length, 6 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 6 * 3); - assert.strictEqual (buffer.primitives[0].uvs.length, 0); + assert.strictEqual (buffer.primitives[0].uvs.length, 0); }); it ('Mesh To Buffer Different UVs', function () { @@ -66,7 +66,7 @@ describe ('Mesh Buffer', function () { assert.strictEqual (buffer.primitives[0].indices.length, 6); assert.strictEqual (buffer.primitives[0].vertices.length, 6 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 6 * 3); - assert.strictEqual (buffer.primitives[0].uvs.length, 6 * 2); + assert.strictEqual (buffer.primitives[0].uvs.length, 6 * 2); }); it ('Mesh To Buffer Same Normals and UVs', function () { @@ -85,7 +85,7 @@ describe ('Mesh Buffer', function () { assert.strictEqual (buffer.primitives[0].indices.length, 6); assert.strictEqual (buffer.primitives[0].vertices.length, 4 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 4 * 3); - assert.strictEqual (buffer.primitives[0].uvs.length, 4 * 2); + assert.strictEqual (buffer.primitives[0].uvs.length, 4 * 2); }); it ('Mesh To Buffer Cube', function () { @@ -123,7 +123,7 @@ describe ('Mesh Buffer', function () { model.AddMesh (mesh); OV.FinalizeModel (model, function () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }); assert (OV.CheckModel (model)); @@ -132,7 +132,7 @@ describe ('Mesh Buffer', function () { assert.strictEqual (buffer.primitives[0].indices.length, 36); assert.strictEqual (buffer.primitives[0].vertices.length, 24 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 24 * 3); - assert.strictEqual (buffer.primitives[0].uvs.length, 0); + assert.strictEqual (buffer.primitives[0].uvs.length, 0); }); it ('Mesh To Buffer Cube Auto Normals', function () { @@ -163,7 +163,7 @@ describe ('Mesh Buffer', function () { model.AddMesh (mesh); OV.FinalizeModel (model, function () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }); assert (OV.CheckModel (model)); @@ -205,7 +205,7 @@ describe ('Mesh Buffer', function () { model.AddMesh (mesh); OV.FinalizeModel (model, function () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }); assert (OV.CheckModel (model)); @@ -217,12 +217,12 @@ describe ('Mesh Buffer', function () { assert.strictEqual (buffer.primitives[0].uvs.length, 0); assert.strictEqual (buffer.primitives[0].GetByteLength (2, 4), 36 * 2 + 2 * 8 * 3 * 4); assert.strictEqual (buffer.GetByteLength (2, 4), 36 * 2 + 2 * 8 * 3 * 4); - }); + }); it ('Mesh To Buffer Cube Materials', function () { var model = new OV.Model (); - model.AddMaterial (new OV.Material (OV.MaterialType.Phong)); - model.AddMaterial (new OV.Material (OV.MaterialType.Phong)); + model.AddMaterial (new OV.PhongMaterial ()); + model.AddMaterial (new OV.PhongMaterial ()); var mesh = new OV.Mesh (); mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0)); @@ -249,7 +249,7 @@ describe ('Mesh Buffer', function () { model.AddMesh (mesh); OV.FinalizeModel (model, function () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }); assert (OV.CheckModel (model)); @@ -266,7 +266,7 @@ describe ('Mesh Buffer', function () { assert.strictEqual (buffer.primitives[1].uvs.length, 0); assert.strictEqual (buffer.primitives[1].GetByteLength (2, 4), 18 * 2 + 2 * 12 * 3 * 4); assert.strictEqual (buffer.GetByteLength (2, 4), 36 * 2 + 2 * 24 * 3 * 4); - }); + }); it ('Mesh To Buffer Cube One UV', function () { var model = new OV.Model (); @@ -299,7 +299,7 @@ describe ('Mesh Buffer', function () { model.AddMesh (mesh); OV.FinalizeModel (model, function () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }); assert (OV.CheckModel (model)); @@ -342,7 +342,7 @@ describe ('Mesh Buffer', function () { model.AddMesh (mesh); OV.FinalizeModel (model, function () { - return new OV.Material (OV.MaterialType.Phong); + return new OV.PhongMaterial (); }); assert (OV.CheckModel (model)); @@ -352,5 +352,5 @@ describe ('Mesh Buffer', function () { assert.strictEqual (buffer.primitives[0].vertices.length, 30 * 3); assert.strictEqual (buffer.primitives[0].normals.length, 30 * 3); assert.strictEqual (buffer.primitives[0].uvs.length, 30 * 2); - }); + }); }); diff --git a/test/tests/model_test.js b/test/tests/model_test.js index b1f200c..eea9892 100644 --- a/test/tests/model_test.js +++ b/test/tests/model_test.js @@ -10,7 +10,7 @@ describe ('Model', function () { it ('Add Material', function () { var model = new OV.Model (); - var material = new OV.Material (OV.MaterialType.Phong); + var material = new OV.PhongMaterial (); material.name = 'example'; var index = model.AddMaterial (material); assert.strictEqual (model.MaterialCount (), 1); @@ -91,7 +91,7 @@ describe ('Model Finalization', function () { var model = new OV.Model (); var meshIndex = model.AddMesh (mesh); assert.strictEqual (model.MaterialCount (), 0); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); assert.strictEqual (model.MaterialCount (), 1); var theMesh = model.GetMesh (meshIndex); assert.strictEqual (theMesh.NormalCount (), 1); @@ -120,7 +120,7 @@ describe ('Model Finalization', function () { var model = new OV.Model () var meshIndex = model.AddMesh (mesh); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); var theMesh = model.GetMesh (meshIndex); assert.strictEqual (theMesh.NormalCount (), 6); @@ -153,7 +153,7 @@ describe ('Model Finalization', function () { var model = new OV.Model () var meshIndex = model.AddMesh (mesh); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); var theMesh = model.GetMesh (meshIndex); assert.strictEqual (theMesh.NormalCount (), 9); @@ -192,7 +192,7 @@ describe ('Model Finalization', function () { node3.AddMeshIndex (meshIndex); node3.AddMeshIndex (emptyMeshIndex); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); assert.strictEqual (model.MeshCount (), 1); let meshInstances = []; @@ -210,7 +210,7 @@ describe ('Model Finalization', function () { it ('Remove Empty Nodes Recursively', function () { let model = testUtils.GetHierarchicalModelNoFinalization (); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); assert.strictEqual (model.MeshCount (), 0); assert.strictEqual (model.MeshInstanceCount (), 0); assert (model.GetRootNode ().IsEmpty ()); @@ -395,7 +395,7 @@ describe ('Node Hierarchy', function () { it ('Instance counters', function () { let model = testUtils.GetTranslatedRotatedCubesModel (); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); assert.strictEqual (model.MeshCount (), 1); assert.strictEqual (model.MeshInstanceCount (), 3); assert.strictEqual (model.VertexCount (), 8 * 3); diff --git a/test/tests/modelutils_test.js b/test/tests/modelutils_test.js index caea250..ae5c417 100644 --- a/test/tests/modelutils_test.js +++ b/test/tests/modelutils_test.js @@ -37,7 +37,7 @@ describe ('Model Utils', function () { mesh2.AddTriangle (new OV.Triangle (0, 1, 2)); model.AddMeshToRootNode (mesh2); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong); }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial (); }); let mesh1Bounds = OV.GetBoundingBox (model.GetMesh (0)); assert (OV.CoordIsEqual3D (mesh1Bounds.min, new OV.Coord3D (0.0, 0.0, 0.0))); diff --git a/test/utils/testfiles.js b/test/utils/testfiles.js index 6daa6d0..8896511 100644 --- a/test/utils/testfiles.js +++ b/test/utils/testfiles.js @@ -54,7 +54,7 @@ module.exports = }); importer.Import (fileName, extension, content, { getDefaultMaterial : function () { - var material = new OV.Material (OV.MaterialType.Phong); + var material = new OV.PhongMaterial (); return material; }, getFileBuffer : function (filePath) { diff --git a/test/utils/testutils.js b/test/utils/testutils.js index a513633..3c344da 100644 --- a/test/utils/testutils.js +++ b/test/utils/testutils.js @@ -170,7 +170,7 @@ module.exports = OV.TransformMesh (cube2, new OV.Transformation (matrix)); model.AddMeshToRootNode (cube2); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); return model; }, @@ -186,7 +186,7 @@ module.exports = OV.TransformMesh (cube2, new OV.Transformation (matrix)) model.AddMeshToRootNode (cube2); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); return model; }, @@ -202,7 +202,7 @@ module.exports = OV.TransformMesh (cube2, new OV.Transformation (matrix)); model.AddMeshToRootNode (cube2); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); return model; }, @@ -251,7 +251,7 @@ module.exports = { var model = new OV.Model (); model.AddMeshToRootNode (mesh); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); return model; }, @@ -375,7 +375,7 @@ module.exports = root.AddChildNode (rotatedNode); rotatedNode.AddChildNode (translatedRotatedNode); - OV.FinalizeModel (model, function () { return new OV.Material (OV.MaterialType.Phong) }); + OV.FinalizeModel (model, function () { return new OV.PhongMaterial () }); return model; } } diff --git a/website/o3dv/js/sidebarpanels.js b/website/o3dv/js/sidebarpanels.js index 73c52f0..c4ae1ee 100644 --- a/website/o3dv/js/sidebarpanels.js +++ b/website/o3dv/js/sidebarpanels.js @@ -116,11 +116,14 @@ OV.DetailsSidebarPanel = class extends OV.SidebarPanel } this.AddProperty (table, new OV.Property (OV.PropertyType.Percent, 'Opacity', material.opacity)); AddTextureMap (this, table, 'Diffuse Map', material.diffuseMap); - AddTextureMap (this, table, 'Specular Map', material.specularMap); AddTextureMap (this, table, 'Bump Map', material.bumpMap); AddTextureMap (this, table, 'Normal Map', material.normalMap); AddTextureMap (this, table, 'Emissive Map', material.emissiveMap); - AddTextureMap (this, table, 'Metallic Map', material.metalnessMap); + if (material.type === OV.MaterialType.Phong) { + AddTextureMap (this, table, 'Specular Map', material.specularMap); + } else if (material.type === OV.MaterialType.Physical) { + AddTextureMap (this, table, 'Metallic Map', material.metalnessMap); + } this.Resize (); }