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 void AddGear(Vector3 pos)
    {
        GameObject gear = new GameObject();

        gear.transform.position = pos;

        GearMesh gearMesh = gear.AddComponent <GearMesh>();

        gearMesh.Build(1, 1.2f, 1.5f, 12);
        gearMesh.AddHingeJoint();

        gearMesh.C_MR.material.color = Color.gray;
    }
Exemple #5
0
    private void AddFrontWheel(GameObject body, Vector3 position)
    {
        carElements[2] = new GameObject();
        //build front wheel
        GearMesh frontWheelScript = carElements[2].AddComponent <GearMesh>();
        float    radius           = Random.Range(0.4f, 0.6f);
        int      sides            = Random.Range(8, 12);

        frontWheelScript.Build(0.1f, radius, radius + 0.2f, sides, material);
        carElements[2].transform.position = position;
        //add motor
        frontWheelScript.AddHingeJoint(new JointMotor2D
        {
            motorSpeed     = 300,
            maxMotorTorque = 1000
        }, body.GetComponent <Rigidbody2D>());

        frontWheelScript.C_MR.material.color = Color.black;
        frontWheelScript.SetPhysicsMaterialProperties(0, 10f);
    }
    private void AddGearWithMotor(Vector3 pos, JointMotor2D C_JM2D)
    {
        //alternative way to add Mesh

        //add GameObject and move it to desired position
        GameObject gear = new GameObject();

        gear.transform.position = pos;

        //add GearMesh component, build the Gear and add a motor
        GearMesh gearMesh = gear.AddComponent <GearMesh>();

        gearMesh.Build(1, 1.2f, 1.5f, 12);
        gearMesh.AddHingeJoint(C_JM2D);

        //override default name
        gear.name = "Motor gear";

        //set mesh's color
        gearMesh.C_MR.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();
        }
    }