Example #1
0
    public void UpdateMesh()
    {
        if (meshSaved)
        {
            return;
        }

        RenderGeometry g = null;

        if (type == HyperPrimitiveType.Plane)
        {
            g = SurfaceComponentGeometries.CreatePlaneGeometry(sizeX, sizeZ, segmentX, segmentZ);
        }
        else if (type == HyperPrimitiveType.Triangle)
        {
            g = SurfaceComponentGeometries.CreateTriangleGeometry(sizeX, sizeZ, offset, segmentX);
        }
        else if (type == HyperPrimitiveType.Polygon)
        {
            g = SurfaceComponentGeometries.CreateRegularPolygonGeometry(sizeR, segmentP);
        }
        else if (type == HyperPrimitiveType.PolygonFan)
        {
            g = SurfaceComponentGeometries.CreateFanCapGeometry(sizeR, segmentP, segmentY, Rad(cutAngle));
        }
        else if (type == HyperPrimitiveType.Sphere)
        {
            g = CircularGeometries.CreateSphereGeometry(sizeR, segmentP, segmentP2, smoothH, smoothV, cutTop, cutBottom);
        }
        else if (type == HyperPrimitiveType.Cylinder)
        {
            g = CircularGeometries.CreateCylinderGeometry(sizeR, sizeY, segmentP, segmentY, smoothH, smoothV, Rad(cutAngle), hollowRatio);
        }
        else if (type == HyperPrimitiveType.Capsule)
        {
            g = CircularGeometries.CreateCapsuleGeometry(sizeR, sizeY, segmentP, segmentY, segmentP2, smoothH, smoothV);
        }
        else if (type == HyperPrimitiveType.Cone)
        {
            g = CircularGeometries.CreateConeGeometry(sizeR, sizeY, segmentP, segmentP2, smoothH, smoothV, cutTop, Rad(cutAngle));
        }
        else if (type == HyperPrimitiveType.Torus)
        {
            g = CircularGeometries.CreateTorusGeometry(sizeR, sizeR2, segmentP, segmentP2, smoothH, smoothV, Rad(cutAngle), Rad(angleOffset));
        }
        else if (type == HyperPrimitiveType.Spring)
        {
            g = CircularGeometries.CreateSpringGeometry(sizeR, sizeR2, sizeY, segmentP, segmentP2, smoothH, smoothV, Rad(angle), Rad(angleOffset));
        }
        else if (type == HyperPrimitiveType.Cube)
        {
            g = PolyhedronGeometries.CreateCubeGeometry(new Vector3(sizeX, sizeY, sizeZ), new int[] { segmentX, segmentY, segmentZ });
        }
        else if (type == HyperPrimitiveType.CubeStar)
        {
            g = PolyhedronGeometries.CreateCubeStarGeometry(sizeX, extrusion, cutTop);
        }
        else if (type == HyperPrimitiveType.CubeFrame)
        {
            g = PolyhedronGeometries.CreateCubeFrameGeometry(sizeX, ratio);
        }
        else if (type == HyperPrimitiveType.BuildingBlock)
        {
            g = PolyhedronGeometries.CreateBuildingBlockGeometry(new Vector3(sizeX, sizeY, sizeZ), new bool[, , ] {
                { { xyz, xyZ }, { xYz, xYZ } }, { { Xyz, XyZ }, { XYz, XYZ } }
            });
        }
        else if (type == HyperPrimitiveType.Tetrahedron)
        {
            g = PolyhedronGeometries.CreateTetrahedronGeometry(sizeX, segmentX);
        }
        else if (type == HyperPrimitiveType.TetrahedronStar)
        {
            g = PolyhedronGeometries.CreateTetrahedronStarGeometry(sizeX, extrusion, cutTop);
        }
        else if (type == HyperPrimitiveType.Octahedron)
        {
            g = PolyhedronGeometries.CreateOctahedronGeometry(sizeX, segmentX);
        }
        else if (type == HyperPrimitiveType.OctahedronStar)
        {
            g = PolyhedronGeometries.CreateOctahedronStarGeometry(sizeX, extrusion, cutTop);
        }
        else if (type == HyperPrimitiveType.Dodecahedron)
        {
            g = PolyhedronGeometries.CreateDodecahedronGeometry(sizeX);
        }
        else if (type == HyperPrimitiveType.DodecahedronStar)
        {
            g = PolyhedronGeometries.CreateDodecahedronStarGeometry(sizeX, extrusion, cutTop);
        }
        else if (type == HyperPrimitiveType.Icosahedron)
        {
            g = PolyhedronGeometries.CreateIcosahedronGeometry(sizeX, segmentX);
        }
        else if (type == HyperPrimitiveType.IcosahedronStar)
        {
            g = PolyhedronGeometries.CreateIcosahedronStarGeometry(sizeX, extrusion, cutTop);
        }
        else if (type == HyperPrimitiveType.TrunctedTetrahedron)
        {
            g = PolyhedronGeometries.CreateTetrahedronToTetrahedronTransitionGeometry(sizeX, ratio, cutEdge);
        }
        else if (type == HyperPrimitiveType.TrunctedCubeOctahedron)
        {
            g = PolyhedronGeometries.CreateCubeToOctahedronTransitionGeometry(sizeX, ratio, cutEdge);
        }
        else if (type == HyperPrimitiveType.TrunctedIcosahedronDodecahedron)
        {
            g = PolyhedronGeometries.CreateIcosahedronToDodecahedronTransitionGeometry(sizeX, ratio, cutEdge);
        }
        else if (type == HyperPrimitiveType.Ramp)
        {
            g = RampGeometries.CreateStraightRampGeometry(sizeX, sizeY, sizeZ, segmentX, segmentZ, smoothX, smoothZ, rampType, curvature, extraSizeY, extraSizeX, extraSizeX2);
        }
        else if (type == HyperPrimitiveType.Test)
        {
            g = SpecialSurfaceComponentGeometries.CreateSplitTriangleGeometry(1, 1, 0, 3);
        }
        else
        {
            g = new RenderGeometry();
        }

        foreach (HyperModifier modifier in GetComponents <HyperModifier>())
        {
            modifier.Apply(g);
        }

        GetComponent <MeshFilter>().sharedMesh = g.ToMesh(surfaceFacing, globalSurfaceType);
        currentGeometry = g;
    }
