Skip to content

Commit

Permalink
Fixed MeshOpt Compression when using normals
Browse files Browse the repository at this point in the history
  • Loading branch information
vnoves committed Aug 8, 2024
1 parent 77bcb50 commit 3f23e2a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Common_glTF_Exporter/Core/GlTFExportContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void OnPolymesh(PolymeshTopology polymesh)

if (preferences.normals)
{
GLTFExportUtils.AddNormals(preferences, CurrentTransform, polymesh, currentGeometry.CurrentItem.Normals);
GLTFExportUtils.AddNormals(CurrentTransform, polymesh, currentGeometry.CurrentItem.Normals);
}
}

Expand All @@ -331,6 +331,8 @@ public void OnPolymesh(PolymeshTopology polymesh)
/// <param name="elementId">Element Id.</param>
public void OnElementEnd(ElementId elementId)
{
element = doc.GetElement(elementId);

if (currentVertices == null || !currentVertices.List.Any())
{
return;
Expand All @@ -343,7 +345,7 @@ public void OnElementEnd(ElementId elementId)
return;
}

if (!Util.CanBeLockOrHidden(element, view, isRFA))
if (!Util.CanBeLockOrHidden(element, view, isRFA) || element is RevitLinkInstance)
{
return;
}
Expand Down
16 changes: 13 additions & 3 deletions Common_glTF_Exporter/Export/MeshOpt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using System;

namespace Common_glTF_Exporter.Export
{
Expand Down Expand Up @@ -55,10 +57,18 @@ public static void Compress(Preferences preferences)
Gltf.GltfPack.gltfpack(fileToCompress,
fileToCompressTemp, "report.txt", settings);

#endif
#endif

files.ForEach(x => File.Delete(x));
File.Move(fileToCompressTemp, fileToCompress);
if (File.Exists(fileToCompressTemp))
{
files.ForEach(x => File.Delete(x));
File.Move(fileToCompressTemp, fileToCompress);
}
else
{
Console.WriteLine("The Compression didn't work");
}


if (preferences.format == FormatEnum.gltf)
{
Expand Down
2 changes: 1 addition & 1 deletion Common_glTF_Exporter/Transform/ModelRotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static List<double> Get(bool flipAxis)
}
else
{
return new List<double> { 0, 0, 0, 0};
return new List<double> { 0, 0, 0, 1};
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Common_glTF_Exporter/Utils/glTFExportUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Common_glTF_Exporter.Utils
{
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
Expand Down Expand Up @@ -122,7 +123,7 @@ public static GLTFBinaryData AddGeometryMeta(List<GLTFBuffer> buffers, List<GLTF
return bufferData;
}

public static void AddNormals(Preferences preferences, Transform transform, PolymeshTopology polymesh, List<double> normals)
public static void AddNormals(Transform transform, PolymeshTopology polymesh, List<double> normals)
{
IList<XYZ> polymeshNormals = polymesh.GetNormals();

Expand Down

0 comments on commit 3f23e2a

Please sign in to comment.