diff --git a/Common_glTF_Exporter/Core/GlTFExportContext.cs b/Common_glTF_Exporter/Core/GlTFExportContext.cs index 3cde758..bbe45e0 100644 --- a/Common_glTF_Exporter/Core/GlTFExportContext.cs +++ b/Common_glTF_Exporter/Core/GlTFExportContext.cs @@ -280,23 +280,14 @@ public void OnElementEnd(ElementId elementId) public void OnMaterial(MaterialNode node) { if (preferences.materials == MaterialsEnum.materials || preferences.materials == MaterialsEnum.textures) - { + { if (node.MaterialId == ElementId.InvalidElementId) { currentMaterial = GLTFExportUtils.GetGLTFMaterial(materials, node.Transparency, false); } else { - string materialId = node.MaterialId.ToString(); - if (materials.Contains(materialId)) - { - currentMaterial = materials.GetElement(materialId); - } - else - { - currentMaterial = RevitMaterials.Export(node, preferences, currentDocument); - } - materials.AddOrUpdateCurrentMaterial(materialId, currentMaterial, false); + currentMaterial = RevitMaterials.ProcessMaterial(node, preferences, currentDocument, materials); } } } diff --git a/Common_glTF_Exporter/Materials/RevitMaterials.cs b/Common_glTF_Exporter/Materials/RevitMaterials.cs index 23e20a5..67c508c 100644 --- a/Common_glTF_Exporter/Materials/RevitMaterials.cs +++ b/Common_glTF_Exporter/Materials/RevitMaterials.cs @@ -11,6 +11,7 @@ using System.Windows.Controls; using System.Windows.Media.Media3D; using Material = Autodesk.Revit.DB.Material; +using Common_glTF_Exporter.Utils; namespace Common_glTF_Exporter.Export @@ -19,21 +20,45 @@ public static class RevitMaterials { const int ONEINTVALUE = 1; - /// - /// Export Revit materials. - /// - public static GLTFMaterial Export(MaterialNode node, - Preferences preferences, Document doc) + public static GLTFMaterial ProcessMaterial(MaterialNode node, + Preferences preferences, Document doc, IndexedDictionary materials) { - GLTFMaterial gl_mat = new GLTFMaterial(); - float opacity = ONEINTVALUE - (float)node.Transparency; + GLTFMaterial gl_mat; - Material material = doc.GetElement(node.MaterialId) as Material; + string materialId = node.MaterialId.ToString(); + if (materials.Contains(materialId)) + { + gl_mat = materials.GetElement(materialId); + } + else + { + Autodesk.Revit.DB.Material material = doc.GetElement(node.MaterialId) as Autodesk.Revit.DB.Material; if (material == null) { - return gl_mat; + gl_mat = GLTFExportUtils.GetGLTFMaterial(materials, node.Transparency, false); + materialId = gl_mat.UniqueId; } + else + { + gl_mat = RevitMaterials.Export(node, preferences, doc, material); + } + } + materials.AddOrUpdateCurrentMaterial(materialId, gl_mat, false); + + return gl_mat; + } + + + /// + /// Export Revit materials. + /// + public static GLTFMaterial Export(MaterialNode node, + Preferences preferences, Document doc, Material material) + { + + GLTFMaterial gl_mat = new GLTFMaterial(); + float opacity = ONEINTVALUE - (float)node.Transparency; gl_mat.name = material.Name; gl_mat.UniqueId = node.MaterialId.ToString();