Represents the MODD chunk
예제 #1
0
        static void ReadMODD(BinaryReader br, WMORoot wmo, uint size)
        {
            // Why oh why is wmo.Header.DoodadCount wrong sometimes
            // 40 is the size of DoodadDefinition
            wmo.DoodadDefinitions = new DoodadDefinition[size / 40];

            for (var i = 0; i < wmo.DoodadDefinitions.Length; i++)
            {
                var dd = new DoodadDefinition
                             {
                                 NameIndex = br.ReadInt32(),
                                 Position = br.ReadVector3(),
                                 Rotation = br.ReadQuaternion(),
                                 Scale = br.ReadSingle(),
                                 Color = br.ReadColor4()
                             };

                if (dd.NameIndex != -1)
                {
                    if(!wmo.DoodadFiles.TryGetValue(dd.NameIndex, out dd.FilePath))
                    {
                        dd.FilePath = "";
                        log.Error(String.Format("Doodad File Path for index: {0} missing from the Dictionary!", dd.NameIndex));
                    }
                }

                wmo.DoodadDefinitions[i] = dd;
            }
        }
예제 #2
0
        private static void CalculateModelsWMOSpaceBounds(DoodadDefinition def, M2Model model)
        {
            var wmoSpaceVecs = new List<Vector3>(model.BoundingVertices.Length);
            for (var j = 0; j < model.BoundingVertices.Length; j++)
            {
                Vector3 rotated;
                Vector3.Transform(ref model.BoundingVertices[j], ref def.ModelToWMO, out rotated);

                Vector3 final;
                Vector3.Add(ref rotated, ref def.Position, out final);
                wmoSpaceVecs.Add(final);
            }
            def.Extents = new BoundingBox(wmoSpaceVecs.ToArray());
        }
