Ejemplo n.º 1
0
        public bool Load(Stream s)
        {
            BinaryReader br = new BinaryReader(s);

            string header = ((char)br.ReadByte()).ToString() + ((char)br.ReadByte()) + ((char)br.ReadByte()) + ((char)br.ReadByte());

            if (header != "GRSM")
                return false;

            majorVersion = br.ReadByte();
            minorVersion = br.ReadByte();

            if (!(majorVersion == 1 && (minorVersion >= 1 && minorVersion <= 5)))
                return false;

            animLen = br.ReadInt32();
            shadeType = br.ReadInt32();

            if (majorVersion >= 1 && minorVersion >= 4)
            {
                alpha = br.ReadByte();
            }
            else
            {
                alpha = 255;
            }

            br.ReadBytes(16);

            int textureCount = br.ReadInt32();
            textures = new Texture[textureCount];

            for (int i = 0; i < textureCount; i++)
            {
                Texture tex = new Texture();

                tex.Name = br.ReadCString(40);

                textures[i] = tex;
            }

            mainNode = br.ReadCString(40).Korean();

            int nodeCount = br.ReadInt32();
            nodes = new Node[nodeCount];

            for (int i = 0; i < nodeCount; i++)
            {
                Node n = new Node();

                if (!n.Load(br, majorVersion, minorVersion, i == 0))
                    return false;

                nodes[i] = n;
            }

            if (FindNode(mainNode) == null)
                return false;

            if (nodes.Length == 1)
                nodes[0].IsOnly = true;

            if (majorVersion < 1 || minorVersion < 5)
            {
                Node mNode = FindNode(mainNode);

                int frameCount = br.ReadInt32();
                mNode.PosKeyFrames = new PosKeyFrame[frameCount];

                for (int i = 0; i < frameCount; i++)
                {
                    PosKeyFrame pfk = new PosKeyFrame();

                    pfk.Read(br);

                    mNode.PosKeyFrames[i] = pfk;
                }
            }

            int volumeCount = br.ReadInt32();
            volumeBoxes = new VolumeBox[volumeCount];

            for (int i = 0; i < volumeCount; i++)
            {
                VolumeBox vb = new VolumeBox();

                vb.Read(br, majorVersion, minorVersion);

                volumeBoxes[i] = vb;
            }

            CalcBoundingBox();

            return true;
        }
Ejemplo n.º 2
0
        public bool Load(Stream s)
        {
            BinaryReader br = new BinaryReader(s);

            string header = ((char)br.ReadByte()).ToString() + ((char)br.ReadByte()) + ((char)br.ReadByte()) + ((char)br.ReadByte());

            if (header != "GRSM")
            {
                return(false);
            }

            majorVersion = br.ReadByte();
            minorVersion = br.ReadByte();

            if (!(majorVersion == 1 && (minorVersion >= 1 && minorVersion <= 5)))
            {
                return(false);
            }

            animLen   = br.ReadInt32();
            shadeType = br.ReadInt32();

            if (majorVersion >= 1 && minorVersion >= 4)
            {
                alpha = br.ReadByte();
            }
            else
            {
                alpha = 255;
            }

            br.ReadBytes(16);

            int textureCount = br.ReadInt32();

            textures = new Texture[textureCount];

            for (int i = 0; i < textureCount; i++)
            {
                Texture tex = new Texture();

                tex.Name = br.ReadCString(40);

                textures[i] = tex;
            }

            mainNode = br.ReadCString(40).Korean();

            int nodeCount = br.ReadInt32();

            nodes = new Node[nodeCount];

            for (int i = 0; i < nodeCount; i++)
            {
                Node n = new Node();

                if (!n.Load(br, majorVersion, minorVersion, i == 0))
                {
                    return(false);
                }

                nodes[i] = n;
            }

            if (FindNode(mainNode) == null)
            {
                return(false);
            }

            if (nodes.Length == 1)
            {
                nodes[0].IsOnly = true;
            }

            if (majorVersion < 1 || minorVersion < 5)
            {
                Node mNode = FindNode(mainNode);

                int frameCount = br.ReadInt32();
                mNode.PosKeyFrames = new PosKeyFrame[frameCount];

                for (int i = 0; i < frameCount; i++)
                {
                    PosKeyFrame pfk = new PosKeyFrame();

                    pfk.Read(br);

                    mNode.PosKeyFrames[i] = pfk;
                }
            }

            int volumeCount = br.ReadInt32();

            volumeBoxes = new VolumeBox[volumeCount];

            for (int i = 0; i < volumeCount; i++)
            {
                VolumeBox vb = new VolumeBox();

                vb.Read(br, majorVersion, minorVersion);

                volumeBoxes[i] = vb;
            }

            CalcBoundingBox();

            return(true);
        }
