Example #1
0
    // Update is called once per frame
    void Update()
    {
        count++;
        if (count > 7)
        {
            pts.RemoveAt(0);
            pts.Add(RhinoWrapper.RandomPt(rect, 1)[0]);
            count = 0;
        }
        _relax.Compute(ref pts, 2, region.ToPolyline(), 0.05);
        var pos = pts.ToHost();

        for (int i = 0; i < pos.Count; i++)
        {
            spheres[i].transform.position = pos[i];
        }
    }
Example #2
0
    public void ReComputeShape()
    {
        //Shape
        Rhino.Geometry.Point3d origin = originVec.ToRhino();
        _shapedGrid.Compute(gridSize, x_Ex, y_Ex, offsetValue, offsetValue2, maxReduceNum, minGridNum, origin, ref shapedGrid, ref shape, ref offsetShape, ref originalShape);
        if (Rhino.Geometry.AreaMassProperties.Compute(offsetShape.ToPolylineCurve()).Area <
            (Rhino.Geometry.AreaMassProperties.Compute(shape).Area / 2f))
        {
            ReComputeShape();
            Debug.Log("Failed RecomputeShape and start RecomputeShape again");
            return;
        }

        _areaRatio.Compute(shape, minAreaRatio, roomNum, ref areaSize, ref areaRatio);
        targetAreaSize = areaSize.ToIntList();
        if (debug)
        {
            debugPreview.Add(RhinoPreview.PtsShow(shapedGrid, gridSize, Color.white));
        }
        if (show)
        {
            if (polyLines.Count != 0)
            {
                foreach (var line in polyLines)
                {
                    Destroy(line);
                }
            }

            polyLines.Add(RhinoPreview.PolyLineShow(shape.ToPolyline(), Color.cyan, 0.3f, "shape"));
            polyLines.Add(RhinoPreview.PolyLineShow(offsetShape, Color.blue, 0.3f, "offsetShape"));
            polyLines.Add(RhinoPreview.PolyLineShow(originalShape.ToPolyline(), Color.gray, 0.3f, "originalShape"));
        }


        // make first agent position
        var center = Rhino.Geometry.AreaMassProperties.Compute(shape).Centroid;

        rectMin = RhinoWrapper.MakeRect(center, gridSize, gridSize);
        var areaCenters = RhinoWrapper.RandomPt(rectMin, roomNum);


        if (debug)
        {
            debugPreview.Add(RhinoPreview.PolyLineShow(rectMin.ToPolyline(), Color.green, 0.3f, "minRect"));
            debugPreview.Add(RhinoPreview.PtsShow(areaCenters, gridSize, Color.black));

            var centersList = new List <Rhino.Geometry.Point3d>();
            centersList.Add(center);
            debugPreview.Add(RhinoPreview.PtsShow(centersList, gridSize, Color.magenta));
        }

        //relax agent position
        minDist = (int)Math.Ceiling(Math.Sqrt(2) * gridSize) * (minGridNum + 1);
        _relax.Compute(ref areaCenters, minDist, offsetShape, (double)gridSize / 2.0);
        if (debug)
        {
            debugPreview.Add(RhinoPreview.PtsShow(areaCenters, gridSize, Color.red));
        }
        agentPosition = areaCenters.ToHost();
    }