コード例 #1
0
ファイル: RoadRenderer.cs プロジェクト: r2d2m/roadbuilder
        void drawLinear2DObject(Curve curve, Linear2DObject sep)
        {
            float margin_0 = sep.margin_0;
            float margin_1 = sep.margin_1;

            if (Algebra.isclose(margin_0 + margin_1, curve.length))
            {
                return;
            }
            Debug.Assert(margin_0 + margin_1 < curve.length);
            if (margin_0 + margin_1 > curve.length)
            {
                return;
            }

            if (curve.length > 0 && (margin_0 > 0 || margin_1 > 0))
            {
                curve = curve.cut(margin_0 / curve.length, 1f - margin_1 / curve.length);
            }
            if (!sep.dashed)
            {
                GameObject    rendins = Instantiate(rend, transform);
                CurveRenderer decomp  = rendins.GetComponent <CurveRenderer> ();
                decomp.CreateMesh(curve, sep.width, sep.material, offset: sep.offset, z_offset: 0.02f);
            }
            else
            {
                List <Curve> dashed = curve.segmentation(dashLength + dashInterval);
                if (!Algebra.isclose(dashed.Last().length, dashLength + dashInterval))
                {
                    dashed.RemoveAt(dashed.Count - 1);
                }
                foreach (Curve singledash in dashed)
                {
                    List <Curve> vacant_and_dashed = singledash.split(dashInterval / (dashLength + dashInterval));

                    if (vacant_and_dashed.Count == 2)
                    {
                        GameObject    rendins = Instantiate(rend, transform);
                        CurveRenderer decomp  = rendins.GetComponent <CurveRenderer> ();
                        decomp.CreateMesh(vacant_and_dashed [1], sep.width, sep.material, offset: sep.offset, z_offset: 0.02f);
                    }
                }
            }
        }