Ejemplo n.º 3
0
            public bool Load(BinaryReader br, byte majorVersion, byte minorVersion, bool main)
            {
                Name = br.ReadCString(40);
                ParentName = br.ReadCString(40);

                IsMain = main;

                int textureCount = br.ReadInt32();
                Textures = new int[textureCount];

                for (int i = 0; i < textureCount; i++)
                {
                    Textures[i] = br.ReadInt32();
                }

                OffsetMT = new float[12];
                for (int i = 0; i < 12; i++)
                {
                    OffsetMT[i] = br.ReadSingle();
                }

                Position.Read(br);
                RotAngle = br.ReadSingle();
                RotAxis.Read(br);
                Scale.Read(br);

                int vertexCount = br.ReadInt32();
                Vertices = new Vertex[vertexCount];

                for (int i = 0; i < vertexCount; i++)
                {
                    Vertices[i].Read(br);
                }

                int tvertexCount = br.ReadInt32();
                TVertices = new TVertex[tvertexCount];

                for (int i = 0; i < tvertexCount; i++)
                {
                    TVertices[i].Read(br, majorVersion, minorVersion);
                }

                int faceCount = br.ReadInt32();
                Faces = new Face[faceCount];

                for (int i = 0; i < faceCount; i++)
                {
                    Face f = new Face();

                    f.VertexID = new ushort[3];
                    f.TVertexID = new ushort[3];

                    for (int n = 0; n < 3; n++)
                        f.VertexID[n] = br.ReadUInt16();

                    for (int n = 0; n < 3; n++)
                        f.TVertexID[n] = br.ReadUInt16();

                    f.TexID = br.ReadUInt16();
                    f.Padding = br.ReadUInt16();
                    f.TwoSide = br.ReadInt32();

                    if (majorVersion >= 1 && minorVersion >= 2)
                    {
                        f.SmoothGroup = br.ReadInt32();
                    }
                    else
                    {
                        f.SmoothGroup = 0;
                    }

                    Faces[i] = f;
                }

                if (majorVersion >= 1 && minorVersion >= 5)
                {
                    int frameCount = br.ReadInt32();
                    PosKeyFrames = new PosKeyFrame[frameCount];

                    for (int i = 0; i < frameCount; i++)
                    {
                        PosKeyFrame pfk = new PosKeyFrame();

                        pfk.Read(br);

                        PosKeyFrames[i] = pfk;
                    }
                }

                int rotFrameCount = br.ReadInt32();
                RotKeyFrames = new RotKeyFrame[rotFrameCount];

                for (int i = 0; i < rotFrameCount; i++)
                {
                    RotKeyFrame rfk = new RotKeyFrame();

                    rfk.Read(br);

                    RotKeyFrames[i] = rfk;
                }

                return true;
            }
Ejemplo n.º 4
0
            public bool Load(BinaryReader br, byte majorVersion, byte minorVersion, bool main)
            {
                Name       = br.ReadCString(40);
                ParentName = br.ReadCString(40);

                IsMain = main;

                int textureCount = br.ReadInt32();

                Textures = new int[textureCount];

                for (int i = 0; i < textureCount; i++)
                {
                    Textures[i] = br.ReadInt32();
                }

                OffsetMT = new float[12];
                for (int i = 0; i < 12; i++)
                {
                    OffsetMT[i] = br.ReadSingle();
                }

                Position.Read(br);
                RotAngle = br.ReadSingle();
                RotAxis.Read(br);
                Scale.Read(br);

                int vertexCount = br.ReadInt32();

                Vertices = new Vertex[vertexCount];

                for (int i = 0; i < vertexCount; i++)
                {
                    Vertices[i].Read(br);
                }

                int tvertexCount = br.ReadInt32();

                TVertices = new TVertex[tvertexCount];

                for (int i = 0; i < tvertexCount; i++)
                {
                    TVertices[i].Read(br, majorVersion, minorVersion);
                }

                int faceCount = br.ReadInt32();

                Faces = new Face[faceCount];

                for (int i = 0; i < faceCount; i++)
                {
                    Face f = new Face();

                    f.VertexID  = new ushort[3];
                    f.TVertexID = new ushort[3];

                    for (int n = 0; n < 3; n++)
                    {
                        f.VertexID[n] = br.ReadUInt16();
                    }

                    for (int n = 0; n < 3; n++)
                    {
                        f.TVertexID[n] = br.ReadUInt16();
                    }

                    f.TexID   = br.ReadUInt16();
                    f.Padding = br.ReadUInt16();
                    f.TwoSide = br.ReadInt32();

                    if (majorVersion >= 1 && minorVersion >= 2)
                    {
                        f.SmoothGroup = br.ReadInt32();
                    }
                    else
                    {
                        f.SmoothGroup = 0;
                    }

                    Faces[i] = f;
                }

                if (majorVersion >= 1 && minorVersion >= 5)
                {
                    int frameCount = br.ReadInt32();
                    PosKeyFrames = new PosKeyFrame[frameCount];

                    for (int i = 0; i < frameCount; i++)
                    {
                        PosKeyFrame pfk = new PosKeyFrame();

                        pfk.Read(br);

                        PosKeyFrames[i] = pfk;
                    }
                }

                int rotFrameCount = br.ReadInt32();

                RotKeyFrames = new RotKeyFrame[rotFrameCount];

                for (int i = 0; i < rotFrameCount; i++)
                {
                    RotKeyFrame rfk = new RotKeyFrame();

                    rfk.Read(br);

                    RotKeyFrames[i] = rfk;
                }

                return(true);
            }