Example #1
0
		public M2 GetOrReadM2(MapDoodadDefinition definition)
		{
			M2 wmo;
			if (!M2s.TryGetValue(definition.FilePath, out wmo))
			{
				M2s.Add(definition.FilePath, wmo = M2Reader.ReadM2(WCellTerrainSettings.GetDefaultMPQFinder(), definition));
			}
			return wmo;
		}
Example #2
0
        public static M2 ReadM2(MpqLibrarian librarian, MapDoodadDefinition doodadDefinition)
        {
            var model = M2Reader.ReadM2(librarian, doodadDefinition.FilePath, false);

            var tempIndices = new List<int>();
            foreach (var tri in model.BoundingTriangles)
            {
                tempIndices.Add(tri.Index0);
                tempIndices.Add(tri.Index1);
                tempIndices.Add(tri.Index2);
            }

            var currentM2 = TransformM2(model, tempIndices, doodadDefinition);
            currentM2.Bounds = new BoundingBox(currentM2.Vertices.ToArray());

            return currentM2;
        }
Example #3
0
		static M2 TransformM2(M2Model model, IEnumerable<int> indicies, MapDoodadDefinition mddf)
		{
			var currentM2 = new M2();
			currentM2.Vertices.Clear();
			currentM2.Indices.Clear();

			var posX = (mddf.Position.X - TerrainConstants.CenterPoint) * -1;
			var posY = (mddf.Position.Y - TerrainConstants.CenterPoint) * -1;
			var origin = new Vector3(posX, posY, mddf.Position.Z);

			// Create the scale matrix used in the following loop.
			Matrix scaleMatrix;
			Matrix.CreateScale(mddf.Scale, out scaleMatrix);

			// Creation the rotations
			var rotateZ = Matrix.CreateRotationZ(MathHelper.ToRadians(mddf.OrientationB + 180));
			var rotateY = Matrix.CreateRotationY(MathHelper.ToRadians(mddf.OrientationA));
			var rotateX = Matrix.CreateRotationX(MathHelper.ToRadians(mddf.OrientationC));

			var worldMatrix = Matrix.Multiply(scaleMatrix, rotateZ);
			worldMatrix = Matrix.Multiply(worldMatrix, rotateX);
			worldMatrix = Matrix.Multiply(worldMatrix, rotateY);

			for (var i = 0; i < model.BoundingVertices.Length; i++)
			{
				var position = model.BoundingVertices[i];
				var normal = model.BoundingNormals[i];

				// Scale and Rotate
				Vector3 rotatedPosition;
				Vector3.Transform(ref position, ref worldMatrix, out rotatedPosition);

				Vector3 rotatedNormal;
				Vector3.Transform(ref normal, ref worldMatrix, out rotatedNormal);
				rotatedNormal.Normalize();

				// Translate
				Vector3 finalVector;
				Vector3.Add(ref rotatedPosition, ref origin, out finalVector);

				currentM2.Vertices.Add(finalVector);
			}

			currentM2.Indices.AddRange(indicies);
			return currentM2;
		}
Example #4
0
		public static M2 ReadM2(MpqLibrarian librarian, MapDoodadDefinition doodadDefinition)
		{
			var filePath = doodadDefinition.FilePath;
			var ext = Path.GetExtension(filePath);

			if (ext.Equals(".mdx") ||
				ext.Equals(".mdl"))
			{
				filePath = Path.ChangeExtension(filePath, ".m2");
			}

			var model = M2Reader.ReadM2(librarian, doodadDefinition.FilePath);

			var tempIndices = new List<int>();
			foreach (var tri in model.BoundingTriangles)
			{
				tempIndices.Add(tri.Index2);
				tempIndices.Add(tri.Index1);
				tempIndices.Add(tri.Index0);
			}

			var currentM2 = TransformM2(model, tempIndices, doodadDefinition);
			var tempVertices = currentM2.Vertices;
			var bounds = new BoundingBox(tempVertices.ToArray());
			currentM2.Bounds = bounds;

			return currentM2;
		}
Example #5
0
        static void ReadMDDF(BinaryReader fileReader, ADT adt)
        {
            var type = fileReader.ReadUInt32();
            var size = fileReader.ReadUInt32();

            var endPos = fileReader.BaseStream.Position + size;
            while (fileReader.BaseStream.Position < endPos)
            {
                var doodadDefinition = new MapDoodadDefinition();
                var nameIndex = fileReader.ReadInt32();
                doodadDefinition.FilePath = adt.ModelFiles[nameIndex]; // 4 bytes
                doodadDefinition.UniqueId = fileReader.ReadUInt32(); // 4 bytes
                var Y = fileReader.ReadSingle();
                var Z = fileReader.ReadSingle();
                var X = fileReader.ReadSingle();
                doodadDefinition.Position = new Vector3(X, Y, Z); // 12 bytes
                doodadDefinition.OrientationA = fileReader.ReadSingle(); // 4 Bytes
                doodadDefinition.OrientationB = fileReader.ReadSingle(); // 4 Bytes
                doodadDefinition.OrientationC = fileReader.ReadSingle(); // 4 Bytes
                doodadDefinition.Scale = fileReader.ReadUInt16() / 1024f; // 2 bytes
                doodadDefinition.Flags = fileReader.ReadUInt16(); // 2 bytes
                adt.DoodadDefinitions.Add(doodadDefinition);
            }
        }