Beispiel #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Goo trailData   = null;
            IGH_Goo colorData   = null;
            bool    texture     = new bool();
            object  displayMode = null;

            VisualData visualData = new VisualData();

            if (!DA.GetData(0, ref trailData) || trailData == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No Trail Data Detected, please connect Trail Data to enable the component");
                return;
            }
            DA.GetData(1, ref colorData);
            string dataType = trailData.GetType().Name.ToString();

            if (trailData.ToString() == "Culebra_GH.Data_Structures.TrailData")
            {
                TrailData td;
                bool      worked = trailData.CastTo(out td);
                if (worked)
                {
                    visualData.trailData = td;
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert trail data, ensure you have the correct inputs");
                    return;
                }
            }
            else
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please input Trail Data Output value for Trail Data not a " + dataType);
                return;
            }
            if (colorData != null)
            {
                string colorType = colorData.GetType().Name.ToString();
                if (colorData.ToString() == "Culebra_GH.Data_Structures.ColorData")
                {
                    ColorData cd;
                    bool      worked = colorData.CastTo(out cd);
                    if (worked)
                    {
                        visualData.colorData = cd;
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert color data, ensure you have the correct inputs");
                        return;
                    }
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please input Trail Data Output value for Trail Data not a " + colorType);
                    return;
                }
            }
            else
            {
                ColorData color = new ColorData();
                color.colorDataType  = "Base";
                visualData.colorData = color;
            }
            if (!DA.GetData(2, ref texture))
            {
                return;
            }
            if (texture)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "WARNING USING TEXTURE CAN MAKE THE SIMULATION VERY UNSTABLE AND MAY CRASH WITHOUT WARNING, I RECOMMEND USING THE GH BUILT IN CLOUD DISPLAY FOR THE CREEPERS OUTPUT");
            }
            visualData.useTexture = texture;

            if (!DA.GetData(3, ref displayMode))
            {
                return;
            }
            string type2 = displayMode.GetType().Name.ToString();

            if (displayMode.GetType() != typeof(GH_Integer) && displayMode.GetType() != typeof(GH_Number))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please input a integer/float value for Display Mode not a " + type2);
                return;
            }
            else
            {
                if (displayMode.GetType() == typeof(GH_Integer))
                {
                    GH_Integer ghInt = (GH_Integer)displayMode;
                    visualData.displayMode = ghInt.Value;
                }
                else
                {
                    GH_Number ghNum = (GH_Number)displayMode;
                    visualData.displayMode = Convert.ToInt32(ghNum.Value);
                }
            }
            IGH_VisualData igh_Viz = new IGH_VisualData(visualData);

            DA.SetData(0, igh_Viz);
        }
