//---------------------------------------------------------------------------- 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); }
static public WorldcraftSidePlane FromTokenReader(TokenReader tr, Textures textures) { WorldcraftSidePlane sp = new WorldcraftSidePlane(); Debug.Assert(tr.LookAhead == "("); tr.GetToken(); Vector3D pt1 = ReadVector3D(tr); Debug.Assert(tr.LookAhead == ")"); tr.GetToken(); Debug.Assert(tr.LookAhead == "("); tr.GetToken(); Vector3D pt2 = ReadVector3D(tr); Debug.Assert(tr.LookAhead == ")"); tr.GetToken(); Debug.Assert(tr.LookAhead == "("); tr.GetToken(); Vector3D pt3 = ReadVector3D(tr); Debug.Assert(tr.LookAhead == ")"); tr.GetToken(); sp.plane = Plane3D.FromCoplanarPoints(pt2, pt1, pt3); sp.plane.Flip(); //Debug.Assert( sp.plane != null ); sp.texture = textures.RequestTexture(tr.GetToken()); Debug.Assert(sp.texture != null); if (sp.texture.IsBitmapLoaded == false) { sp.texture.LoadBitmap(); } Debug.Assert(tr.LookAhead == "["); tr.GetToken(); Vector3D sAxis = ReadVector3D(tr); float sOffset = float.Parse(tr.GetToken()); Debug.Assert(tr.LookAhead == "]"); tr.GetToken(); Debug.Assert(tr.LookAhead == "["); tr.GetToken(); Vector3D tAxis = ReadVector3D(tr); float tOffset = float.Parse(tr.GetToken()); Debug.Assert(tr.LookAhead == "]"); tr.GetToken(); Vector3D rAxis = Vector3D.Cross(sAxis, tAxis); float rotation = float.Parse(tr.GetToken()); float sScale = float.Parse(tr.GetToken()); float tScale = float.Parse(tr.GetToken()); Matrix3D xfrm = new Matrix3D(); //xfrm.Scale( sScale, tScale, 1 ); //xfrm.Translate( -sOffset, -tOffset, 0 ); sp.sAxis = sAxis; sp.tAxis = tAxis; //xfrm.ChangeBasis( sAxis, tAxis, rAxis ); //xfrm.Scale( sp.texture.Width, sp.texture.Height, 1 ); //xfrm.Invert(); //sp.xfrm = xfrm; return(sp); }
public bool Contains(WorldcraftSidePlane sp) { return(_arraylist.Contains(sp)); }
public void Remove(WorldcraftSidePlane sp) { _arraylist.Remove(sp); }
public int Add(WorldcraftSidePlane sp) { return(_arraylist.Add(sp)); }