i think i may have found a bug
I tested multiple ways the tree in VS and inside a class all seems to work fine - there is a reuqired number of branches etc.
but problem appears when i Set it in actual component interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Grasshopper.Kernel;
using Rhino.Geometry;
namespace dynarek.Swarm
{
public class Comp_Swarm : GH_Component
{
private SwarmSystem mySwarm;
public Comp_Swarm()
: base("Swarm", "Swarm",
"Basic Swarm Intelligence",
"Wtyczka_Dynarek", "Swarm")
{
}
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddBooleanParameter("Reset", "Reset", "Reset", GH_ParamAccess.item);
pManager.AddPointParameter("Starting Points", "Starting Points", "Starting Points", GH_ParamAccess.list);
pManager.AddBooleanParameter("Flock", "Flock", "Flock", GH_ParamAccess.item);
pManager.AddBooleanParameter("Trail", "Trail", "Trail", GH_ParamAccess.item);
pManager.AddBooleanParameter("RTree", "RTree", "RTree", GH_ParamAccess.item);
pManager.AddBooleanParameter("Unitize", "Unitize", "Unitize", GH_ParamAccess.item);
// pManager.AddNumberParameter("Random Strength", "Random Strength", "Random Strength", GH_ParamAccess.item);
pManager.AddNumberParameter("Attraction Strength", "Attraction Strength", "Attraction Strength", GH_ParamAccess.item);
pManager.AddNumberParameter("Cohesion Strength", "Cohesion Strength", "Cohesion Strength", GH_ParamAccess.item);
pManager.AddNumberParameter("Repulsion Strength", "Repulsion Strength", "Repulsion Strength", GH_ParamAccess.item);
pManager.AddNumberParameter("Attraction Distance", "Attraction Distance", "Attraction Distance", GH_ParamAccess.item);
pManager.AddNumberParameter("Cohesion Distance", "Cohesion Distance", "Cohesion Distance", GH_ParamAccess.item);
pManager.AddNumberParameter("Repulsion Distance", "Repulsion Distance", "Repulsion Distance", GH_ParamAccess.item);
pManager.AddNumberParameter("Random Strength", "Random Strength", "Random Strength", GH_ParamAccess.item);
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddPointParameter("Points", "Points", "Points", GH_ParamAccess.list);
pManager.AddVectorParameter("Vectors", "Vectors", "Vectors", GH_ParamAccess.list);
pManager.AddIntegerParameter("Iterations", "Iterations", "Iterations", GH_ParamAccess.item);
pManager.AddPointParameter("Trails", "Trails", "Trails", GH_ParamAccess.tree);
pManager.AddIntegerParameter("Test", "Test", "Test", GH_ParamAccess.item);
//pManager.AddPointParameter("Trails", "Trails", "Trails", );
// pManager.
// pManager.AddPointParameter()
// pManager.AddCurveParameter("Trails", "Trails", "Trails", GH_ParamAccess.list);
}
protected override void SolveInstance(IGH_DataAccess DA)
{
bool iReset = true;
bool iFlock = true;
bool iTrails = true;
bool iRTree = true;
bool iUnitize = true;
List<Point3d> iStartingPoints = new List<Point3d>();
double iRandomStrength = 0.0;
double iAttractionStrength = 0.0;
double iCohesionStrength = 0.0;
double iRepulsionStrength = 0.0;
double iAttractionDistance = 0.0;
double iCohesionDistance = 0.0;
double iRepulsionDistance = 0.0;
//int iIterations = 0;
DA.GetData("Reset", ref iReset);
DA.GetData("Flock", ref iFlock);
DA.GetData("Trail", ref iTrails);
DA.GetData("RTree", ref iRTree);
DA.GetData("Unitize", ref iUnitize);
DA.GetDataList("Starting Points", iStartingPoints);
DA.GetData("Random Strength", ref iRandomStrength);
DA.GetData("Attraction Strength", ref iAttractionStrength);
DA.GetData("Cohesion Strength", ref iCohesionStrength);
DA.GetData("Repulsion Strength", ref iRepulsionStrength);
DA.GetData("Attraction Distance", ref iAttractionDistance);
DA.GetData("Cohesion Distance", ref iCohesionDistance);
DA.GetData("Repulsion Distance", ref iRepulsionDistance);
if (iReset || mySwarm == null)
{
mySwarm = new SwarmSystem(iStartingPoints);
mySwarm.Iterations = 0;
}
mySwarm.Flock = iFlock;
mySwarm.RandomStrength = iRandomStrength;
mySwarm.CohesionDistance = iCohesionDistance;
mySwarm.CohesionStrength = iCohesionStrength;
mySwarm.AttractionDistance = iAttractionDistance;
mySwarm.AttractionStrength = iAttractionStrength;
mySwarm.Unitize = iUnitize;
mySwarm.RepulsionDistance = iRepulsionDistance;
mySwarm.RepulsionStrength = iRepulsionStrength;
mySwarm.Trail = iTrails;
mySwarm.Update();
//mySwarm.Iterations += 1;
List<Point3d> outputPoints = mySwarm.GetPoints();
DA.SetDataList("Points", outputPoints);
DA.SetDataList("Vectors", mySwarm.GetVectors());
DA.SetData("Iterations", mySwarm.Iterations);
DA.SetData("Test", mySwarm.testInteger);
if (iTrails)
DA.SetDataTree("Trails", mySwarm.GetTrails());
//DA.SetDataList("Trails", mySwarm.treeTrails);
}
protected override System.Drawing.Bitmap Icon
{
get
{
return Properties.Resources.SwarmSystemIcon;
}
}
public override Guid ComponentGuid
{
get { return new Guid("3ffc5bfa-16ee-43cb-8530-bc3891aed948"); }
}
}
}
When i use SetDataList, tree seems to be outputted flattened. But if i try to use SetDataTree, it seems to be an error on casting GH_Structure to IGH_DataTree
Lauren Delrieu, it all works fine in c# component, and i have no problem there, but it doesnt work in Visual Studio