static List <ISurfaceDataMember> ParseAppearance(XElement node) { List <ISurfaceDataMember> retVal = new List <ISurfaceDataMember>(); string app = "http://www.opengis.net/citygml/appearance/2.0"; XName appearance = XName.Get("Appearance", app); XName surfaceDataMember = XName.Get("surfaceDataMember", app); var child = node.Element(appearance); var surfaceDataMembers = child.Elements(surfaceDataMember); foreach (var sfd in surfaceDataMembers) { var ParameterizedTexture = XName.Get("ParameterizedTexture", app); var X3DMaterial = XName.Get("X3DMaterial", app); var textures = sfd.Elements(ParameterizedTexture); var materials = sfd.Elements(X3DMaterial); foreach (var texture in textures) { ParameterizedTexture gmlTexture = new ParameterizedTexture(texture.FirstAttribute.Value); CreateParamaterizedTexture(ref gmlTexture, texture); retVal.Add(gmlTexture); } foreach (var material in materials) { X3DMaterial mat = new X3DMaterial(material.FirstAttribute.Value); CreateX3DMaterial(ref mat, material); retVal.Add(mat); } } return(retVal); }
private Polygon SideFromTexture(ParameterizedTexture texture) { foreach (Polygon p in sides) { if (p.gmlID == texture.targetURI) { return(p); } } return(null); }
public void CreateSideUVs() { if (sides == null || textures == null) { return; } foreach (var texture in textures) { if (texture.GetType() == typeof(X3DMaterial)) { continue; } ParameterizedTexture param = (ParameterizedTexture)texture; Polygon p = SideFromTexture(param); if (p == null) { continue; } p.uvs = param.textureCoordinates; } }
static void CreateMTLFile(List <ISurfaceDataMember> textures, string path) { using (StreamWriter sw = File.CreateText(path)) { foreach (var tex in textures) { if (tex.GetType() == typeof(X3DMaterial)) { continue; } ParameterizedTexture texture = (ParameterizedTexture)tex; sw.WriteLine("newmtl " + texture.targetURI); sw.WriteLine("illum 0"); //Possible placeholder sw.WriteLine("Ka 1.0 1.0 1.0"); sw.WriteLine("Kd 1.0 1.0 1.0"); sw.WriteLine("Ks 0.0 0.0 0.0"); sw.WriteLine("map_Kd " + texture.imageURI); sw.WriteLine(); } } }
static void CreateParamaterizedTexture(ref ParameterizedTexture texture, XElement element) { string app = "http://www.opengis.net/citygml/appearance/2.0"; foreach (var child in element.Elements()) { if (child.Name == XName.Get("imageURI", app)) { texture.imageURI = child.Value; continue; } if (child.Name == XName.Get("mimeType", app)) { texture.mimeType = child.Value; continue; } if (child.Name == XName.Get("textureType", app)) { texture.textureType = child.Value; continue; } if (child.Name == XName.Get("wrapMode", app)) { texture.wrapMode = child.Value; continue; } if (child.Name == XName.Get("borderColor", app)) { string value = child.Value; var valArray = value.Split(' '); int index = 0; foreach (string s in valArray) { double d = double.Parse(s); texture.borderColor[index] = d; ++index; } continue; } if (child.Name == XName.Get("target", app)) { string target = child.FirstAttribute.Value.Substring(1, child.FirstAttribute.Value.Length - 1); texture.targetURI = target; //We also have to parse out the texture coordinates here. var textCoordList = XName.Get("TexCoordList", app); var tclNode = child.Elements(textCoordList); var textureCoordinates = tclNode.Elements(XName.Get("textureCoordinates", app)); foreach (var t in textureCoordinates) { string value = t.Value; string[] valueArray = value.Split(' '); foreach (string s in valueArray) { double d = double.Parse(s); texture.textureCoordinates.Add(d); } continue; } } } }