static protected void CutPolygonByPlanes(Polygon3D polygon, WorldcraftSidePlanes sidePlanes, int iSkipPlaneIndex) { for (int i = 0; i < sidePlanes.Count; i++) { if (i != iSkipPlaneIndex) { sidePlanes[i].plane.ClipPolygon(polygon); } } }
//---------------------------------------------------------------------------- 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); }
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); }