예제 #3
0
        //private static void DrawBoundingBox(BoundingBox boundingBox, Color color, WMORoot currentWMO)
        //{
        //    var min = boundingBox.Min;
        //    var max = boundingBox.Max;
        //    DrawBoundingBox(min, max, color, currentWMO);
        //}
        //private static void DrawBoundingBox(Vector3 min, Vector3 max, Color color, WMORoot currentWMO)
        //{
        //    var zero = min;
        //    var one = new Vector3(min.X, max.Y, min.Z);
        //    var two = new Vector3(min.X, max.Y, max.Z);
        //    var three = new Vector3(min.X, min.Y, max.Z);
        //    var four = new Vector3(max.X, min.Y, min.Z);
        //    var five = new Vector3(max.X, max.Y, min.Z);
        //    var six = max;
        //    var seven = new Vector3(max.X, min.Y, max.Z);
        //    var offset = currentWMO.WmoVertices.Count;
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(zero, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(one, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(two, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(three, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(four, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(five, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(six, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(seven, color, Vector3.Up));
        //    // Bottom Face
        //    currentWMO.WmoIndices.Add(offset + 0);
        //    currentWMO.WmoIndices.Add(offset + 1);
        //    currentWMO.WmoIndices.Add(offset + 5);
        //    currentWMO.WmoIndices.Add(offset + 0);
        //    currentWMO.WmoIndices.Add(offset + 5);
        //    currentWMO.WmoIndices.Add(offset + 4);
        //    // Front face
        //    currentWMO.WmoIndices.Add(offset + 0);
        //    currentWMO.WmoIndices.Add(offset + 1);
        //    currentWMO.WmoIndices.Add(offset + 2);
        //    currentWMO.WmoIndices.Add(offset + 0);
        //    currentWMO.WmoIndices.Add(offset + 2);
        //    currentWMO.WmoIndices.Add(offset + 3);
        //    // Left face
        //    currentWMO.WmoIndices.Add(offset + 1);
        //    currentWMO.WmoIndices.Add(offset + 2);
        //    currentWMO.WmoIndices.Add(offset + 6);
        //    currentWMO.WmoIndices.Add(offset + 1);
        //    currentWMO.WmoIndices.Add(offset + 6);
        //    currentWMO.WmoIndices.Add(offset + 5);
        //    // Back face
        //    currentWMO.WmoIndices.Add(offset + 5);
        //    currentWMO.WmoIndices.Add(offset + 6);
        //    currentWMO.WmoIndices.Add(offset + 7);
        //    currentWMO.WmoIndices.Add(offset + 5);
        //    currentWMO.WmoIndices.Add(offset + 7);
        //    currentWMO.WmoIndices.Add(offset + 4);
        //    // Right face
        //    currentWMO.WmoIndices.Add(offset + 0);
        //    currentWMO.WmoIndices.Add(offset + 3);
        //    currentWMO.WmoIndices.Add(offset + 7);
        //    currentWMO.WmoIndices.Add(offset + 0);
        //    currentWMO.WmoIndices.Add(offset + 7);
        //    currentWMO.WmoIndices.Add(offset + 4);
        //    // Top face
        //    currentWMO.WmoIndices.Add(offset + 3);
        //    currentWMO.WmoIndices.Add(offset + 2);
        //    currentWMO.WmoIndices.Add(offset + 6);
        //    currentWMO.WmoIndices.Add(offset + 3);
        //    currentWMO.WmoIndices.Add(offset + 6);
        //    currentWMO.WmoIndices.Add(offset + 7);
        //}
        //private static void DrawPositionPoint(Vector3 position, WMORoot currentWMO)
        //{
        //    var color = Color.Green;
        //    var step = TerrainConstants.UnitSize/2;
        //    var topRight = new Vector3(position.X + step, position.Y + step, position.Z);
        //    var topLeft = new Vector3(position.X + step, position.Y - step, position.Z);
        //    var bottomRight = new Vector3(position.X - step, position.Y + step, position.Z);
        //    var bottomLeft = new Vector3(position.X - step, position.Y - step, position.Z);
        //    var offset = currentWMO.WmoVertices.Count;
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(bottomRight, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(topRight, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(topLeft, color, Vector3.Up));
        //    currentWMO.WmoIndices.Add(offset + 0);
        //    currentWMO.WmoIndices.Add(offset + 1);
        //    currentWMO.WmoIndices.Add(offset + 2);
        //    offset = currentWMO.WmoVertices.Count;
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(bottomRight, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(topLeft, color, Vector3.Up));
        //    currentWMO.WmoVertices.Add(new VertexPositionNormalColored(bottomLeft, color, Vector3.Up));
        //    currentWMO.WmoIndices.Add(offset + 0);
        //    currentWMO.WmoIndices.Add(offset + 1);
        //    currentWMO.WmoIndices.Add(offset + 2);
        //}
        private static M2.M2 TransformWMOM2(M2Model model, IEnumerable<int> indicies, DoodadDefinition modd)
        {
            var currentM2 = new M2.M2();

            currentM2.Vertices.Clear();
            currentM2.Indices.Clear();

            var origin = new Vector3(modd.Position.X, modd.Position.Y, modd.Position.Z);

            // Create the scalar
            var scalar = modd.Scale;
            var scaleMatrix = Matrix.CreateScale(scalar);

            // Create the rotations
            var quatX = modd.Rotation.X;
            var quatY = modd.Rotation.Y;
            var quatZ = modd.Rotation.Z;
            var quatW = modd.Rotation.W;

            var rotQuat = new Quaternion(quatX, quatY, quatZ, quatW);
            var rotMatrix = Matrix.CreateFromQuaternion(rotQuat);

            var compositeMatrix = Matrix.Multiply(scaleMatrix, rotMatrix);

            for (var i = 0; i < model.BoundingVertices.Length; i++)
            {
                // Scale and transform
                var basePosVector = model.BoundingVertices[i];
                var baseNormVector = model.BoundingNormals[i];
                //PositionUtil.TransformToXNACoordSystem(ref vertex.Position);

                // Scale
                //Vector3 scaledVector;
                //Vector3.Transform(ref vector, ref scaleMatrix, out scaledVector);

                // Rotate
                Vector3 rotatedPosVector;
                Vector3.Transform(ref basePosVector, ref compositeMatrix, out rotatedPosVector);

                Vector3 rotatedNormVector;
                Vector3.Transform(ref baseNormVector, ref compositeMatrix, out rotatedNormVector);
                rotatedNormVector.Normalize();

                // Translate
                Vector3 finalPosVector;
                Vector3.Add(ref rotatedPosVector, ref origin, out finalPosVector);

                currentM2.Vertices.Add(finalPosVector);
            }

            currentM2.Indices.AddRange(indicies);
            return currentM2;
        }