private static TileModel TransformM2Model(MapDoodadDefinition definition, M2Model m2model) { var model = new TileModel { Vertices = new Vector3[m2model.BoundingVertices.Length] }; // Rotate var origin = new Vector3( (TerrainConstants.CenterPoint - definition.Position.X), definition.Position.Y, (TerrainConstants.CenterPoint - definition.Position.Z) ); for (var i = 0; i < model.Vertices.Length; i++) { // Reverse the previos coord transform for the rotation. var vector = TransformToIntermediateCoords(m2model.BoundingVertices[i]); // Create the rotation matrices var rotateX = Matrix.CreateRotationX(definition.OrientationC * RadiansPerDegree); var rotateY = Matrix.CreateRotationY((definition.OrientationB - 90) * RadiansPerDegree); var rotateZ = Matrix.CreateRotationZ(-definition.OrientationA * RadiansPerDegree); // Rotate the vector var rotatedVector = Vector3.Transform(vector, rotateY); rotatedVector = Vector3.Transform(rotatedVector, rotateZ); rotatedVector = Vector3.Transform(rotatedVector, rotateX); var finalVector = rotatedVector + origin; model.Vertices[i] = finalVector; } // Add the triangle indices to the model model.Triangles = new Index3[m2model.BoundingTriangles.Length]; for (var i = 0; i < m2model.BoundingTriangles.Length; i++) { var tri = m2model.BoundingTriangles[i]; model.Triangles[i] = new Index3 { Index0 = (short)tri[2], Index1 = (short)tri[1], Index2 = (short)tri[0] }; } // Calculate the boundingbox model.Bounds = new BoundingBox(model.Vertices); return model; }
private static TileModel ExtractModel(MapDoodadDefinition definition) { var filePath = definition.FilePath; var m2model = ExtractM2Model(filePath); return TransformM2Model(definition, m2model); }