public TreeProfile(GraphicsDevice device, TreeGenerator generator, Texture2D trunkTexture, Texture2D leafTexture, Effect trunkEffect, Effect leafEffect)
 {
     GraphicsDevice = device;
     Generator = generator;
     TrunkTexture = trunkTexture;
     LeafTexture = leafTexture;
     TrunkEffect = trunkEffect;
     LeafEffect = leafEffect;
 }
 public TreeProfile(GraphicsDevice device, TreeGenerator generator, Texture2D trunkTexture, Texture2D leafTexture, Effect trunkEffect, Effect leafEffect)
 {
     GraphicsDevice = device;
     Generator      = generator;
     TrunkTexture   = trunkTexture;
     LeafTexture    = leafTexture;
     TrunkEffect    = trunkEffect;
     LeafEffect     = leafEffect;
 }
Example #3
0
        /// <summary>
        /// Creates a tree generator from a specified XML document.
        /// </summary>
        /// <param name="document">The XML document to parse.</param>
        /// <returns>A new tree generator.</returns>
        /// <exception cref="ArgumentException">If the XML document is not a valid tree specification.</exception>
        public static TreeGenerator CreateFromXml(XmlDocument document)
        {
            TreeGenerator generator  = new TreeGenerator();
            string        rootName   = null;
            int           levels     = -1;
            int           boneLevels = 3;
            MultiMap <string, ProductionNodePair> productions = new MultiMap <string, ProductionNodePair>();

            XmlNode root = document.SelectSingleNode("Tree");

            foreach (XmlNode child in root.ChildNodes)
            {
                switch (child.Name)
                {
                case "Root":
                    rootName = XmlUtil.GetString(child, "ref");
                    break;

                case "Levels":
                    levels = XmlUtil.GetInt(child, "value");
                    break;

                case "BoneLevels":
                    boneLevels = XmlUtil.GetInt(child, "value");
                    break;

                case "LeafAxis":
                    generator.LeafAxis = XmlUtil.GetVector3(child, "value");
                    generator.LeafAxis.Value.Normalize();
                    break;

                case "Production":
                    string name = XmlUtil.GetString(child, "id");
                    productions.Add(name, new ProductionNodePair(new Production(), child));
                    break;

                case "ConstrainUnderground":
                    generator.Constraints.Constaints.Add(new ConstrainUndergroundBranches(XmlUtil.GetFloat(child, "lowerBound", 256.0f)));
                    break;

                case "TextureHeight":
                    generator.TextureHeight          = XmlUtil.GetFloat(child, "height");
                    generator.TextureHeightVariation = XmlUtil.GetFloat(child, "variation", 0.0f);
                    break;
                }
            }

            if (rootName == null)
            {
                throw new ArgumentException("Root name must be specified.");
            }

            // Now we have a map of names -> productions, so we can start parsing the the productions
            foreach (ProductionNodePair pn in productions.Values)
            {
                ParseInstructionsFromXml(pn.Node, pn.Production.Instructions, productions);
            }

            generator.Root       = productions[rootName][0].Production;
            generator.MaxLevel   = levels;
            generator.BoneLevels = boneLevels;

            return(generator);
        }
        /// <summary>
        /// Creates a tree generator from a specified XML document.
        /// </summary>
        /// <param name="document">The XML document to parse.</param>
        /// <returns>A new tree generator.</returns>
        /// <exception cref="ArgumentException">If the XML document is not a valid tree specification.</exception>
        public static TreeGenerator CreateFromXml(XmlDocument document)
        {
            var generator = new TreeGenerator();
            string rootName = null;
            int levels = -1;
            int boneLevels = 3;
            var productions = new MultiMap<string, ProductionNodePair>();

            XmlNode root = document.SelectSingleNode("Tree");

            foreach (XmlNode child in root.ChildNodes)
            {
                switch (child.Name)
                {
                    case "Root":
                        rootName = XmlUtil.GetString(child, "ref");
                        break;

                    case "Levels":
                        levels = XmlUtil.GetInt(child, "value");
                        break;

                    case "BoneLevels":
                        boneLevels = XmlUtil.GetInt(child, "value");
                        break;

                    case "LeafAxis":
                        generator.LeafAxis = XmlUtil.GetVector3(child, "value");
                        generator.LeafAxis.Value.Normalize();
                        break;

                    case "Production":
                        string name = XmlUtil.GetString(child, "id");
                        productions.Add(name, new ProductionNodePair(new Production(), child));
                        break;

                    case "ConstrainUnderground":
                        generator.Constraints.Constaints.Add(
                            new ConstrainUndergroundBranches(XmlUtil.GetFloat(child, "lowerBound", 256.0f)));
                        break;

                    case "TextureHeight":
                        generator.TextureHeight = XmlUtil.GetFloat(child, "height");
                        generator.TextureHeightVariation = XmlUtil.GetFloat(child, "variation", 0.0f);
                        break;
                }
            }

            if (rootName == null)
                throw new ArgumentException("Root name must be specified.");

            // Now we have a map of names -> productions, so we can start parsing the the productions
            foreach (ProductionNodePair pn in productions.Values)
            {
                ParseInstructionsFromXml(pn.Node, pn.Production.Instructions, productions);
            }

            generator.Root = productions[rootName][0].Production;
            generator.MaxLevel = levels;
            generator.BoneLevels = boneLevels;

            return generator;
        }