Beispiel #1
0
        //----------------------------------------------------------------------------

        static public WorldcraftObject FromTokenReader(TokenReader tr, Textures textures)
        {
            WorldcraftObject wo = new WorldcraftObject();

            Debug.Assert(tr.LookAhead == "{");
            tr.GetToken();

            while (tr.LookAhead != null && tr.LookAhead != "}")
            {
                if (tr.LookAhead == "{")
                {
                    tr.GetToken();
                    WorldcraftSidePlanes sidePlanes = new WorldcraftSidePlanes();
                    while (tr.LookAhead != null && tr.LookAhead == "(")
                    {
                        sidePlanes.Add(WorldcraftSidePlane.FromTokenReader(tr, textures));
                    }
                    wo.Faces.AddRange(ConvertSidePlanesToFaces(wo, sidePlanes, textures));

                    Debug.Assert(tr.LookAhead == "}");
                    tr.GetToken();
                }
                else
                {
                    string key = tr.GetToken();
                    string val = tr.GetToken();
                    if (wo._properties.Contains(key) == false)
                    {
                        wo._properties.Add(key, val);
                    }
                }
            }

            Debug.Assert(tr.LookAhead != null);
            tr.GetToken();

            Debug.Assert(wo.ClassName != null);

            /*Color clrMaterial = wo.MaterialColor;
             * foreach( Face face in wo.Faces ) {
             *      face.Color = clrMaterial;
             * }*/

            return(wo);
        }
Beispiel #2
0
        static protected Faces ConvertSidePlanesToFaces(WorldcraftObject wo, WorldcraftSidePlanes sidePlanes, Textures textures)
        {
            Faces faces = new Faces();

            for (int i = 0; i < sidePlanes.Count; i++)
            {
                //Consider this side plane and it's associated heavily used parts.
                WorldcraftSidePlane sp = sidePlanes[i];

                Polygon3D polygon = sp.plane.CreatePolygon(10000);
                if (Vector3D.Dot(polygon.GetNormal(), sp.plane.Normal) > 0)
                {
                    polygon.Flip();
                }
                CutPolygonByPlanes(polygon, sidePlanes, i);

                if (polygon.Points.Count >= 3)
                {
                    Face face = new Face();
                    face.Texture   = sp.texture;
                    face.SAxis     = sp.sAxis;
                    face.TAxis     = sp.tAxis;
                    face.Plane     = sp.plane.GetFlipped();
                    face.GroupName = wo.ClassName;

                    foreach (Vector3D pt in polygon.Points)
                    {
                        face.Points.Add(face.Plane.ProjectOntoPlane(pt));
                    }

                    faces.Add(face);
                }
            }

            return(faces);
        }
Beispiel #3
0
        static public WorldcraftMap  FromFile(string strFileName, string strTexturePath)
        {
            //Debug2.Push( "Reading Worldcraft Map" );

            WorldcraftMap wm = new WorldcraftMap();

            wm.FileName = strFileName;
            //wm.Textures.DefaultPath			= strTexturePath;
            //wm.Textures.DefaultExtension	= ".bmp";

//			progressTracker.UpdateProgress( 20 );
//			progressTracker.UpdateTask( "Parsing worldcraft map: '" + strFileName + "'..." );

            TokenReader tr = new TokenReader(strFileName, ' ');

            int faceCount = 0;

            while (tr.LookAhead != null && tr.LookAhead == "{")
            {
                WorldcraftObject wo = WorldcraftObject.FromTokenReader(tr, wm.Textures);
                faceCount += wo.Faces.Count;
                wm.Objects.Add(wo);
            }

            tr.Close();

            //Thread.Sleep( 200 );

//			progressTracker.UpdateTask( "      worldcraft objects: " + wm.Objects.Count );
//			progressTracker.UpdateTask( "      totals faces count: " + faceCount );
//			progressTracker.UpdateTask( "      # of textures in use: " + wm.Textures.Count );

            //Debug2.Pop();

            return(wm);
        }
Beispiel #4
0
 public virtual void Add(WorldcraftObject o)
 {
     this.List.Add(o);
 }