public BuildingObjectLib3DS CreateBuildingModel()
        {
            BuildingObjectLib3DS Building;
            Hashtable            Textures  = new Hashtable();
            Lib3dsMesh           test      = new Lib3dsMesh();
            OpenGLControl        openglCtr = new SharpGL.OpenGLControl();

            foreach (Lib3dsMaterial material in MyModel.materials)
            {
                Texture texture = new Texture();
                try
                {
                    texture.Create(openglCtr.OpenGL, "..\\Model\\" + material.name + ".jpg");
                    Textures.Add(material.name, texture);
                }
                catch
                {
                    // Do not find the texture file
                }
            }

            Building = new BuildingObjectLib3DS(null, BuildingObjectType.Building, 0,
                                                MyModel, Textures);

            foreach (Lib3dsMeshInstanceNode node in MyModel.nodes)
            {
                if (node.type != Lib3dsNodeType.LIB3DS_NODE_MESH_INSTANCE || node.childs == null)
                {
                    continue;
                }
                Building.AddNewChild(node);
            }

            return(Building);
        }
        public BuildingObjectLib3DS CreateBuildingModel()
        {
            BuildingObjectLib3DS Building;
            Hashtable Textures = new Hashtable();
            Lib3dsMesh test = new Lib3dsMesh();
            OpenGLControl openglCtr = new SharpGL.OpenGLControl();

            foreach (Lib3dsMaterial material in MyModel.materials)
            {
                Texture texture = new Texture();
                try
                {
                    texture.Create(openglCtr.OpenGL, "..\\Model\\" + material.name + ".jpg");
                    Textures.Add(material.name, texture);
                }
                catch
                {
                    // Do not find the texture file
                }
            }

            Building = new BuildingObjectLib3DS(null, BuildingObjectType.Building, 0,
                MyModel, Textures);

            foreach (Lib3dsMeshInstanceNode node in MyModel.nodes)
            {
                if (node.type != Lib3dsNodeType.LIB3DS_NODE_MESH_INSTANCE || node.childs == null)
                    continue;
                Building.AddNewChild(node);
            }

            return Building;
        }
        /// <summary>
        /// Insert a new child into this object.
        /// </summary>
        /// <param name="newObj">New child</param>
        public void AddNewChild(Lib3dsMeshInstanceNode newObj)
        {
            string[] newObjectLoca = null;

            // Return if location info is illegal
            if ((newObjectLoca = GetLocation(newObj.name)) == null)
            {
                return;
            }

            switch (this.Type)
            {
            case BuildingObjectType.Building:
                if (this.Childs.Contains(newObjectLoca[0]) == false)
                {
                    BuildingObjectType childType;
                    if (newObjectLoca[0] == "0")
                    {
                        childType = BuildingObjectType.Outside;
                    }
                    else
                    {
                        childType = BuildingObjectType.Floor;
                    }

                    BuildingObjectLib3DS bObj = new BuildingObjectLib3DS(this, childType,
                                                                         (uint)System.Convert.ToInt32(newObjectLoca[0]), Model, Textures);
                    this.Childs.Add(newObjectLoca[0], bObj);
                    bObj.AddNewChild(newObj);
                }
                else
                {
                    (this.Childs[(newObjectLoca[0])] as BuildingObjectLib3DS).AddNewChild(newObj);
                }
                break;

            case BuildingObjectType.Floor:
                if (this.Childs.Contains(newObjectLoca[1]) == false)
                {
                    BuildingObjectLib3DS bObj = new BuildingObjectLib3DS(this, BuildingObjectType.Room,
                                                                         (uint)System.Convert.ToInt32(newObjectLoca[1]), Model, Textures);
                    this.Childs.Add(newObjectLoca[1], bObj);
                    bObj.AddNewChild(newObj);
                }
                else
                {
                    (this.Childs[(newObjectLoca[1])] as BuildingObjectLib3DS).AddNewChild(newObj);
                }
                break;

            case BuildingObjectType.Room:
                if (this.Childs.Contains(newObjectLoca[2]) == false)
                {
                    BuildingObjectLib3DS bObj = new BuildingObjectLib3DS(this, BuildingObjectType.Object,
                                                                         (uint)System.Convert.ToInt32(newObjectLoca[2]), Model, Textures);
                    this.Childs.Add(newObjectLoca[2], bObj);
                    bObj.AddNewChild(newObj);
                }
                else
                {
                    // Same Name... ??? Do not insert it...
                }
                break;

            case BuildingObjectType.Outside:
            case BuildingObjectType.Object:
                this.Object = newObj;
                //if (this.Object.childs.Count == 0)
                //{
                //    Lib3dsMesh ThisMesh = FindLib3dsMeshByName(this.Object.name, this.Model.meshes);
                //    if (ThisMesh != null)
                //    {
                //        this.Normalizes = new Lib3dsVertex[1][];
                //        this.Normalizes[0] = new Lib3dsVertex[ThisMesh.faces.Count];
                //        for (int i = 0; i < ThisMesh.faces.Count; i++)
                //        {
                //            Lib3dsFace face = ThisMesh.faces[i];
                //            Lib3dsVertex Point1 = ThisMesh.vertices[face.index[0]];
                //            Lib3dsVertex Point2 = ThisMesh.vertices[face.index[1]];
                //            Lib3dsVertex Point3 = ThisMesh.vertices[face.index[2]];
                //            this.Normalizes[0][i] = CreateNormalize(Point1, Point2, Point3);
                //        }
                //    }
                //}
                //else
                //{
                //    this.Normalizes = new Lib3dsVertex[newObj.childs.Count][];
                //    int cnt = 0;
                //    foreach (Lib3dsNode node in newObj.childs)
                //    {
                //        Lib3dsMesh ThisMesh = FindLib3dsMeshByName(node.name, this.Model.meshes);
                //        if (ThisMesh == null)
                //        {
                //            continue;
                //        }

                //        this.Normalizes[cnt] = new Lib3dsVertex[ThisMesh.faces.Count];

                //        for (int i = 0; i < ThisMesh.faces.Count; i++)
                //        {
                //            Lib3dsFace face = ThisMesh.faces[i];
                //            Lib3dsVertex Point1 = ThisMesh.vertices[face.index[0]];
                //            Lib3dsVertex Point2 = ThisMesh.vertices[face.index[1]];
                //            Lib3dsVertex Point3 = ThisMesh.vertices[face.index[2]];
                //            this.Normalizes[cnt][i] = CreateNormalize(Point1, Point2, Point3);
                //        }
                //        cnt++;
                //    }
                //}
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Insert a new child into this object.
        /// </summary>
        /// <param name="newObj">New child</param>
        public void AddNewChild(Lib3dsMeshInstanceNode newObj)
        {
            string[] newObjectLoca = null;

            // Return if location info is illegal
            if ((newObjectLoca = GetLocation(newObj.name)) == null)
                return;

            switch (this.Type)
            {
                case BuildingObjectType.Building:
                    if (this.Childs.Contains(newObjectLoca[0]) == false)
                    {
                        BuildingObjectType childType;
                        if (newObjectLoca[0] == "0")
                        {
                            childType = BuildingObjectType.Outside;
                        }
                        else
                        {
                            childType = BuildingObjectType.Floor;
                        }

                        BuildingObjectLib3DS bObj = new BuildingObjectLib3DS(this, childType,
                            (uint)System.Convert.ToInt32(newObjectLoca[0]), Model, Textures);
                        this.Childs.Add(newObjectLoca[0], bObj);
                        bObj.AddNewChild(newObj);
                    }
                    else
                    {
                        (this.Childs[(newObjectLoca[0])] as BuildingObjectLib3DS).AddNewChild(newObj);
                    }
                    break;
                case BuildingObjectType.Floor:
                    if (this.Childs.Contains(newObjectLoca[1]) == false)
                    {
                        BuildingObjectLib3DS bObj = new BuildingObjectLib3DS(this, BuildingObjectType.Room,
                            (uint)System.Convert.ToInt32(newObjectLoca[1]), Model, Textures);
                        this.Childs.Add(newObjectLoca[1], bObj);
                        bObj.AddNewChild(newObj);
                    }
                    else
                    {
                        (this.Childs[(newObjectLoca[1])] as BuildingObjectLib3DS).AddNewChild(newObj);
                    }
                    break;
                case BuildingObjectType.Room:
                    if (this.Childs.Contains(newObjectLoca[2]) == false)
                    {
                        BuildingObjectLib3DS bObj = new BuildingObjectLib3DS(this, BuildingObjectType.Object,
                            (uint)System.Convert.ToInt32(newObjectLoca[2]), Model, Textures);
                        this.Childs.Add(newObjectLoca[2], bObj);
                        bObj.AddNewChild(newObj);
                    }
                    else
                    {
                        // Same Name... ??? Do not insert it...
                    }
                    break;
                case BuildingObjectType.Outside:
                case BuildingObjectType.Object:
                    this.Object = newObj;
                    //if (this.Object.childs.Count == 0)
                    //{
                    //    Lib3dsMesh ThisMesh = FindLib3dsMeshByName(this.Object.name, this.Model.meshes);
                    //    if (ThisMesh != null)
                    //    {
                    //        this.Normalizes = new Lib3dsVertex[1][];
                    //        this.Normalizes[0] = new Lib3dsVertex[ThisMesh.faces.Count];
                    //        for (int i = 0; i < ThisMesh.faces.Count; i++)
                    //        {
                    //            Lib3dsFace face = ThisMesh.faces[i];
                    //            Lib3dsVertex Point1 = ThisMesh.vertices[face.index[0]];
                    //            Lib3dsVertex Point2 = ThisMesh.vertices[face.index[1]];
                    //            Lib3dsVertex Point3 = ThisMesh.vertices[face.index[2]];
                    //            this.Normalizes[0][i] = CreateNormalize(Point1, Point2, Point3);
                    //        }
                    //    }
                    //}
                    //else
                    //{
                    //    this.Normalizes = new Lib3dsVertex[newObj.childs.Count][];
                    //    int cnt = 0;
                    //    foreach (Lib3dsNode node in newObj.childs)
                    //    {
                    //        Lib3dsMesh ThisMesh = FindLib3dsMeshByName(node.name, this.Model.meshes);
                    //        if (ThisMesh == null)
                    //        {
                    //            continue;
                    //        }

                    //        this.Normalizes[cnt] = new Lib3dsVertex[ThisMesh.faces.Count];

                    //        for (int i = 0; i < ThisMesh.faces.Count; i++)
                    //        {
                    //            Lib3dsFace face = ThisMesh.faces[i];
                    //            Lib3dsVertex Point1 = ThisMesh.vertices[face.index[0]];
                    //            Lib3dsVertex Point2 = ThisMesh.vertices[face.index[1]];
                    //            Lib3dsVertex Point3 = ThisMesh.vertices[face.index[2]];
                    //            this.Normalizes[cnt][i] = CreateNormalize(Point1, Point2, Point3);
                    //        }
                    //        cnt++;
                    //    }
                    //}
                    break;
                default:
                    break;
            }
        }