Example #2
0
        public void SetUpLevel(string levelCode, int size, float minePercentage)
        {
            RenderGeometry geometry;
            var            goldenNumber = (Mathf.Sqrt(5) + 1) / 2;

            switch (levelCode)
            {
            case "1-1":
                geometry = PolyhedronGeometries.CreateCubeGeometry(Vector3.one * TILE_SIZE_SQUARE * size, new[] { size, size, size });
                break;

            case "1-2":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateCubeGeometry(Vector3.one * TILE_SIZE_SQUARE * size * 2, new[] { 1, 1, 1 }),
                    f => SpecialSurfaceComponentGeometries.CreateDiamondCenterCrossSplitSquareGeometry(1, 1, size, size));
                break;

            case "1-3":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateCubeGeometry(Vector3.one * TILE_SIZE_SQUARE * size * 2, new[] { 1, 1, 1 }),
                    f => SpecialSurfaceComponentGeometries.CreateDiamondCenterOctaSplitSquareGeometry(1, 1, size, size));
                break;

            case "1-4":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateCubeGeometry(Vector3.one * TILE_SIZE_SQUARE * size * 1.5f, new[] { 1, 1, 1 }),
                    f => SpecialSurfaceComponentGeometries.CreatePantagonSquareGeometry(1, 1, size, size, 0.4f));
                break;

            case "1-5":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateCubeGeometry(Vector3.one * TILE_SIZE_SQUARE * size * 1.2f, new[] { 1, 1, 1 }),
                    f => SpecialSurfaceComponentGeometries.CreateAlternatingDiagonalSplitSquareGeometry(1, 1, size, size));
                break;

            case "1-6":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateCubeGeometry(Vector3.one * TILE_SIZE_SQUARE * size * 1.5f, new[] { 1, 1, 1 }),
                    f => SpecialSurfaceComponentGeometries.CreateXSplitSquareGeometry(1, 1, size, size, 0.2f / size));
                break;

            case "2-1":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateCubeStarGeometry(TILE_SIZE_SQUARE * size, 2, 1),
                    f => SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, size, size));
                break;

            case "3-1":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateCubeFrameGeometry(TILE_SIZE_SQUARE * (size + 2), 1 - ((size + 2) / 3 * 2) / (float)(size + 2)),
                    f => SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, Mathf.RoundToInt(f.edge.prev.length / TILE_SIZE_SQUARE), Mathf.RoundToInt(f.edge.length / TILE_SIZE_SQUARE)));
                break;

            case "4-1":
                geometry = PolyhedronGeometries.CreateTetrahedronGeometry(TILE_SIZE_TRIANGLE * size / Mathf.Sqrt(2), size);
                break;

            case "4-2":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateTetrahedronGeometry(TILE_SIZE_TRIANGLE * size * Mathf.Sqrt(2), 1),
                    f => SpecialSurfaceComponentGeometries.CreateSplitTriangleGeometry(1, 1, 0, size));
                break;

            case "4-3":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateOctahedronStarGeometry(TILE_SIZE_TRIANGLE * size * Mathf.Sqrt(2), 2, 0),
                    f => SurfaceComponentGeometries.CreateTriangleGeometry(1, 1, 0, size));
                break;

            case "4-4":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateOctahedronStarGeometry(TILE_SIZE_TRIANGLE * size * 2 * Mathf.Sqrt(2), 2, 0),
                    f => SpecialSurfaceComponentGeometries.CreateSplitTriangleGeometry(1, 1, 0, size));
                break;

            case "5-1":
                geometry = PolyhedronGeometries.CreateOctahedronGeometry(TILE_SIZE_TRIANGLE * size * Mathf.Sqrt(2), size);
                break;

            case "5-2":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateCuboctahedronGeometry(TILE_SIZE_SQUARE_TRIANGLE * size * Mathf.Sqrt(2), 0.5f),
                    f => f.edges.Count == 4
                        ? SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, size, size)
                        : SurfaceComponentGeometries.CreateTriangleGeometry(1, 1, 0, size));
                break;

            case "5-3":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateRhombicuboctahedronGeometry(TILE_SIZE_SQUARE_TRIANGLE * size * (1 + Mathf.Sqrt(2)), Mathf.Sqrt(2) / (1 + Mathf.Sqrt(2))),
                    f => f.edges.Count == 4
                        ? SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, size, size)
                        : SurfaceComponentGeometries.CreateTriangleGeometry(1, 1, 0, size));
                break;

            case "6-1":
                geometry = PolyhedronGeometries.CreateIcosahedronGeometry(TILE_SIZE_TRIANGLE * size * goldenNumber, size);
                break;

            case "6-2":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateDodecahedronGeometry(TILE_SIZE_TRIANGLE * size * goldenNumber * goldenNumber),
                    f => SpecialSurfaceComponentGeometries.CreateTrianglesCombinedRegularPolygonGeometry(1, 5, () => SpecialSurfaceComponentGeometries.CreateWallTiledTriangleGeometry(1, 1, 0, size).ShiftBoundaries(1)));
                break;

            case "6-3":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateIcosidodecahedronGeometry(TILE_SIZE_TRIANGLE * size * goldenNumber * 2),
                    f => f.edges.Count == 5
                         ? SpecialSurfaceComponentGeometries.CreateTrianglesCombinedRegularPolygonGeometry(1, 5, () => SpecialSurfaceComponentGeometries.CreateWallTiledTriangleGeometry(1, 1, 0, size).ShiftBoundaries(1))
                         : SurfaceComponentGeometries.CreateTriangleGeometry(1, 1, 0, size));
                break;

            case "6-4":
                geometry = ReplaceAllFace(
                    PolyhedronGeometries.CreateTrunctedIcosahedronGeometry(TILE_SIZE_TRIANGLE * size * goldenNumber * goldenNumber * 2, 2 / 3f),
                    f => f.edges.Count == 5
                         ? SpecialSurfaceComponentGeometries.CreateTrianglesCombinedRegularPolygonGeometry(1, 5, () => SpecialSurfaceComponentGeometries.CreateWallTiledTriangleGeometry(1, 1, 0, size).ShiftBoundaries(1))
                         : SpecialSurfaceComponentGeometries.CreateTrianglesCombinedRegularPolygonGeometry(1, 6, () => SurfaceComponentGeometries.CreateTriangleGeometry(1, 1, 0, size)));
                break;

            case "7-1":
                geometry = CircularGeometries.CreateTorusGeometry(TILE_SIZE_SQUARE * (3 + size) * 0.4f, TILE_SIZE_SQUARE * (3 + size) * 0.16f, (3 + size) * 2, 3 + size, false, false);
                break;

            case "9-9":
                geometry = SpecialSurfaceComponentGeometries.CreateTrianglesCombinedRegularPolygonGeometry(TILE_SIZE_SQUARE * size, 5, () => SpecialSurfaceComponentGeometries.CreateWallTiledTriangleGeometry(1, 1, 0, size).ShiftBoundaries(1));
                break;

            default:
                return;
            }

            MineFieldControl.instance.InitField(geometry, Mathf.RoundToInt(geometry.faces.Count * minePercentage));
        }