Fix incorrect rotation on object polys

This commit is contained in:
Jarrod Doyle 2024-12-10 21:33:18 +00:00
parent 2a75e016ef
commit a6e4e85470
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 11 additions and 6 deletions

View File

@ -126,9 +126,17 @@ public class MeshBuilder
var scale = scaleProp?.value ?? Vector3.One; var scale = scaleProp?.value ?? Vector3.One;
var model = new ModelFile(modelPath); var model = new ModelFile(modelPath);
pos -= model.Header.Center; 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 // for each object modify the vertices
// TODO: Almost perfect transform!
// TODO: Handle nested sub objects // TODO: Handle nested sub objects
foreach (var subObj in model.Objects) foreach (var subObj in model.Objects)
{ {
@ -140,11 +148,8 @@ public class MeshBuilder
var objTrans = subObj.Transform; var objTrans = subObj.Transform;
jointTrans = jointRot * objTrans; jointTrans = jointRot * objTrans;
} }
var scalePart = Matrix4x4.CreateScale(scale);
var rotPart = Matrix4x4.CreateFromYawPitchRoll(float.DegreesToRadians(rot.Y), float.DegreesToRadians(rot.X), var transform = jointTrans * modelTrans;
float.DegreesToRadians(rot.Z));
var transPart = Matrix4x4.CreateTranslation(pos);
var transform = jointTrans * scalePart * rotPart * transPart;
var start = subObj.PointIdx; var start = subObj.PointIdx;
var end = start + subObj.PointCount; var end = start + subObj.PointCount;