Beispiel #1
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(bool reset, bool go, bool debug, List <System.Object> P, List <System.Object> V, double curlNoiseScale, double curlNoiseTime, double simNoiseScale, double simNoiseTime, double isoValue, double isoValueTol, double planeRadius, double searchRadius, double cInt, double aInt, double sInt, double fieldInt, double isoVInt, double maxForce, ref object Planes, ref object neigh)
    {
        // <Custom code>

        // align planes with field/neighbours - C#
        // code by Alessio Erioli - (c) Co-de-iT 2019

        if (P == null || V == null || P.Count != V.Count)
        {
            return;
        }

        if (reset || aPS == null)
        {
            // Casting P and V to Point3d and Vector3d Lists
            List <Point3d>  pList = new List <Point3d>();
            List <Vector3d> vList = new List <Vector3d>();
            for (int i = 0; i < P.Count; i++)
            {
                pList.Add((Point3d)P[i]);
                vList.Add((Vector3d)V[i]);
            }

            // passing the essential parameters to the new simulation
            aPS = new AgentPlaneSimulation(pList, vList);
        }

        if (go)
        {
            // update parameters
            aPS.curlNoiseScale      = curlNoiseScale;
            aPS.curlNoiseTime       = curlNoiseTime;
            aPS.simplexNoiseScale   = (float)simNoiseScale;
            aPS.simplexNoiseTime    = (float)simNoiseTime;
            aPS.isoValue            = (float)isoValue;
            aPS.isoValueTol         = (float)isoValueTol;
            aPS.planeRadius         = planeRadius;
            aPS.searchRadius        = searchRadius;
            aPS.cohesionIntensity   = cInt;
            aPS.alignmentIntensity  = aInt;
            aPS.separationIntensity = sInt;
            aPS.fieldIntensity      = fieldInt;
            aPS.isoValIntensity     = isoVInt;
            aPS.maxForce            = maxForce;

            // run simulation
            aPS.Update();
            Component.ExpireSolution(true);
        }

        // extract output geometries
        Planes = aPS.ExtractPlanes();
        if (debug)
        {
            neigh = aPS.ExtractNeighbours();
        }
        // </Custom code>
    }
Beispiel #2
0
 // constructor
 public AgentPlane(Point3d O, Vector3d dirX, AgentPlaneSimulation agentSim)
 {
     this.O = O;
     dirX.Unitize();
     this.X        = dirX;
     this.agentSim = agentSim;
     neighbours    = new List <Point3d>();
     neighTens     = new List <TensorPoint>();
 }
Beispiel #3
0
        // constructor
        public AgentPlane(Point3d O, Vector3d X, AgentPlaneSimulation agentSim)
        {
            this.O = O;
            X.Unitize();
            this.X        = X;
            this.agentSim = agentSim;
            Vector3d oV = new Vector3d(O);

            oV.Unitize();
            Y          = Vector3d.CrossProduct(X, oV);
            neighbours = new List <AgentPlane>();
        }
Beispiel #4
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(bool reset, bool go, List <Point3d> P, List <Vector3d> V, Mesh Ms, Mesh Mv, double pR, double nR, double cS, double aS, double sS, double fS, double meR, double meS, double coS, double mF, ref object Planes, ref object MeshPlanes)
    {
        // <Custom code>

        // align planes with mesh field - C#
        // code by Alessio Erioli - (c) Co-de-iT 2019
        //  implementations:
        //  . fixed pts and dirs (for future modularization of the process over larger number of units
        //  . field as static set of pts and vectors (RTree searchable)


        if (P == null || P.Count == 0)
        {
            return;
        }

        if (reset || aPS == null)
        {
            // passing the essential parameters to the new simulation
            aPS          = new AgentPlaneSimulation(P, V);
            MEnvironment = Ms;
            MeshRTree    = RTreeFromMesh(Ms);
            TensorField  = TensorFieldFromMeshes(Ms, Mv);
            // initializing arrays for export
            gP = new GH_Plane[aPS.agentPlanes.Length];
            gM = new GH_Mesh[aPS.agentPlanes.Length];
        }

        if (go)
        {
            // update parameters
            aPS.PlaneRadius        = pR;
            aPS.NeighborhoodRadius = nR;
            aPS.CohesionStrength   = cS;
            aPS.AlignmentStrength  = aS;
            aPS.SeparationStrength = sS;
            aPS.FieldStrength      = fS;
            aPS.MeshSeekRadius     = meR;
            aPS.MeshStrength       = meS;
            aPS.SeekColorStrength  = coS;
            aPS.MaxForce           = mF;

            // run simulation
            aPS.Update();

            Component.ExpireSolution(true);
        }

        // extract output geometries and information

        Parallel.For(0, aPS.agentPlanes.Length, i =>
        {
            // extract planes
            gP[i] = new GH_Plane(aPS.agentPlanes[i].PlaneOut());
        });


        Planes = gP;

        // </Custom code>
    }