示例#1
0
 public Particle(float a, float b, float f, float k, Vector3 dir, float dirF, float v, float dB,
                 Vector3 point, ReactionDiffusion reacc)
 {
     this.A        = a;
     this.B        = b;
     this.f        = f;
     this.k        = k;
     this._dir     = dir;
     this._dirF    = dirF;
     this.v        = v;
     this.dB       = dB;
     this._point   = point;
     this.reaction = reacc;
 }
示例#2
0
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(
        Mesh mesh,
        List <Vector3> dir,
        List <float> dirF,
        List <float> v,
        List <float> dB,
        List <float> feed,
        List <float> kill,
        List <int> seedA,
        List <int> seedB,
        int iter)
    {
        //Written by Vicente Soler and changed by Laurent Delrieu
        //http://www.grasshopper3d.com/forum/topics/reaction-diffusion-on-triangular-mesh
        //29th of August 2015
        //Adapted by Bathsheba Grossman February 2019 to take more general inputs and use Alea to compute on the GPU.

        if (mesh == null)
        {
            Debug.Log("No mesh");
            return;
        }

        //Validate inputs: supply reasonable defaults for nulls and check # of values.  No range checks.
        var size = mesh.vertexCount;

        if (dir.Count == 0 || dirF.Count == 0)
        {
            //direction vector and weight
            dirF = new List <float> {
                1.0f
            };
            dir = new List <Vector3> {
                new Vector3(1, 0, 0)
            };
        }
        else
        {
            if (!CheckLen <Vector3>(dir, "dir", size))
            {
                return;
            }
        }

        if (v.Count == 0)
        {
            v = new List <float> {
                1.0f
            }
        }
        ;                                              //slows diffusion => shrinks scale 0-1
        if (dB.Count == 0)
        {
            dB = new List <float> {
                0.5f
            }
        }
        ;                                                //diffusion of B relative to A, always < 1

        if (feed.Count == 0)
        {
            feed = new List <float> {
                0.055f
            }
        }
        ;
        if (kill.Count == 0)
        {
            kill = new List <float> {
                0.062f
            }
        }
        ;

        if (seedA.Count == 0)
        {
            seedA = new List <int> {
                1
            }
        }
        ;                                                 //default A seeds all 1

        if (seedB.Count == 0)
        {
            //default B seeds 1/20 1 rest 0
            for (var i = 0; i < size; i++)
            {
                seedB.Add((Random.Range(0, 1) < 0.05) ? 1 : 0);
            }
        }

        if (!CheckLen <float>(dirF, "dirF", size))
        {
            return;
        }
        if (!CheckLen <float>(v, "v", size))
        {
            return;
        }
        if (!CheckLen <float>(dB, "dB", size))
        {
            return;
        }
        if (!CheckLen <float>(feed, "feed", size))
        {
            return;
        }
        if (!CheckLen <float>(kill, "kill", size))
        {
            return;
        }
        if (!CheckLen <float>(seedA, "seedA", size))
        {
            return;
        }
        if (!CheckLen <float>(seedB, "seedB", size))
        {
            return;
        }
        //Done validating

        var t        = DateTime.Now;
        var reaction = new ReactionDiffusion(mesh, dir, dirF, v, dB, feed, kill, seedA, seedB);

        var s = DateTime.Now.Subtract(t);

        Debug.Log("initialize: " + s.ToString());

        t = DateTime.Now;
        reaction.Run(iter);

        s = DateTime.Now.Subtract(t);
        Debug.Log("run: " + s.ToString());

        var A = reaction.ListA;
        var B = reaction.ListB;
    }