From a6e4e8547080fc2a654cf9eae2cb21a646b68723 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Tue, 10 Dec 2024 21:33:18 +0000 Subject: [PATCH] Fix incorrect rotation on object polys --- KeepersCompound.Lightmapper/MeshBuilder.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/KeepersCompound.Lightmapper/MeshBuilder.cs b/KeepersCompound.Lightmapper/MeshBuilder.cs index fa5472f..340fff9 100644 --- a/KeepersCompound.Lightmapper/MeshBuilder.cs +++ b/KeepersCompound.Lightmapper/MeshBuilder.cs @@ -126,9 +126,17 @@ public class MeshBuilder var scale = scaleProp?.value ?? Vector3.One; var model = new ModelFile(modelPath); pos -= model.Header.Center; + + + var scalePart = Matrix4x4.CreateScale(scale); + var rotPart = Matrix4x4.Identity; + rotPart *= Matrix4x4.CreateRotationX(float.DegreesToRadians(rot.X)); + rotPart *= Matrix4x4.CreateRotationY(float.DegreesToRadians(rot.Y)); + rotPart *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(rot.Z)); + var transPart = Matrix4x4.CreateTranslation(pos); + var modelTrans = scalePart * rotPart * transPart; // for each object modify the vertices - // TODO: Almost perfect transform! // TODO: Handle nested sub objects foreach (var subObj in model.Objects) { @@ -140,11 +148,8 @@ public class MeshBuilder var objTrans = subObj.Transform; jointTrans = jointRot * objTrans; } - var scalePart = Matrix4x4.CreateScale(scale); - var rotPart = Matrix4x4.CreateFromYawPitchRoll(float.DegreesToRadians(rot.Y), float.DegreesToRadians(rot.X), - float.DegreesToRadians(rot.Z)); - var transPart = Matrix4x4.CreateTranslation(pos); - var transform = jointTrans * scalePart * rotPart * transPart; + + var transform = jointTrans * modelTrans; var start = subObj.PointIdx; var end = start + subObj.PointCount;