コード例 #1
0
        static bool TryGetAttribute(XmlNode node, string attribute, out CapnpGen.CapFilterMode value)
        {
            value = CapnpGen.CapFilterMode.point;

            if (node.Attributes[attribute] == null)
            {
                return(false);
            }

            return(Enum.TryParse <CapnpGen.CapFilterMode>(node.Attributes[attribute].Value, out value));
        }
コード例 #2
0
        public static bool ParseSampler(XmlNode samplerNode, List <CapnpGen.CapSampler> samplers, out string error)
        {
            error = "";
            CapnpGen.CapSampler sampler = new CapnpGen.CapSampler();

            string name = "";

            if (!TryGetAttribute(samplerNode, "name", out name))
            {
                error = "Sampler node does not have a name attribute";
                return(false);
            }
            sampler.Name = name;

            CapnpGen.CapFilterMode filterXY = CapnpGen.CapFilterMode.point;
            if (!TryGetAttribute(samplerNode, "filterXY", out filterXY))
            {
                error = "Sampler node \"" + sampler.Name + "\" does not have a valid filterXY attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapFilterMode));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            sampler.FilterXY = filterXY;

            CapnpGen.CapFilterMode filterZ = CapnpGen.CapFilterMode.point;
            if (!TryGetAttribute(samplerNode, "filterZ", out filterZ))
            {
                error = "Sampler node \"" + sampler.Name + "\" does not have a valid filterZ attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapFilterMode));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            sampler.FilterZ = filterZ;

            CapnpGen.CapWrapMode wrapModeXY = CapnpGen.CapWrapMode.clamp;
            if (!TryGetAttribute(samplerNode, "wrapModeXY", out wrapModeXY))
            {
                error = "Sampler node \"" + sampler.Name + "\" does not have a valid wrapModeXY attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapWrapMode));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            sampler.WrapModeXY = wrapModeXY;

            CapnpGen.CapWrapMode wrapModeZ = CapnpGen.CapWrapMode.clamp;
            if (!TryGetAttribute(samplerNode, "wrapModeZ", out wrapModeZ))
            {
                error = "Sampler node \"" + sampler.Name + "\" does not have a valid wrapModeZ attribute, valid values: ";
                var values = Enum.GetValues(typeof(CapnpGen.CapWrapMode));
                foreach (var value in values)
                {
                    error += value + " ";
                }
                return(false);
            }
            sampler.WrapModeZ = wrapModeZ;

            samplers.Add(sampler);
            return(true);
        }