Beispiel #1
0
        public bool PreLoadChunk()
        {
            mFile.Position = mInfo.ofsMcnk;
            if (ReadSignature() != "MCNK")
                return false;

            uint size = mFile.Read<uint>();
            // +8 -> MCNK + size = 8 bytes
            if (size + 8 != mInfo.size)
                return false;

            mHeader = mFile.Read<MCNK>();
            var posY = (32.0f * Utils.Metrics.Tilesize - mHeader.position.X) - Utils.Metrics.MidPoint;
            var posX = (32.0f * Utils.Metrics.Tilesize - mHeader.position.Y) - Utils.Metrics.MidPoint;
            mHeader.position.X = posX;
            mHeader.position.Y = posY;

            mFile.Position = mInfo.ofsMcnk + mHeader.ofsHeight;
            if (ReadSignature() != "MCVT")
                return false;

            size = mFile.Read<uint>();
            float[] height = new float[145];
            uint counter = 0;
            Vector3 minPos = new Vector3(999999.9f);
            Vector3 maxPos = new Vector3(-999999.9f);
            minPos.X = mHeader.position.X;
            minPos.Y = mHeader.position.Y;
            maxPos.X = minPos.X + Utils.Metrics.Chunksize;
            maxPos.Y = minPos.Y + Utils.Metrics.Chunksize;
            for (int i = 0; i < 17; ++i)
            {
                for (int j = 0; j < (((i % 2) != 0) ? 8 : 9); ++j)
                {
                    float x, y, z;
                    z = mFile.Read<float>() + mHeader.position.Z;
                    y = i * Utils.Metrics.Unitsize * 0.5f + mHeader.position.Y;
                    x = j * Utils.Metrics.Unitsize + mHeader.position.X;

                    if ((i % 2) != 0)
                        x += 0.5f * Utils.Metrics.Unitsize;

                    if (z < minPos.Z)
                        minPos.Z = z;
                    if (z > maxPos.Z)
                        maxPos.Z = z;

                    vertices[counter] = new ADTVertex()
                    {
                        X = x,
                        Y = y,
                        Z = z,
                        U = ADTStaticData.TexCoords[counter, 0],
                        V = ADTStaticData.TexCoords[counter, 1],
                        S = ADTStaticData.AlphaCoords[counter, 0],
                        T = ADTStaticData.AlphaCoords[counter, 1]
                    };

                    ++counter;
                }
            }

            mBox = new BoundingBox(minPos, maxPos);
            MinPosition = minPos;
            MaxPosition = maxPos;

            mFile.Position = mInfo.ofsMcnk + mHeader.ofsLayer;
            if (ReadSignature() != "MCLY")
                return false;

            mFile.Read<uint>();

            for (int i = 0; i < mHeader.nLayers; ++i)
            {
                var layer = mFile.Read<MCLY>();
                mLayers.Add(layer);
                if ((layer.flags & 0x40) != 0)
                    mTextureFlags[i] = 1;
            }

            LoadAlphaData();
            if (!LoadNormals())
                return false;

            LoadShadows();

            mFile.Position = mInfo.ofsMcnk + mHeader.ofsRefs + 0x08;
            for (uint i = 0; i < mHeader.nDoodadRefs; ++i)
                mRefs.Add(mFile.Read<uint>());
            for (uint i = 0; i < mHeader.nMapObjRefs; ++i)
                mWmoRefs.Add(mFile.Read<uint>());

            LoadLiquids();

            return true;
        }
Beispiel #2
0
        public bool PreLoadChunk()
        {
            mFile.Position = mInfo.ofsMcnk;
            if (ReadSignature() != "MCNK")
            {
                return(false);
            }

            uint size = mFile.Read <uint>();

            // +8 -> MCNK + size = 8 bytes
            if (size + 8 != mInfo.size)
            {
                return(false);
            }

            mHeader = mFile.Read <MCNK>();
            var posY = (32.0f * Utils.Metrics.Tilesize - mHeader.position.X) - Utils.Metrics.MidPoint;
            var posX = (32.0f * Utils.Metrics.Tilesize - mHeader.position.Y) - Utils.Metrics.MidPoint;

            mHeader.position.X = posX;
            mHeader.position.Y = posY;

            mFile.Position = mInfo.ofsMcnk + mHeader.ofsHeight;
            if (ReadSignature() != "MCVT")
            {
                return(false);
            }

            size = mFile.Read <uint>();
            float[] height  = new float[145];
            uint    counter = 0;
            Vector3 minPos  = new Vector3(999999.9f);
            Vector3 maxPos  = new Vector3(-999999.9f);

            minPos.X = mHeader.position.X;
            minPos.Y = mHeader.position.Y;
            maxPos.X = minPos.X + Utils.Metrics.Chunksize;
            maxPos.Y = minPos.Y + Utils.Metrics.Chunksize;
            for (int i = 0; i < 17; ++i)
            {
                for (int j = 0; j < (((i % 2) != 0) ? 8 : 9); ++j)
                {
                    float x, y, z;
                    z = mFile.Read <float>() + mHeader.position.Z;
                    y = i * Utils.Metrics.Unitsize * 0.5f + mHeader.position.Y;
                    x = j * Utils.Metrics.Unitsize + mHeader.position.X;

                    if ((i % 2) != 0)
                    {
                        x += 0.5f * Utils.Metrics.Unitsize;
                    }

                    if (z < minPos.Z)
                    {
                        minPos.Z = z;
                    }
                    if (z > maxPos.Z)
                    {
                        maxPos.Z = z;
                    }

                    vertices[counter] = new ADTVertex()
                    {
                        X = x,
                        Y = y,
                        Z = z,
                        U = ADTStaticData.TexCoords[counter, 0],
                        V = ADTStaticData.TexCoords[counter, 1],
                        S = ADTStaticData.AlphaCoords[counter, 0],
                        T = ADTStaticData.AlphaCoords[counter, 1]
                    };

                    ++counter;
                }
            }

            mBox        = new BoundingBox(minPos, maxPos);
            MinPosition = minPos;
            MaxPosition = maxPos;

            mFile.Position = mInfo.ofsMcnk + mHeader.ofsLayer;
            if (ReadSignature() != "MCLY")
            {
                return(false);
            }

            mFile.Read <uint>();

            for (int i = 0; i < mHeader.nLayers; ++i)
            {
                var layer = mFile.Read <MCLY>();
                mLayers.Add(layer);
                if ((layer.flags & 0x40) != 0)
                {
                    mTextureFlags[i] = 1;
                }
            }

            LoadAlphaData();
            if (!LoadNormals())
            {
                return(false);
            }

            LoadShadows();

            mFile.Position = mInfo.ofsMcnk + mHeader.ofsRefs + 0x08;
            for (uint i = 0; i < mHeader.nDoodadRefs; ++i)
            {
                mRefs.Add(mFile.Read <uint>());
            }
            for (uint i = 0; i < mHeader.nMapObjRefs; ++i)
            {
                mWmoRefs.Add(mFile.Read <uint>());
            }

            LoadLiquids();

            return(true);
        }