From 751b09ffda9233d8616f37e646624168555229e2 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sat, 7 Aug 2021 21:24:44 +0200 Subject: [PATCH 1/3] Add material comparator function. --- source/import/importer3dm.js | 23 +------- source/model/material.js | 105 ++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 23 deletions(-) diff --git a/source/import/importer3dm.js b/source/import/importer3dm.js index 9dc214f..8ab5be8 100644 --- a/source/import/importer3dm.js +++ b/source/import/importer3dm.js @@ -318,28 +318,9 @@ OV.Importer3dm = class extends OV.ImporterBase } for (let i = 0; i < model.MaterialCount (); i++) { let current = model.GetMaterial (i); - if (current.name !== material.name) { - continue; + if (OV.MaterialIsEqual (current, material)) { + return i; } - if (!OV.ColorIsEqual (current.ambient, material.ambient)) { - continue; - } - if (!OV.ColorIsEqual (current.color, material.color)) { - continue; - } - if (!OV.ColorIsEqual (current.specular, material.specular)) { - continue; - } - if (!OV.IsEqual (current.opacity, material.opacity)) { - continue; - } - if (current.transparent !== material.transparent) { - continue; - } - if (!OV.IsEqual (current.shininess, material.shininess)) { - continue; - } - return i; } return model.AddMaterial (material); } diff --git a/source/model/material.js b/source/model/material.js index 041b1ef..1df1460 100644 --- a/source/model/material.js +++ b/source/model/material.js @@ -190,14 +190,115 @@ OV.HexStringToColor = function (hexString) return new OV.Color (r, g, b); }; +OV.ArrayToColor = function (arr) +{ + return new OV.Color (arr[0], arr[1], arr[2]); +}; + OV.ColorIsEqual = function (a, b) { return a.r === b.r && a.g === b.g && a.b === b.b; }; -OV.ArrayToColor = function (arr) +OV.TextureIsEqual = function (a, b) { - return new OV.Color (arr[0], arr[1], arr[2]); + if (a.name !== b.name) { + return false; + } + if (a.name !== b.name) { + return false; + } + if (a.url !== b.url) { + return false; + } + if (!OV.CoordIsEqual2D (a.offset, b.offset)) { + return false; + } + if (!OV.CoordIsEqual2D (a.scale, b.scale)) { + return false; + } + if (!OV.IsEqual (a.rotation, b.rotation)) { + return false; + } + 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) From 6a2315fbff77532fe7ea2194be00f0506f1b5976 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sat, 7 Aug 2021 22:08:06 +0200 Subject: [PATCH 2/3] Show physical material properties in the sidebar. --- website/o3dv/js/detailssidebarpanel.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/o3dv/js/detailssidebarpanel.js b/website/o3dv/js/detailssidebarpanel.js index 1debaef..b0da02a 100644 --- a/website/o3dv/js/detailssidebarpanel.js +++ b/website/o3dv/js/detailssidebarpanel.js @@ -71,6 +71,10 @@ OV.DetailsSidebarPanel = class extends OV.SidebarPanel this.AddProperty (table, new OV.Property (OV.PropertyType.Text, 'Source', material.isDefault ? 'Default' : 'Model')); this.AddProperty (table, new OV.Property (OV.PropertyType.Text, 'Type', typeString)); this.AddProperty (table, new OV.Property (OV.PropertyType.Color, 'Color', material.color)); + if (material.type === OV.MaterialType.Physical) { + this.AddProperty (table, new OV.Property (OV.PropertyType.Percent, 'Metalness', material.metalness)); + this.AddProperty (table, new OV.Property (OV.PropertyType.Percent, 'Roughness', material.roughness)); + } 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); From ad7a1f9e89c49f74ee20513e96de7cef086dcece Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sat, 7 Aug 2021 22:08:16 +0200 Subject: [PATCH 3/3] Support Rhino PBR materials #107 --- source/import/importer3dm.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/import/importer3dm.js b/source/import/importer3dm.js index 8ab5be8..3d200e4 100644 --- a/source/import/importer3dm.js +++ b/source/import/importer3dm.js @@ -298,14 +298,23 @@ OV.Importer3dm = class extends OV.ImporterBase return rhinoColor.r === 255 && rhinoColor.g === 255 && rhinoColor.b === 255; } - let material = new OV.Material (OV.MaterialType.Phong); + let material = null; if (rhinoMaterial === null) { + material = new OV.Material (OV.MaterialType.Phong); material.color.Set (255, 255, 255); } else { + let physicallyBased = rhinoMaterial.physicallyBased (); + if (physicallyBased.supported) { + material = new OV.Material (OV.MaterialType.Physical); + material.metalness = physicallyBased.metallic ? 1.0 : 0.0; + material.roughness = physicallyBased.roughness; + } else { + material = new OV.Material (OV.MaterialType.Phong); + SetColor (material.ambient, rhinoMaterial.ambientColor); + SetColor (material.specular, rhinoMaterial.specularColor); + } material.name = rhinoMaterial.name; - SetColor (material.ambient, rhinoMaterial.ambientColor); SetColor (material.color, rhinoMaterial.diffuseColor); - SetColor (material.specular, rhinoMaterial.specularColor); material.opacity = 1.0 - rhinoMaterial.transparency; OV.UpdateMaterialTransparency (material); // material.shininess = rhinoMaterial.shine / 255.0;