示例#1
0
        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);
        }
示例#2
0
        static void CreateX3DMaterial(ref X3DMaterial material, XElement element)
        {
            string gmlString = "http://www.opengis.net/gml";
            string appString = "http://www.opengis.net/citygml/appearance/2.0";

            material.gmlID = element.FirstAttribute.Value;
            foreach (var child in element.Elements())
            {
                if (child.Name == XName.Get("name", gmlString))
                {
                    material.name = child.Value;
                    continue;
                }
                if (child.Name == XName.Get("ambientIntensity", appString))
                {
                    material.ambientIntensity = double.Parse(child.Value);
                    try
                    {
                        material.ambientIntensity = double.Parse(child.Value);
                    }catch (Exception e)
                    {
                        material.ambientIntensity = 0.2; //0.2 is the default ambient intensity value
                    }
                    continue;
                }
                if (child.Name == XName.Get("diffuseColor", appString))
                {
                    var vals = child.Value.Split(' ');
                    material.diffuseColor = ParseColorValue(vals);
                    continue;
                }
                if (child.Name == XName.Get("emissiveColor", appString))
                {
                    var vals = child.Value.Split(' ');
                    material.emissiveColor = ParseColorValue(vals);
                    continue;
                }
                if (child.Name == XName.Get("specularColor", appString))
                {
                    var vals = child.Value.Split(' ');
                    material.specularColor = ParseColorValue(vals);
                    continue;
                }
                if (child.Name == XName.Get("shininess", appString))
                {
                    material.shininess = double.Parse(child.Value);
                    continue;
                }
                if (child.Name == XName.Get("transparency", appString))
                {
                    material.transparency = double.Parse(child.Value);
                    continue;
                }
                if (child.Name == XName.Get("target", appString))
                {
                    string target = child.Value;
                    target          = target.Substring(1, target.Length - 1);
                    material.target = target;
                    continue;
                }
            }
        }