private MeshBase GetChoosenMesh(MeshCreator meshCreator)
    {
        switch (meshCreator.meshType)
        {
        case MeshCreator.MeshType.Triangle:
            return(TriangleMesh.AddTriangle(meshCreator.transform.position, meshCreator.triangleVertex1,
                                            meshCreator.triangleVertex2, meshCreator.triangleVertex3, Space.World, meshCreator.material,
                                            meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Rectangle:
            return(RectangleMesh.AddRectangle(meshCreator.transform.position, meshCreator.boxSize,
                                              meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Circle:
            return(CircleMesh.AddCircle(meshCreator.transform.position, meshCreator.circleRadius,
                                        meshCreator.circleSides, meshCreator.circleUseCircleCollider, meshCreator.material,
                                        meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Quadrangle:
            Vector2[] verts = new Vector2[4] {
                meshCreator.quadrangleVertex1, meshCreator.quadrangleVertex2,
                meshCreator.quadrangleVertex3, meshCreator.quadrangleVertex4
            };
            return(QuadrangleMesh.AddQuadrangle(meshCreator.transform.position, verts, Space.World,
                                                meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Ellipse:
            return(EllipseMesh.AddEllipse(meshCreator.transform.position, meshCreator.ellipseHorizontalRadius,
                                          meshCreator.ellipseVerticalRadius, meshCreator.ellipseSides, meshCreator.material,
                                          meshCreator.attachRigidbody));

        case MeshCreator.MeshType.PointedCircle:
            return(PointedCircleMesh.AddPointedCircle(meshCreator.transform.position, meshCreator.pointedCircleRadius,
                                                      meshCreator.pointedCircleSides, meshCreator.pointedCircleShift, meshCreator.material,
                                                      meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Cake:
            return(CakeMesh.AddCakeMesh(meshCreator.transform.position, meshCreator.cakeRadius, meshCreator.cakeSides,
                                        meshCreator.cakeSidesToFill, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Convex:
            return(ConvexMesh.AddConvexMesh(meshCreator.transform.position,
                                            MeshHelper.ConvertVec2ToVec3(meshCreator.convexPoints), Space.World,
                                            meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Star:
            return(StarMesh.AddStar(meshCreator.transform.position, meshCreator.starRadiusA, meshCreator.starRadiusB,
                                    meshCreator.starSides, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Gear:
            return(GearMesh.AddGear(meshCreator.transform.position, meshCreator.gearInnerRadius, meshCreator.gearRootRadius,
                                    meshCreator.gearOuterRadius, meshCreator.gearSides, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Line:
            return(LineMesh.AddLine(meshCreator.transform.position, meshCreator.linePoints.ToArray(), meshCreator.lineWidth,
                                    meshCreator.lineUseDoubleCollider, Space.World, meshCreator.material, meshCreator.attachRigidbody));
        }
        return(null);
    }
    private GearMesh AddGear()
    {
        Vector3  pos      = new Vector3(-7, 3, -0.1f);
        GearMesh gearMesh = GearMesh.AddGear(pos, 0, 0.9f, 1.2f, 5, null, false);

        gearMesh.SetColor(Color.red);
        return(gearMesh);
    }
    private void AddGear(Vector3 pos)
    {
        float innerRadius = Random.Range(0.3f, 0.5f);
        float rootRadius  = innerRadius + Random.Range(0.1f, 0.5f);
        float outerRadius = rootRadius + Random.Range(0.3f, 0.5f);
        int   sides       = Random.Range(3, 17);

        GearMesh gear = GearMesh.AddGear(pos, innerRadius, rootRadius, outerRadius, sides, material);

        gear.AddHingeJoint();

        gear.GetComponent <MeshRenderer>().material.color = Color.gray;
    }
    private MeshBase GetChoosenMesh(MeshCreator meshCreator)
    {
        float?minArea = meshCreator.splineSimplification != SplineSimplification.Type.None
            ? meshCreator.minAbsoluteSplineArea
            : (float?)null;

        switch (meshCreator.meshType)
        {
        case MeshCreator.MeshType.Triangle:
            return(TriangleMesh.AddTriangle(meshCreator.transform.position, meshCreator.triangleVertex1,
                                            meshCreator.triangleVertex2, meshCreator.triangleVertex3, Space.World, meshCreator.material,
                                            meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Rectangle:
            return(RectangleMesh.AddRectangle(meshCreator.transform.position, meshCreator.boxSize,
                                              meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Circle:
            return(CircleMesh.AddCircle(meshCreator.transform.position, meshCreator.circleRadius,
                                        meshCreator.circleSides, meshCreator.circleUseCircleCollider, meshCreator.material,
                                        meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Quadrangle:
            Vector2[] verts = new Vector2[4] {
                meshCreator.quadrangleVertex1, meshCreator.quadrangleVertex2,
                meshCreator.quadrangleVertex3, meshCreator.quadrangleVertex4
            };
            return(QuadrangleMesh.AddQuadrangle(meshCreator.transform.position, verts, Space.World,
                                                meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Ellipse:
            return(EllipseMesh.AddEllipse(meshCreator.transform.position, meshCreator.ellipseHorizontalRadius,
                                          meshCreator.ellipseVerticalRadius, meshCreator.ellipseSides, meshCreator.material,
                                          meshCreator.attachRigidbody));

        case MeshCreator.MeshType.PointedCircle:
            return(PointedCircleMesh.AddPointedCircle(meshCreator.transform.position, meshCreator.pointedCircleRadius,
                                                      meshCreator.pointedCircleSides, meshCreator.pointedCircleShift, meshCreator.material,
                                                      meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Cake:
            return(CakeMesh.AddCakeMesh(meshCreator.transform.position, meshCreator.cakeRadius, meshCreator.cakeSides,
                                        meshCreator.cakeSidesToFill, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Convex:
            return(ConvexMesh.AddConvexMesh(meshCreator.transform.position,
                                            MeshHelper.ConvertVec2ToVec3(meshCreator.convexPoints),
                                            meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Star:
            return(StarMesh.AddStar(meshCreator.transform.position, meshCreator.starRadiusA, meshCreator.starRadiusB,
                                    meshCreator.starSides, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Gear:
            return(GearMesh.AddGear(meshCreator.transform.position, meshCreator.gearInnerRadius, meshCreator.gearRootRadius,
                                    meshCreator.gearOuterRadius, meshCreator.gearSides, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.Line:
            return(LineMesh.AddLine(meshCreator.transform.position, meshCreator.linePoints.ToArray(), meshCreator.lineWidth,
                                    meshCreator.lineUseDoubleCollider, Space.World, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.TriangulatedMesh:
            return(TriangulatedMesh.Add(meshCreator.transform.position, meshCreator.triangulatedPoints.ToArray(),
                                        meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.SplineShape:
            return(SplineShapeMesh.AddSplineShape(meshCreator.transform.position, meshCreator.splinePoints.ToArray(), meshCreator.splineResolution,
                                                  minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.SplineCurve:
            return(SplineCurveMesh.AddSplineCurve(meshCreator.transform.position, meshCreator.splineCurvePoints.ToArray(),
                                                  meshCreator.splineResolution, meshCreator.splineCurveWidth, meshCreator.splineCurveUseDoubleCollider, minArea,
                                                  Space.World, meshCreator.material, meshCreator.attachRigidbody));

        case MeshCreator.MeshType.SplineConvexShape:
            return(ConvexSplineMesh.AddConvexSpline(meshCreator.transform.position, meshCreator.convexSplinePoints.ToArray(),
                                                    meshCreator.splineResolution, minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody));

        default:
            throw new System.ArgumentOutOfRangeException();
        }
    }