Beispiel #1
0
        private static void ExtractWMOM2s(MapObjectDefinition wmo, WMORoot root, TileModels tileModels)
        {
            var setIndices = new List<int> { 0 };
            if (wmo.DoodadSet != 0) setIndices.Add(wmo.DoodadSet);

            foreach (var index in setIndices)
            {
                var set = root.DoodadSets[index];
                for (var k = 0; k < set.InstanceCount; k++)
                {
                    var dd = root.DoodadDefinitions[(int)set.FirstInstanceIndex + k];
                    if (string.IsNullOrEmpty(dd.FilePath)) continue;

                    var model = ExtractModel(wmo, dd);

                    if (model.Vertices.Length < 1) continue;
                    tileModels.Models.Add(model);
                }
            }
        }
Beispiel #2
0
        private static TileModel TransformM2Model(MapObjectDefinition wmo, DoodadDefinition definition, M2Model m2model)
        {
            var model = new TileModel
            {
                Vertices = new Vector3[m2model.BoundingVertices.Length]
            };

            var origin = new Vector3(-definition.Position.X, definition.Position.Z, definition.Position.Y);
            var wmoOrigin = CorrectWMOOrigin(wmo.Position);
            var rotation = definition.Rotation;
            var rotateY = Matrix.CreateRotationY((wmo.OrientationB - 90) * RadiansPerDegree);
            for (var i = 0; i < m2model.BoundingVertices.Length; i++)
            {
                var vector = m2model.BoundingVertices[i];
                var rotatedVector = Vector3.Transform(vector, rotation);
                rotatedVector = TransformToIntermediateCoords(rotatedVector);
                var finalModelVector = rotatedVector + origin;

                var rotatedWMOVector = Vector3.Transform(finalModelVector, rotateY);
                var finalWMOVector = rotatedWMOVector + wmoOrigin;

                model.Vertices[i] = finalWMOVector;
            }

            // 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;
        }
Beispiel #3
0
        private static TileModel ExtractModel(MapObjectDefinition wmo, DoodadDefinition definition)
        {
            var filePath = definition.FilePath;
            var m2model = ExtractM2Model(filePath);

            return TransformM2Model(wmo, definition, m2model);
        }