Beispiel #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (GH_Document.IsEscapeKeyDown())
            {
                GH_Document GHDocument = OnPingDocument();
                GHDocument.RequestAbortSolution();
                return;
            }

            ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("culebra"));
            ikvm.runtime.Startup.addBootClassPathAssemby(Assembly.Load("IKVM.OpenJDK.Core"));

            bool           reset           = new bool();
            int            iterations      = new int();
            List <object>  init_Settings   = new List <object>();
            List <object>  move_Settings   = new List <object>();
            IGH_VisualData visual_Settings = null;

            object behavioral_Settings = null;

            if (!DA.GetDataList(0, init_Settings) || init_Settings.Count == 0 || init_Settings == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No Init Settings Detected, please connect Init Settings to enable the component");
                return;
            }
            if (!DA.GetDataList(1, move_Settings) || move_Settings.Count == 0 || move_Settings == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No Move Settings Detected, please connect Move Settings to enable the component");
                return;
            }
            if (!DA.GetData(3, ref visual_Settings) || visual_Settings == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No Visual Settings Detected, please connect Visual Settings to enable the component");
                return;
            }
            if (!DA.GetData(4, ref iterations))
            {
                return;
            }
            if (!DA.GetData(5, ref reset))
            {
                return;
            }
            Random rnd = new Random();

            if (!DA.GetData(2, ref behavioral_Settings) || behavioral_Settings == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input Object is Null");
                return;
            }
            string objtype = behavioral_Settings.GetType().Name.ToString();

            if (!(behavioral_Settings.GetType() == typeof(IGH_BehaviorData)))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "You did not input a Behavior Data Object, please ensure input is Behavior Data Object and not " + objtype);
                return;
            }
            else
            {
                #region Initialize / Data Parse
                //------------------------Init Settings--------------------------
                if (init_Settings.Count != 0)
                {
                    String init_Convert = "";
                    if (init_Settings[0].GetType() == typeof(GH_String))
                    {
                        GH_String value = (GH_String)init_Settings[0];
                        init_Convert = value.Value;
                    }
                    if (init_Convert == "Box")
                    {
                        this.spawnData = "box";
                        GH_Convert.ToBox_Primary(init_Settings[3], ref this.box);
                        GH_Convert.ToInt32(init_Settings[4], out this.spawnType, GH_Conversion.Primary);
                        GH_Convert.ToInt32(init_Settings[5], out this.pointCount, GH_Conversion.Primary);
                        GH_Convert.ToInt32(init_Settings[1], out this.dimensions, GH_Conversion.Primary);
                    }
                    else if (init_Convert == "Points")
                    {
                        this.spawnData = "Points";
                        var wrapperToGoo = GH_Convert.ToGoo(init_Settings[3]);
                        wrapperToGoo.CastTo <List <Point3d> >(out this.ptList);
                        GH_Convert.ToInt32(init_Settings[1], out this.dimensions, GH_Conversion.Primary);
                        GH_Convert.ToBox_Primary(init_Settings[4], ref this.box);
                    }
                    GH_Convert.ToInt32(init_Settings[2], out this.bounds, GH_Conversion.Primary);
                }
                //------------------------Move Settings--------------------------
                Vector3d initialVector = new Vector3d();
                if (move_Settings.Count != 0)
                {
                    if (move_Settings[0].GetType() == typeof(GH_Vector))
                    {
                        GH_Vector value = (GH_Vector)move_Settings[0];
                        initialVector = value.Value;
                    }
                    else if (move_Settings[0].GetType() == typeof(GH_Number))
                    {
                        GH_Number value = (GH_Number)move_Settings[0];
                        this.initialSpeed = value.Value;
                    }
                    GH_Convert.ToDouble(move_Settings[1], out this.maxSpeed, GH_Conversion.Primary);
                    GH_Convert.ToDouble(move_Settings[2], out this.maxForce, GH_Conversion.Primary);
                    GH_Convert.ToDouble(move_Settings[3], out this.velMultiplier, GH_Conversion.Primary);
                }
                //------------------------Visual Settings--------------------------
                TrailData td = visual_Settings.Value.trailData;
                ColorData cd = visual_Settings.Value.colorData;
                this.trail           = td.createTrail;
                this.displayMode     = visual_Settings.Value.displayMode;
                this.trailStep       = td.trailStep;
                this.maxTrailSize    = td.maxTrailSize;
                this.particleTexture = cd.particleTexture;
                this.graphicType     = cd.colorDataType;
                this.useTexture      = visual_Settings.Value.useTexture;
                if (cd.colorDataType == "Gradient")
                {
                    this.maxthick       = cd.maxThickness;
                    this.minthick       = cd.minThickness;
                    this.redValues[0]   = cd.redChannel[0];
                    this.redValues[1]   = cd.redChannel[1];
                    this.greenValues[0] = cd.greenChannel[0];
                    this.greenValues[1] = cd.greenChannel[1];
                    this.blueValues[0]  = cd.blueChannel[0];
                    this.blueValues[1]  = cd.blueChannel[1];
                }
                else if (cd.colorDataType == "GraphicPolyline")
                {
                    this.polylineColor = cd.color;
                    this.dotted        = cd.dotted;
                    this.maxthick      = cd.maxThickness;
                }
                else if (cd.colorDataType == "Disco")
                {
                    this.maxthick = cd.maxThickness;
                    this.minthick = cd.minThickness;
                }
                else if (cd.colorDataType == "Base")
                {
                    this.maxthick = 3;
                    this.minthick = 1;
                }
                //-----------------------------------------------------------------
                IGH_PreviewObject comp = (IGH_PreviewObject)this;
                if (comp.Hidden && (this.displayMode == 0))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Component preview must be enabled to see Graphic Mode on Canvas, right click on component and set preview on");
                }
                #endregion
                #region Pre Simulation Code
                //------------------------RESET STARTS HERE--------------------------
                if (reset)
                { //We are using the reset to reinitialize all the variables and positions
                    //-----------------------------------------------------------------
                    this.bb = new BoundingBox();
                    int  loopCount = new int();
                    bool create    = new bool();
                    if (this.spawnData == "box")
                    {
                        this.bb   = this.box.BoundingBox;
                        loopCount = this.pointCount;
                        create    = true;
                    }
                    else if (this.spawnData == "Points")
                    {
                        loopCount = this.ptList.Count;
                        create    = false;
                        this.bb   = this.box.BoundingBox;
                    }
                    //-----------------------------------------------------------------
                    this.moveList       = new List <Vector3d>();
                    this.startList      = new List <Vector3d>();
                    this.creepList      = new List <CulebraObject>();
                    this.currentPosList = new List <Point3d>();
                    this.networkList    = new List <Line>();
                    flattenedTrails     = new List <Vector3d>();

                    for (int i = 0; i < loopCount; i++)
                    {
                        if (this.dimensions == 0)
                        { //If we want 2D
                            General.setViewport("Top", "Shaded");
                            if (create)
                            { //If are creating random points inside bbox
                                if (this.spawnType == 0 || this.spawnType == 2)
                                {
                                    this.startPos = new Vector3d((int)bb.Min[0], rnd.Next((int)bb.Min[1], (int)bb.Max[1]), 0); //spawn along the y axis of the bounding area
                                }
                                else if (this.spawnType == 1 || this.spawnType == 3)
                                {
                                    this.startPos = new Vector3d(rnd.Next((int)bb.Min[0], (int)bb.Max[0]), rnd.Next((int)bb.Min[1], (int)bb.Max[1]), 0); //spawn randomly inside the bounding area
                                }
                                if (initialVector.Length > 0)
                                {
                                    this.moveVec = initialVector; //move in the user specified direction
                                }
                                else
                                {
                                    this.moveVec = new Vector3d(rnd.Next(-1, 2) * initialSpeed, rnd.Next(-1, 2) * initialSpeed, 0); //move randomly in any direction 2d
                                }
                            }
                            else
                            { //If we are using user defined points
                                this.startPos = (Vector3d)this.ptList[i];
                                if (initialVector.Length > 0)
                                {
                                    this.moveVec = initialVector; //move in the user specified direction
                                }
                                else
                                {
                                    this.moveVec = new Vector3d(rnd.Next(-1, 2) * initialSpeed, rnd.Next(-1, 2) * initialSpeed, 0); //move randomly in any direction 2d
                                }
                            }
                            this.creep = new Creeper(this.startPos, this.moveVec, true, false);
                            this.creepList.Add(this.creep);
                        }
                        else
                        { //If we want 3D
                            General.setViewport("Perspective", "Shaded");
                            if (create)
                            { //If are creating random points inside bbox
                                if (this.spawnType == 0 || this.spawnType == 2)
                                {
                                    this.startPos = new Vector3d(rnd.Next((int)bb.Min[0], (int)bb.Max[0]), rnd.Next((int)bb.Min[1], (int)bb.Max[1]), (int)bb.Min[2]); //start randomly on the lowest plane of the 3d bounds
                                    if (initialVector.Length > 0)
                                    {
                                        this.moveVec = initialVector; //move in the user specified direction
                                    }
                                    else
                                    {
                                        this.moveVec = new Vector3d(rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed, 1 * initialSpeed); //move randomly in the xy axis and up in the z axis
                                    }
                                }
                                else if (this.spawnType == 1 || this.spawnType == 3)
                                {
                                    this.startPos = new Vector3d(rnd.Next((int)bb.Min[0], (int)bb.Max[0]), rnd.Next((int)bb.Min[1], (int)bb.Max[1]), rnd.Next((int)bb.Min[2], (int)bb.Max[2])); //start randomly inside the 3d bounds
                                    if (initialVector.Length > 0)
                                    {
                                        this.moveVec = initialVector; //move in the user specified direction
                                    }
                                    else
                                    {
                                        this.moveVec = new Vector3d(rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed); //move randomly in any direction 3d
                                    }
                                }
                            }
                            else
                            { //If we are using user defined points
                                this.startPos = (Vector3d)this.ptList[i];
                                if (initialVector.Length > 0)
                                {
                                    this.moveVec = initialVector; //move in the user specified direction
                                }
                                else
                                {
                                    this.moveVec = new Vector3d(rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed, rnd.Next(-2, 2) * initialSpeed); //move randomly in any direction 3d
                                }
                            }
                            this.creep = new Creeper(this.startPos, this.moveVec, true, true);
                            this.creepList.Add(this.creep);
                        }
                        this.startList.Add(this.startPos); //add the initial starting positions to the list to pass once we start running
                        this.moveList.Add(this.moveVec);   //add the initial move vectors to the list to pass once we start running
                    }
                    #endregion
                    #region Simulation Code
                    this.trailTree    = new DataTree <Point3d>();
                    this.globalEngine = new Engine_Global();
                    for (int z = 0; z < iterations; z++)
                    {
                        this.particleSet    = new DataTree <Point3d>();
                        this.currentPosList = new List <Point3d>();

                        this.trailTree.Clear();
                        this.networkTree.Clear();
                        this.trailTree.TrimExcess();
                        this.networkTree.TrimExcess();

                        if (this.moveList == null)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please Reset the CreepyCrawlers Component"); return;
                        }
                        try
                        {
                            globalEngine.Action(this.creepList, this.dimensions, behavioral_Settings, this.displayMode, this.networkList,
                                                this.maxSpeed, this.maxForce, this.velMultiplier, this.flattenedTrails, this.particleList, this.particleSet, networkTree, trailStep, maxTrailSize, bounds, bb, currentPosList, trail, trailTree);
                        }
                        catch (Exception e)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message.ToString());
                            return;
                        }

                        this.flattenedTrails.Clear();
                        this.flattenedTrails.TrimExcess();

                        #endregion
                    }
                    DA.SetDataList(0, this.currentPosList);
                    DA.SetDataTree(2, networkTree);
                    if (this.displayMode == 1 && this.trail)
                    {
                        DA.SetDataTree(1, trailTree);
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object       behavioral_Settings = null;
            object       visual_Settings     = null;
            bool         reset  = new bool();
            List <Curve> curves = new List <Curve>();

            if (!DA.GetDataList(0, curves))
            {
                return;
            }
            if (!DA.GetData(1, ref behavioral_Settings) || behavioral_Settings == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Behavior Input Object is Null");
                return;
            }
            string objtype = behavioral_Settings.GetType().Name.ToString();

            if (!(behavioral_Settings.GetType() == typeof(IGH_BehaviorData)))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "You did not input a Behavior Data Object, please ensure input is Behavior Data Object and not " + objtype);
                return;
            }
            if (!DA.GetData(2, ref visual_Settings) || visual_Settings == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Visual Input Object is Null");
                return;
            }
            string objtype2 = visual_Settings.GetType().Name.ToString();

            if (!(visual_Settings.GetType() == typeof(IGH_VisualData)))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "You did not input a Visual Data Object, please ensure input is Visual Data Object and not " + objtype2);
                return;
            }
            if (!DA.GetData(3, ref reset))
            {
                return;
            }
            //------------------------Visual Settings--------------------------
            IGH_VisualData igh_Visual = (IGH_VisualData)visual_Settings;
            TrailData      td         = igh_Visual.Value.trailData;
            ColorData      cd         = igh_Visual.Value.colorData;

            this.trail           = td.createTrail;
            this.displayMode     = igh_Visual.Value.displayMode;
            this.trailStep       = td.trailStep;
            this.maxTrailSize    = td.maxTrailSize;
            this.particleTexture = cd.particleTexture;
            this.graphicType     = cd.colorDataType;
            this.useTexture      = igh_Visual.Value.useTexture;
            if (cd.colorDataType == "Gradient")
            {
                this.maxthick       = cd.maxThickness;
                this.minthick       = cd.minThickness;
                this.redValues[0]   = cd.redChannel[0];
                this.redValues[1]   = cd.redChannel[1];
                this.greenValues[0] = cd.greenChannel[0];
                this.greenValues[1] = cd.greenChannel[1];
                this.blueValues[0]  = cd.blueChannel[0];
                this.blueValues[1]  = cd.blueChannel[1];
            }
            else if (cd.colorDataType == "GraphicPolyline")
            {
                this.polylineColor = cd.color;
                this.dotted        = cd.dotted;
                this.maxthick      = cd.maxThickness;
            }
            else if (cd.colorDataType == "Disco")
            {
                this.maxthick = cd.maxThickness;
                this.minthick = cd.minThickness;
            }
            else if (cd.colorDataType == "Base")
            {
                this.maxthick = 3;
                this.minthick = 1;
            }
            //-----------------------------------------------------------------
            if (reset)
            {
                this.cycles  = 0;
                this.crvList = new List <Curve>();
                this.crvList = curves;
                DA.SetDataList(0, crvList);
            }
            else
            {
                this.particleSet.Clear();
                this.particleSet.TrimExcess();

                IGH_BehaviorData igh_Behavior = (IGH_BehaviorData)behavioral_Settings;

                this.thresh    = igh_Behavior.Value.bundlingData.threshold;
                this.ratio     = igh_Behavior.Value.bundlingData.ratio;
                this.ptCount   = igh_Behavior.Value.bundlingData.pointCount;
                this.rebuild   = igh_Behavior.Value.bundlingData.rebuild;
                this.weldCount = igh_Behavior.Value.bundlingData.weldCount;
                //-----------------------------------------------------------------
                foreach (string s in igh_Behavior.Value.dataOrder)
                {
                    if (s == "Bundling")
                    {
                        try
                        {
                            if (igh_Behavior.Value.bundlingData.colorMesh != null)
                            {
                                this.crvList = this.selfOrg.Bundling(particleList, particleSet, this.crvList, this.thresh, this.ratio, this.weldCount, this.rebuild, this.ptCount,
                                                                     igh_Behavior.Value.bundlingData.colorMesh, igh_Behavior.Value.bundlingData.useColor);
                            }
                            else
                            {
                                this.crvList = this.selfOrg.Bundling(particleList, particleSet, this.crvList, this.thresh, this.ratio, this.weldCount, this.rebuild, this.ptCount);
                            }
                        }
                        catch (Exception e)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message.ToString());
                            return;
                        }
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Currently we can only run bundling behavior on the Bundling Engine, please remove other behaviors");
                        return;
                    }
                }
                if (this.displayMode == 1)
                {
                    DA.SetDataList(0, this.crvList);
                }
                this.cycles++;
            }
            timer.DisplayMessage(this, "Bundling", this.cycles, this.myBool);
        }