예제 #1
0
        public override void ReadFromStream(Stream stream)
        {
            EndianBinaryReader reader = new EndianBinaryReader(stream, Program.Endianness);

            /* Read header */
            FileSize                = reader.ReadUInt32();
            Unknown0x04             = reader.ReadUInt32();
            UnknownPointer          = reader.ReadUInt32();
            AssetListPointer        = reader.ReadUInt32();
            ModelListPointer        = reader.ReadUInt32();
            NodeListPointer         = reader.ReadUInt32();
            TransformIndicesPointer = reader.ReadUInt32();
            TransformDataPointer    = reader.ReadUInt32();
            GroupListPointer        = reader.ReadUInt32();
            PrimitiveListPointer    = reader.ReadUInt32();
            VertexDataPointer       = reader.ReadUInt32();
            TextureListPointer      = reader.ReadUInt32();

            /* Read data */
            Assets     = BinaryHelpers.GetMultiDictionary <short, short>(stream, AssetListPointer);
            Models     = BinaryHelpers.GetArray <Model>(stream, ModelListPointer);
            Nodes      = BinaryHelpers.GetArray <Node>(stream, NodeListPointer);
            Groups     = BinaryHelpers.GetArray <Group>(stream, GroupListPointer);
            Primitives = BinaryHelpers.GetArray <Primitive>(stream, PrimitiveListPointer);
            Vertices   = GetVertices(stream, VertexDataPointer, (int)Primitives.Max(x => x.VertexIndices.Max()) + 1);
            Textures   = BinaryHelpers.GetArray <Texture>(stream, TextureListPointer);

            /* Generate textures */
            convTextures = new Cobalt.Texture.Texture[Textures.Length];
            for (int i = 0; i < Textures.Length; i++)
            {
                convTextures[i] = new Cobalt.Texture.Texture(Textures[i].Image, OpenTK.Graphics.OpenGL.TextureWrapMode.Repeat, OpenTK.Graphics.OpenGL.TextureWrapMode.Repeat, OpenTK.Graphics.OpenGL.TextureMinFilter.Linear, OpenTK.Graphics.OpenGL.TextureMagFilter.Linear);
            }

            /* Generate transforms */
            nodeTransforms = new NodeTransformData[Nodes.Length][];
            for (int i = 0; i < Nodes.Length; i++)
            {
                nodeTransforms[i] = new NodeTransformData[Nodes[i].NumTransformIndices];
                for (int j = 0; j < nodeTransforms[i].Length; j++)
                {
                    TransformIndices indices = GetTransformIndices(stream, TransformIndicesPointer, Nodes[i].TransformIndices[j]);

                    NodeTransformData nodeTransform = new NodeTransformData(
                        GetTransformData(stream, TransformDataPointer, indices.TranslationXIndex),
                        GetTransformData(stream, TransformDataPointer, indices.TranslationYIndex),
                        GetTransformData(stream, TransformDataPointer, indices.TranslationZIndex),
                        GetTransformData(stream, TransformDataPointer, indices.RotationXIndex),
                        GetTransformData(stream, TransformDataPointer, indices.RotationYIndex),
                        GetTransformData(stream, TransformDataPointer, indices.RotationZIndex),
                        GetTransformData(stream, TransformDataPointer, indices.ScaleXIndex),
                        GetTransformData(stream, TransformDataPointer, indices.ScaleYIndex),
                        GetTransformData(stream, TransformDataPointer, indices.ScaleZIndex));

                    nodeTransforms[i][j] = nodeTransform;
                }
            }

            primitiveMeshes = new Dictionary <Primitive, Mesh>();
        }
예제 #2
0
        private TransformIndices GetTransformIndices(Stream stream, uint pointer, uint indicesIndex)
        {
            long lastPosition = stream.Position;

            stream.Seek(pointer + (indicesIndex * 0x28), SeekOrigin.Begin);

            TransformIndices indices = new TransformIndices(stream);

            stream.Position = lastPosition;
            return(indices);
        }