コード例 #2
0
ファイル: RoadRenderer.cs プロジェクト: r2d2m/roadbuilder
        void generateSingle(Curve curve, List <string> laneConfig,
                            float indicatorMargin_0L, float indicatorMargin_0R, float indicatorMargin_1L, float indicatorMargin_1R)
        {
            List <Linear2DObject> separators      = new List <Linear2DObject>();
            List <Linear3DObject> linear3DObjects = new List <Linear3DObject>();
            float width = getConfigureWidth(laneConfig);

            for (int i = 0; i != laneConfig.Count; ++i)
            {
                string   l            = laneConfig[i];
                float    partialWidth = getConfigureWidth(laneConfig.GetRange(0, i + 1));
                string[] configs      = l.Split('_');
                if (commonTypes.Contains(configs[0]))
                {
                    switch (configs[0])
                    {
                    case "lane":
                    case "interval":
                        if (!linear3DObjects.Any(obj => obj.tag == "bridgepanel"))
                        {
                            linear3DObjects.Add(new Linear3DObject("bridgepanel"));
                        }
                        if (!linear3DObjects.Any(obj => obj.tag == "crossbeam"))
                        {
                            Linear3DObject squarecolumn = new Linear3DObject("squarecolumn");
                            Linear3DObject crossbeam    = new Linear3DObject("crossbeam");
                            squarecolumn.margin_0 = crossbeam.margin_0 =
                                Algebra.Lerp(indicatorMargin_0L, indicatorMargin_0R, partialWidth / width);
                            squarecolumn.margin_1 = crossbeam.margin_1 =
                                Algebra.Lerp(indicatorMargin_1L, indicatorMargin_1R, partialWidth / width);

                            linear3DObjects.Add(squarecolumn);
                            linear3DObjects.Add(crossbeam);
                        }
                        break;

                    case "fence":
                    {
                        Linear3DObject fence   = new Linear3DObject("fence");
                        Linear3DObject lowbar  = new Linear3DObject("lowbar");
                        Linear3DObject highbar = new Linear3DObject("highbar");

                        fence.offset   = lowbar.offset = highbar.offset = partialWidth - fenceWidth;
                        fence.margin_0 = lowbar.margin_0 = highbar.margin_0 =
                            Algebra.Lerp(indicatorMargin_0L, indicatorMargin_0R, partialWidth / width);
                        fence.margin_1 = lowbar.margin_1 = highbar.margin_1 =
                            Algebra.Lerp(indicatorMargin_1L, indicatorMargin_1R, partialWidth / width);

                        linear3DObjects.Add(fence);
                        linear3DObjects.Add(lowbar);
                        linear3DObjects.Add(highbar);
                        break;
                    }

                    case "singlefence":
                    {
                        Linear3DObject fence   = new Linear3DObject("fence");
                        Linear3DObject lowbar  = new Linear3DObject("lowbar");
                        Linear3DObject highbar = new Linear3DObject("highbar");

                        fence.offset   = lowbar.offset = highbar.offset = partialWidth - fenceWidth * 1.5f;
                        fence.margin_0 = lowbar.margin_0 = highbar.margin_0 =
                            Algebra.Lerp(indicatorMargin_0L, indicatorMargin_0R, partialWidth / width);
                        fence.margin_1 = lowbar.margin_1 = highbar.margin_1 =
                            Algebra.Lerp(indicatorMargin_1L, indicatorMargin_1R, partialWidth / width);

                        linear3DObjects.Add(fence);
                        linear3DObjects.Add(lowbar);
                        linear3DObjects.Add(highbar);
                        break;
                    }

                    case "removal":
                        Debug.Assert(laneConfig.Count == 1);
                        //drawRemovalMark(curve, float.Parse(configs[1]));
                        Linear2DObject sep = new Linear2DObject("removal");
                        sep.dashed   = false;
                        sep.width    = float.Parse(configs[1]);
                        sep.margin_0 = Mathf.Max(indicatorMargin_0L, indicatorMargin_0R);
                        sep.margin_1 = Mathf.Max(indicatorMargin_1L, indicatorMargin_1R);
                        drawLinear2DObject(curve, sep);
                        break;
                    }
                }
                else
                {
                    string septype, sepcolor;
                    septype  = configs[0];
                    sepcolor = configs[1];

                    Linear2DObject sep;

                    switch (sepcolor)
                    {
                    case "yellow":
                        sep = new Linear2DObject("yellow");
                        break;

                    case "white":
                        sep = new Linear2DObject("white");
                        break;

                    case "blueindi":
                        sep = new Linear2DObject("blueindi");
                        break;

                    default:
                        throw new System.Exception();
                    }

                    sep.margin_0 = Algebra.Lerp(indicatorMargin_0L, indicatorMargin_0R, partialWidth / width);
                    sep.margin_1 = Algebra.Lerp(indicatorMargin_1L, indicatorMargin_1R, partialWidth / width);

                    switch (septype)
                    {
                    case "dash":
                        sep.dashed = true;
                        break;

                    case "solid":
                        sep.dashed = false;
                        break;
                    }

                    sep.offset = partialWidth - separatorWidth;

                    separators.Add(sep);
                }
            }

            //adjust center

            for (int i = 0; i != separators.Count; i++)
            {
                separators[i].offset -= (width / 2 - separatorWidth / 2);
                drawLinear2DObject(curve, separators[i]);
            }


            for (int i = 0; i != linear3DObjects.Count; i++)
            {
                {
                    Linear3DObject obj = linear3DObjects[i];
                    switch (obj.tag)
                    {
                    case "crossbeam":
                        if ((curve.z_start > 0 || curve.z_offset > 0))
                        {
                            linear3DObjects[i].setParam(width);
                            drawLinear3DObject(curve, linear3DObjects[i]);
                        }
                        break;

                    case "squarecolumn":
                        if ((curve.z_start > 0 || curve.z_offset > 0))
                        {
                            drawLinear3DObject(curve, linear3DObjects[i]);
                        }
                        break;

                    case "bridgepanel":
                        linear3DObjects[i].setParam(width);
                        drawLinear3DObject(curve, linear3DObjects[i]);

                        break;

                    case "fence":
                    case "singlefence":
                    case "highbar":
                    case  "lowbar":
                        linear3DObjects[i].offset -= (width / 2 - fenceWidth / 2);
                        drawLinear3DObject(curve, linear3DObjects[i]);

                        break;
                    }
                }
            }
        }