Object3d ProcessObjectChunk(ThreeDSChunk chunk, Object3d e)
        {
            while (chunk.BytesRead < chunk.Length)
            {
                ThreeDSChunk child = new ThreeDSChunk(reader);

                switch ((Groups)child.ID)
                {
                case Groups.C_OBJECT_MESH:

                    ProcessObjectChunk(child, e);
                    break;

                case Groups.C_OBJECT_VERTICES:

                    //e.vertices = ReadVertices(child);
                    e.m_lstpoints = ReadVertices(child);
                    break;

                case Groups.C_OBJECT_FACES:

                    //e.indices =
                    Triangle [] tris = ReadIndices(child);
                    foreach (Triangle t in tris)
                    {
                        Polygon p = new Polygon();
                        p.m_points    = new Point3d[3];
                        p.m_points[0] = (Point3d)e.m_lstpoints[t.vertex1];
                        p.m_points[1] = (Point3d)e.m_lstpoints[t.vertex2];
                        p.m_points[2] = (Point3d)e.m_lstpoints[t.vertex3];
                        e.m_lstpolys.Add(p);
                    }
                    e.Update();
                    if (child.BytesRead < child.Length)
                    {
                        ProcessObjectChunk(child, e);
                    }
                    break;

                case Groups.C_OBJECT_MATERIAL:

                    string name2 = ProcessString(child);
                    Console.WriteLine("	Uses Material: {0}", name2);

                    Material mat;
                    if (materials.TryGetValue(name2, out mat))
                    {
                        e.material = mat;
                    }
                    else
                    {
                        Console.WriteLine(" Warning: Material '{0}' not found. ", name2);
                    }

                    SkipChunk(child);
                    break;

                case Groups.C_OBJECT_UV:

                    int cnt = reader.ReadUInt16();
                    child.BytesRead += 2;

                    Console.WriteLine("	TexCoords: {0}", cnt);
                    //e.texcoords = new TexCoord[cnt];
                    //TexCoord tc = new TexCoord();
                    for (int ii = 0; ii < cnt; ii++)
                    {
                        //should add this to a list somewhere
                        TexCoord tc = new TexCoord(reader.ReadSingle(), reader.ReadSingle());
                    }

                    child.BytesRead += (cnt * (4 * 2));

                    break;

                default:

                    SkipChunk(child);
                    break;
                }
                chunk.BytesRead += child.BytesRead;
                //Console.WriteLine ( "	ID: {0} Length: {1} Read: {2}", chunk.ID.ToString("x"), chunk.Length , chunk.BytesRead );
            }
            return(e);
        }
        Object3d ProcessObjectChunk(ThreeDSChunk chunk, Object3d e)
        {
            while (chunk.BytesRead < chunk.Length)
            {
                ThreeDSChunk child = new ThreeDSChunk(reader);

                switch ((Groups)child.ID)
                {
                    case Groups.C_OBJECT_MESH:

                        ProcessObjectChunk(child, e);
                        break;

                    case Groups.C_OBJECT_VERTICES:

                        //e.vertices = ReadVertices(child);
                        e.m_lstpoints = ReadVertices(child);
                        break;

                    case Groups.C_OBJECT_FACES:

                        //e.indices =
                        Triangle []tris = ReadIndices(child);
                        foreach (Triangle t in tris)
                        {
                            Polygon p = new Polygon();
                            p.m_points = new Point3d[3];
                            p.m_points[0] = (Point3d)e.m_lstpoints[t.vertex1];
                            p.m_points[1] = (Point3d)e.m_lstpoints[t.vertex2];
                            p.m_points[2] = (Point3d)e.m_lstpoints[t.vertex3];
                            e.m_lstpolys.Add(p);
                        }
                        e.Update();
                        if (child.BytesRead < child.Length)
                            ProcessObjectChunk(child, e);
                        break;

                    case Groups.C_OBJECT_MATERIAL:

                        string name2 = ProcessString(child);
                        Console.WriteLine("	Uses Material: {0}", name2);

                        Material mat;
                        if (materials.TryGetValue(name2, out mat))
                            e.material = mat;
                        else
                            Console.WriteLine(" Warning: Material '{0}' not found. ", name2);

                        SkipChunk(child);
                        break;

                    case Groups.C_OBJECT_UV:

                        int cnt = reader.ReadUInt16();
                        child.BytesRead += 2;

                        Console.WriteLine("	TexCoords: {0}", cnt);
                        //e.texcoords = new TexCoord[cnt];
                        //TexCoord tc = new TexCoord();
                        for (int ii = 0; ii < cnt; ii++)
                        {
                            //should add this to a list somewhere
                            TexCoord tc = new TexCoord(reader.ReadSingle(), reader.ReadSingle());
                        }

                        child.BytesRead += (cnt * (4 * 2));

                        break;

                    default:

                        SkipChunk(child);
                        break;

                }
                chunk.BytesRead += child.BytesRead;
                //Console.WriteLine ( "	ID: {0} Length: {1} Read: {2}", chunk.ID.ToString("x"), chunk.Length , chunk.BytesRead );
            }
            return e;
        }