Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions Common_glTF_Exporter/Core/GlTFExportContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
43 changes: 34 additions & 9 deletions Common_glTF_Exporter/Materials/RevitMaterials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,21 +20,45 @@ public static class RevitMaterials
{
const int ONEINTVALUE = 1;

/// <summary>
/// Export Revit materials.
/// </summary>
public static GLTFMaterial Export(MaterialNode node,
Preferences preferences, Document doc)
public static GLTFMaterial ProcessMaterial(MaterialNode node,
Preferences preferences, Document doc, IndexedDictionary<GLTFMaterial> 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;
}


/// <summary>
/// Export Revit materials.
/// </summary>
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();
Expand Down
Loading