Skip to content

Commit

Permalink
Fix cloth vertex format descriptor export
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbyte committed Dec 6, 2018
1 parent 5826b92 commit 9c4b44e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ConverterApp/GR2Pane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private void UpdateCommonExporterSettings(ExporterOptions settings)
}
else
{
settings.ModelInfoFormat = DivinityModelInfoFormat.LSM;
settings.ModelInfoFormat = DivinityModelInfoFormat.LSMv1;
}
}

Expand Down
3 changes: 2 additions & 1 deletion LSLib/Granny/Model/ColladaMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,8 @@ public void ImportFromCollada(mesh mesh, VertexDescriptor vertexFormat, bool isS

}

if (Options.ModelInfoFormat == DivinityModelInfoFormat.LSM)
if (Options.ModelInfoFormat == DivinityModelInfoFormat.LSMv0
|| Options.ModelInfoFormat == DivinityModelInfoFormat.LSMv1)
{
if (!HasNormals || !HasTangents)
{
Expand Down
34 changes: 21 additions & 13 deletions LSLib/Granny/Model/DivinityMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,30 @@ public static List<DivinityFormatDesc> FromVertexFormat(VertexDescriptor format)
formats.Add(Make(DivinityVertexUsage.BoneIndices, DivinityVertexFormat.UInt8, (byte)format.NumBoneInfluences));
}

if (format.ColorMapType != ColorMapType.None)
if (format.NormalType != NormalType.None)
{
if (format.ColorMapType == ColorMapType.Byte4)
if (format.NormalType == NormalType.QTangent)
{
for (int i = 0; i < format.ColorMaps; i++)
{
formats.Add(Make(DivinityVertexUsage.Color, DivinityVertexFormat.UInt8, 4, (byte)i));
}
formats.Add(Make(DivinityVertexUsage.QTangent, DivinityVertexFormat.NormalInt16, 4));
}
else
{
throw new InvalidOperationException($"Color format not supported in LSM: {format.ColorMapType}");
throw new InvalidOperationException($"Normal format not supported in LSM: {format.NormalType}");
}
}

if (format.NormalType != NormalType.None)
if (format.ColorMapType != ColorMapType.None)
{
if (format.NormalType == NormalType.QTangent)
if (format.ColorMapType == ColorMapType.Byte4)
{
formats.Add(Make(DivinityVertexUsage.QTangent, DivinityVertexFormat.NormalInt16, 4));
for (int i = 0; i < format.ColorMaps; i++)
{
formats.Add(Make(DivinityVertexUsage.Color, DivinityVertexFormat.NormalUInt8, 4, (byte)i));
}
}
else
{
throw new InvalidOperationException($"Normal format not supported in LSM: {format.NormalType}");
throw new InvalidOperationException($"Color format not supported in LSM: {format.ColorMapType}");
}
}

Expand Down Expand Up @@ -266,7 +266,6 @@ public static DivinityMeshExtendedData MakeMeshExtendedData(Mesh mesh, DivinityM
}
else
{
extendedData.LSMVersion = 1;
switch (meshModelType)
{
case DivinityModelType.Normal:
Expand All @@ -282,7 +281,16 @@ public static DivinityMeshExtendedData MakeMeshExtendedData(Mesh mesh, DivinityM
break;
}

extendedData.UserMeshProperties.FormatDescs = DivinityFormatDesc.FromVertexFormat(mesh.VertexFormat);
if (format == DivinityModelInfoFormat.LSMv1)
{
extendedData.LSMVersion = 1;
extendedData.UserMeshProperties.FormatDescs = DivinityFormatDesc.FromVertexFormat(mesh.VertexFormat);
}
else
{
extendedData.LSMVersion = 0;
extendedData.UserMeshProperties.FormatDescs = new List<DivinityFormatDesc>();
}
}

return extendedData;
Expand Down
4 changes: 3 additions & 1 deletion LSLib/Granny/Model/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public enum DivinityModelInfoFormat
// User the UserDefinedProperties string to add properties
UserDefinedProperties,
// Use LSM UserMeshProperties
LSM
LSMv0,
// Use LSM UserMeshProperties and FormatDescs
LSMv1
};

public class ExporterOptions
Expand Down
2 changes: 1 addition & 1 deletion LSLib/LS/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class Common
{
public const int MajorVersion = 1;
public const int MinorVersion = 12;
public const int PatchVersion = 1;
public const int PatchVersion = 2;

/// <summary>
/// Returns the version number of the LSLib library
Expand Down

0 comments on commit 9c4b44e

Please sign in to comment.