Tidy up mesh transform calculation
This commit is contained in:
parent
0f9467b8c4
commit
bf47578133
|
@ -113,6 +113,7 @@ public class MeshBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// Let's try and place an object :)
|
// Let's try and place an object :)
|
||||||
|
// TODO: Handle failing to find model more gracefully
|
||||||
var modelName = modelNameProp.value.ToLower() + ".bin";
|
var modelName = modelNameProp.value.ToLower() + ".bin";
|
||||||
var modelPath = campaignResources.GetResourcePath(ResourceType.Object, modelName);
|
var modelPath = campaignResources.GetResourcePath(ResourceType.Object, modelName);
|
||||||
if (modelPath == null)
|
if (modelPath == null)
|
||||||
|
@ -123,20 +124,12 @@ public class MeshBuilder
|
||||||
var model = new ModelFile(modelPath);
|
var model = new ModelFile(modelPath);
|
||||||
model.ApplyJoints(joints);
|
model.ApplyJoints(joints);
|
||||||
|
|
||||||
// TODO: Handle failing to find model more gracefully
|
|
||||||
var pos = brush.position;
|
|
||||||
var rot = brush.angle;
|
|
||||||
var scale = scaleProp?.value ?? Vector3.One;
|
|
||||||
pos -= model.Header.Center;
|
|
||||||
|
|
||||||
// Calculate base model transform
|
// Calculate base model transform
|
||||||
var scalePart = Matrix4x4.CreateScale(scale);
|
var transform = Matrix4x4.CreateScale(scaleProp?.value ?? Vector3.One);
|
||||||
var rotPart = Matrix4x4.Identity;
|
transform *= Matrix4x4.CreateRotationX(float.DegreesToRadians(brush.angle.X));
|
||||||
rotPart *= Matrix4x4.CreateRotationX(float.DegreesToRadians(rot.X));
|
transform *= Matrix4x4.CreateRotationY(float.DegreesToRadians(brush.angle.Y));
|
||||||
rotPart *= Matrix4x4.CreateRotationY(float.DegreesToRadians(rot.Y));
|
transform *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(brush.angle.Z));
|
||||||
rotPart *= Matrix4x4.CreateRotationZ(float.DegreesToRadians(rot.Z));
|
transform *= Matrix4x4.CreateTranslation(brush.position - model.Header.Center);
|
||||||
var transPart = Matrix4x4.CreateTranslation(pos);
|
|
||||||
var modelTrans = scalePart * rotPart * transPart;
|
|
||||||
|
|
||||||
// for each polygon slam its vertices and indices :)
|
// for each polygon slam its vertices and indices :)
|
||||||
foreach (var poly in model.Polygons)
|
foreach (var poly in model.Polygons)
|
||||||
|
@ -146,7 +139,7 @@ public class MeshBuilder
|
||||||
foreach (var idx in poly.VertexIndices)
|
foreach (var idx in poly.VertexIndices)
|
||||||
{
|
{
|
||||||
var vertex = model.Vertices[idx];
|
var vertex = model.Vertices[idx];
|
||||||
vertex = Vector3.Transform(vertex, modelTrans);
|
vertex = Vector3.Transform(vertex, transform);
|
||||||
polyVertices.Add(vertex);
|
polyVertices.Add(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue