コード例 #1
0
ファイル: Forest.cs プロジェクト: Phylliida/WorldSeed
        public static void GrowNewBranches(ParallelQuery <Module> allModules)
        {
            // SelectMany will join all of the new modules returned by each module (if any) into a single list
            allModules.SelectMany(module =>
            {
                return(module.nodes
                       // Grow module off of it if not grown and vigor is greater than vigorRootMins
                       .Where(node => node.main == null && node.lateral == null && node.v > module.plant.plantConfig.vigorRootMin)
                       .Select(node =>
                {
                    UnityEngine.Debug.Log("Growing new branch at pos " + Node.GetGlobalPos(node));
                    float lambda = module.plant.plantConfig.lambda;
                    float dPrime = module.root.v * module.plant.plantConfig.D / module.plant.plantConfig.vigorRootMax;

                    ModulePrototype closestPrototype = PlantConfig.ClosestPrototype(module.plant.plantConfig, lambda, dPrime);
                    Module newModule = ModulePrototype.CreateInstance(module.plant, closestPrototype, Node.GetPose(node));
                    node.main = newModule.root;     // connect main to root so the trickle of q and v can work properly
                    newModule.root.parent = node.main;
                    return newModule;
                }));
            })
            // Do last piece not in parallel, since we are appending to lists that is not thread safe
            .ToList()
            .ForEach(newModule =>
            {
                newModule.plant.modules.Add(newModule);
            });
        }
コード例 #2
0
        public static void DrawConnectionsOut(Node node)
        {
            Vector3 myPos = Node.GetGlobalPos(node);

            if (node.main != null)
            {
                GL.Vertex(myPos);
                GL.Vertex(Node.GetGlobalPos(node.main));
                DrawConnectionsOut(node.main);
            }
            if (node.lateral != null)
            {
                GL.Vertex(myPos);
                GL.Vertex(Node.GetGlobalPos(node.lateral));
                DrawConnectionsOut(node.lateral);
            }
        }