예제 #1
0
    public static SurfaceComponentGeometry CreateDiamondCenterOctaSplitSquareGeometry(
        float sizeX, float sizeZ, int segmentX, int segmentZ, float diamondRatio = 0.6f, int surfaceGroup = 0, RenderGeometry.FaceType faceType = RenderGeometry.FaceType.Polygonal)
    {
        SurfaceComponentGeometry planeGeometry = SurfaceComponentGeometries.CreatePlaneGeometry(sizeX, sizeZ, segmentX, segmentZ);
        List <Vertex>            corners       = planeGeometry.corners;

        var structure    = new StructureGeometry(planeGeometry);
        var edgesToMerge = new List <Halfedge>();

        structure.faces.ForEach(f => {
            var component = CreateSingleDiamondCenterOctaSplitSquareGeometry(1, 1, diamondRatio, surfaceGroup, faceType);
            edgesToMerge.AddRange(component.boundaries.SelectMany(b => b).Select(e => e.opposite));
            structure.SetFaceComponent(f, component, true);
        });
        var geometry = new SurfaceComponentGeometry(structure.Build());

        foreach (Halfedge edge in edgesToMerge)
        {
            if (edge.index >= 0 && !edge.opposite.isBoundary)
            {
                geometry.MergeFaces(edge);
            }
        }
        geometry.DefineBoundaries(corners.Select(structure.GetBuiltVertex).ToArray());

        return(geometry);
    }
예제 #2
0
    public static SurfaceComponentGeometry CreateDiamondCenterCrossSplitSquareGeometry(
        float sizeX, float sizeZ, int segmentX, int segmentZ, float diamondRatio = 0.6f, int surfaceGroup = 0, RenderGeometry.FaceType faceType = RenderGeometry.FaceType.Polygonal)
    {
        SurfaceComponentGeometry planeGeometry = SurfaceComponentGeometries.CreatePlaneGeometry(sizeX, sizeZ, segmentX, segmentZ);
        List <Vertex>            corners       = planeGeometry.corners;

        var structure = new StructureGeometry(planeGeometry);

        structure.faces.ForEach(f => structure.SetFaceComponent(f, CreateSingleDiamondCenterCrossSplitSquareGeometry(1, 1, diamondRatio, surfaceGroup, faceType), true));
        var geometry = new SurfaceComponentGeometry(structure.Build());

        geometry.DefineBoundaries(corners.Select(structure.GetBuiltVertex).ToArray());

        return(geometry);
    }
    public static RenderGeometry CreateSpringGeometry(float ringRadius, float barRadius, float heightPerCycle, int segmentPerCycle, int segmentBar, bool smoothH, bool smoothV, float angle = 0, float deltaAngle = 0)
    {
        StructureGeometry structure = new StructureGeometry();

        RenderGeometry.FaceType faceType = GetFaceType(smoothH, smoothV);
        float heightPerRad = heightPerCycle / (2 * Mathf.PI);
        float slope        = heightPerRad / ringRadius;
        float scaleH       = Mathf.Sqrt(1 + slope * slope);
        int   segmentRing  = Mathf.CeilToInt(segmentPerCycle * angle / (2 * Mathf.PI) - 1e-6f);

        SurfaceComponentGeometry face = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, segmentBar, segmentRing, 1, faceType);

        var warp = new SpaceWarp(
            $" a1=(z+0.5)*{angle}",
            $" a2={deltaAngle}-x*(2*PI)",
            $" r={ringRadius}+{barRadius}*cos(a2)",
            $" X=r*cos(a1)",
            $" Y={scaleH}*{barRadius}*sin(a2)+a1*{heightPerRad}",
            $" Z=r*sin(a1)"
            );

        face.ApplySpaceWarp(warp);

        SurfaceComponentGeometry cap1 = SurfaceComponentGeometries.CreateRegularPolygonGeometry(barRadius, segmentBar, 2);
        SurfaceComponentGeometry cap2 = SurfaceComponentGeometries.CreateRegularPolygonGeometry(barRadius, segmentBar, 2);

        cap1.ApplyLinearTransform(
            Matrix4x4.Translate(Vector3.right * ringRadius) *
            Matrix4x4.Scale(new Vector3(1, scaleH, 1)) *
            Matrix4x4.Rotate(Quaternion.LookRotation(Vector3.down, Vector3.back) * Quaternion.AngleAxis(-deltaAngle * Mathf.Rad2Deg, Vector3.up)));
        cap2.ApplyLinearTransform(
            Matrix4x4.Translate(new Vector3(ringRadius * Mathf.Cos(angle), heightPerRad * angle, ringRadius * Mathf.Sin(angle))) *
            Matrix4x4.Scale(new Vector3(1, scaleH, 1)) *
            Matrix4x4.Rotate(Quaternion.LookRotation(Vector3.up, Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.down) * Vector3.forward) * Quaternion.AngleAxis(deltaAngle * Mathf.Rad2Deg, Vector3.up)));

        Vertex corner1 = structure.CreateVertex();
        Vertex corner2 = structure.CreateVertex();

        structure.CreateFace(face, false, corner1, corner2, corner2, corner1);
        structure.CreateFace(cap1, false, corner1);
        structure.CreateFace(cap2, false, corner2);
        return(structure.Build());
    }
예제 #4
0
    public static SurfaceComponentGeometry CreatePantagonSquareGeometry(
        float sizeX, float sizeZ, int segmentX, int segmentZ, float pantagonRatio = 0.3f, int surfaceGroup = 0, RenderGeometry.FaceType faceType = RenderGeometry.FaceType.Polygonal)
    {
        SurfaceComponentGeometry planeGeometry = SurfaceComponentGeometries.CreatePlaneGeometry(sizeX, sizeZ, segmentX * 2, segmentZ * 2, surfaceGroup, faceType);
        var originalVertexList = new List <Vertex>(planeGeometry.vertices);

        Vertex corner(int x, int z) => originalVertexList[x * (segmentZ * 2 + 1) + z];

        float deltaX = sizeX / (segmentX * 2) * pantagonRatio;
        float deltaZ = sizeZ / (segmentZ * 2) * pantagonRatio;

        for (int x = 1; x < segmentX * 2; x++)
        {
            for (int z = 1; z < segmentZ * 2; z++)
            {
                if (x % 2 == 0 && z % 2 == 1)
                {
                    corner(x, z).p += deltaX * ((x + z) % 4 == 3 ? Vector3.left : Vector3.right);
                }
                else if (x % 2 == 1 && z % 2 == 0)
                {
                    corner(x, z).p += deltaZ * ((x + z) % 4 == 3 ? Vector3.forward : Vector3.back);
                }
            }
        }
        for (int x = 0; x < segmentX; x++)
        {
            for (int z = 0; z < segmentZ; z++)
            {
                if ((x + z) % 2 == 0)
                {
                    planeGeometry.MergeFaces(planeGeometry.FindHalfedge(corner(x * 2 + 1, z * 2 + 1), corner(x * 2 + 1, z * 2)));
                    planeGeometry.MergeFaces(planeGeometry.FindHalfedge(corner(x * 2 + 1, z * 2 + 1), corner(x * 2 + 1, z * 2 + 2)));
                }
                else
                {
                    planeGeometry.MergeFaces(planeGeometry.FindHalfedge(corner(x * 2 + 1, z * 2 + 1), corner(x * 2, z * 2 + 1)));
                    planeGeometry.MergeFaces(planeGeometry.FindHalfedge(corner(x * 2 + 1, z * 2 + 1), corner(x * 2 + 2, z * 2 + 1)));
                }
            }
        }
        return(planeGeometry);
    }
예제 #5
0
    public static SurfaceComponentGeometry CreateXSplitSquareGeometry(
        float sizeX, float sizeZ, int segmentX, int segmentZ, float spikeHeight = 0, int surfaceGroup = 0, RenderGeometry.FaceType faceType = RenderGeometry.FaceType.Polygonal)
    {
        var           planeGeometry = SurfaceComponentGeometries.CreatePlaneGeometry(sizeX, sizeZ, segmentX, segmentZ);
        List <Vertex> corners       = planeGeometry.corners;

        var structure  = new StructureGeometry(planeGeometry);
        var coneHeight = spikeHeight / (sizeZ / segmentZ) * Mathf.Sqrt(2);

        structure.faces.ForEach(f => {
            var component = SurfaceComponentGeometries.CreateConeCapGeometry(1, coneHeight, 4, 1, 0, surfaceGroup, faceType);
            component.SplitBoundaries();
            structure.SetFaceComponent(f, component, true);
        });
        var geometry = new SurfaceComponentGeometry(structure.Build());

        geometry.DefineBoundaries(corners.Select(structure.GetBuiltVertex).ToArray());

        return(geometry);
    }
    public static RenderGeometry CreateTorusGeometry(float ringRadius, float barRadius, int segmentRing, int segmentBar, bool smoothH, bool smoothV, float cutAngle = 0, float deltaAngle = 0)
    {
        StructureGeometry structure = new StructureGeometry();

        RenderGeometry.FaceType faceType = GetFaceType(smoothH, smoothV);

        SurfaceComponentGeometry face = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, segmentBar, segmentRing, 1, faceType);

        var warp = new SpaceWarp(
            $" a1=(z+0.5)*(2*PI-{cutAngle})",
            $" a2={deltaAngle}-x*(2*PI)",
            $" r={ringRadius}+{barRadius}*cos(a2)",
            $" X=r*cos(a1)",
            $" Y={barRadius}*sin(a2)",
            $" Z=r*sin(a1)"
            );

        face.ApplySpaceWarp(warp);

        if (cutAngle == 0)
        {
            Vertex corner = structure.CreateVertex();
            structure.CreateFace(face, false, corner, corner, corner, corner);
        }
        else
        {
            SurfaceComponentGeometry cap1 = SurfaceComponentGeometries.CreateRegularPolygonGeometry(barRadius, segmentBar, 2);
            SurfaceComponentGeometry cap2 = SurfaceComponentGeometries.CreateRegularPolygonGeometry(barRadius, segmentBar, 2);
            cap1.ApplyRotation(Quaternion.LookRotation(Vector3.down, Vector3.back) * Quaternion.AngleAxis(-deltaAngle, Vector3.up));
            cap1.ApplyOffset(Vector3.right * ringRadius);
            cap2.ApplyRotation(Quaternion.LookRotation(Vector3.up, Quaternion.AngleAxis(cutAngle * Mathf.Rad2Deg, Vector3.up) * Vector3.forward) * Quaternion.AngleAxis(deltaAngle * Mathf.Rad2Deg, Vector3.up));
            cap2.ApplyOffset(new Vector3(ringRadius * Mathf.Cos(cutAngle), 0, -ringRadius * Mathf.Sin(cutAngle)));

            Vertex corner1 = structure.CreateVertex();
            Vertex corner2 = structure.CreateVertex();
            structure.CreateFace(face, false, corner1, corner2, corner2, corner1);
            structure.CreateFace(cap1, false, corner1);
            structure.CreateFace(cap2, false, corner2);
        }
        return(structure.Build());
    }
예제 #7
0
    private static void CreateStraightPlatformPart(
        StructureGeometry structure,
        Vertex cornerTopLeft1, Vertex cornerTopLeft2, Vertex cornerTopRight1, Vertex cornerTopRight2,
        Vertex cornerBottomLeft1, Vertex cornerBottomLeft2, Vertex cornerBottomRight1, Vertex cornerBottomRight2,
        bool addLeftSide, bool addRightSide, int segmentLength, RenderGeometry.FaceType sideFaceType)
    {
        SurfaceComponentGeometry topFace    = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentLength, 0, sideFaceType);
        SurfaceComponentGeometry bottomFace = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentLength, 1, sideFaceType);

        if (cornerTopLeft1 == cornerBottomLeft1)
        {
            // Copy vertices since it is a flat face.
            Vertex cornerLeft1  = structure.CreateVertex(cornerBottomLeft1.p);
            Vertex cornerLeft2  = structure.CreateVertex(cornerBottomLeft2.p);
            Vertex cornerRight1 = structure.CreateVertex(cornerBottomRight1.p);
            Vertex cornerRight2 = structure.CreateVertex(cornerBottomRight2.p);
            structure.CreateFace(topFace, true, cornerLeft1, cornerLeft2, cornerRight2, cornerRight1);
            structure.CreateFace(bottomFace, true, cornerRight1, cornerRight2, cornerLeft2, cornerLeft1);
        }
        else
        {
            SurfaceComponentGeometry backFace  = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, 1, 4, RenderGeometry.FaceType.Polygonal);
            SurfaceComponentGeometry frontFace = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, 1, 5, RenderGeometry.FaceType.Polygonal);
            structure.CreateFace(topFace, true, cornerTopLeft1, cornerTopLeft2, cornerTopRight2, cornerTopRight1);
            structure.CreateFace(bottomFace, true, cornerBottomRight1, cornerBottomRight2, cornerBottomLeft2, cornerBottomLeft1);
            structure.CreateFace(backFace, true, cornerBottomLeft1, cornerTopLeft1, cornerTopRight1, cornerBottomRight1);
            structure.CreateFace(frontFace, true, cornerBottomRight2, cornerTopRight2, cornerTopLeft2, cornerBottomLeft2);

            if (addLeftSide)
            {
                SurfaceComponentGeometry leftFace = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentLength, 2, sideFaceType);
                structure.CreateFace(leftFace, true, cornerBottomLeft1, cornerBottomLeft2, cornerTopLeft2, cornerTopLeft1);
            }
            if (addRightSide)
            {
                SurfaceComponentGeometry rightFace = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentLength, 3, sideFaceType);
                structure.CreateFace(rightFace, true, cornerTopRight1, cornerTopRight2, cornerBottomRight2, cornerBottomRight1);
            }
        }
    }
예제 #8
0
    public static SurfaceComponentGeometry CreateAlternatingDiagonalSplitSquareGeometry(
        float sizeX, float sizeZ, int segmentX, int segmentZ, int surfaceGroup = 0, RenderGeometry.FaceType faceType = RenderGeometry.FaceType.Polygonal)
    {
        var geometry = SurfaceComponentGeometries.CreatePlaneGeometry(sizeX, sizeZ, segmentX, segmentZ, surfaceGroup, faceType);

        foreach (Face face in new List <Face>(geometry.faces))
        {
            List <Halfedge> edges     = face.edges;
            Vector3         facePoint = edges[0].prev.vertex.p;
            int             x         = Mathf.RoundToInt((facePoint.x - sizeX / 2) / (sizeX / segmentX));
            int             z         = Mathf.RoundToInt((facePoint.z - sizeZ / 2) / (sizeZ / segmentZ));
            if ((x + z) % 2 == 0)
            {
                geometry.SplitFace(edges[0].vertex, edges[2].vertex);
            }
            else
            {
                geometry.SplitFace(edges[1].vertex, edges[3].vertex);
            }
        }
        return(geometry);
    }
예제 #9
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;
    }
    public static RenderGeometry CreateCylinderGeometry(float radius, float height, int segmentP, int segmentH, bool smoothH, bool smoothV, float cutAngle = 0, float hollowRatio = 0)
    {
        StructureGeometry structure = new StructureGeometry();

        RenderGeometry.FaceType faceType = GetFaceType(smoothH, smoothV);
        float hollowRadius = hollowRatio * radius;

        SurfaceComponentGeometry side      = SurfaceComponentGeometries.CreateCylinderSideGeometry(radius, height, segmentP, segmentH, cutAngle, false, 1, faceType);
        SurfaceComponentGeometry sideInner = null;

        if (hollowRatio > 0)
        {
            sideInner = SurfaceComponentGeometries.CreateCylinderSideGeometry(hollowRadius, height, segmentP, segmentH, cutAngle, true, 1, faceType);
        }
        SurfaceComponentGeometry upperCap, lowerCap;

        if (hollowRatio > 0)
        {
            upperCap = SurfaceComponentGeometries.CreateRingCapGeometry(radius, hollowRadius, segmentP, 1, cutAngle, 2);
            lowerCap = SurfaceComponentGeometries.CreateRingCapGeometry(radius, hollowRadius, segmentP, 1, cutAngle, 2);
        }
        else if (cutAngle == 0)
        {
            upperCap = SurfaceComponentGeometries.CreateRegularPolygonGeometry(radius, segmentP, 2);
            lowerCap = SurfaceComponentGeometries.CreateRegularPolygonGeometry(radius, segmentP, 2);
        }
        else
        {
            upperCap = SurfaceComponentGeometries.CreateFanCapGeometry(radius, segmentP, 1, cutAngle, 2);
            lowerCap = SurfaceComponentGeometries.CreateFanCapGeometry(radius, segmentP, 1, cutAngle, 2);
        }
        lowerCap.ApplyRotation(Quaternion.AngleAxis(cutAngle * Mathf.Rad2Deg, Vector3.up) * Quaternion.AngleAxis(180, Vector3.right));

        if (cutAngle == 0)
        {
            Vertex cornerUp   = structure.CreateVertex(new Vector3(radius, height / 2, 0));
            Vertex cornerDown = structure.CreateVertex(new Vector3(radius, -height / 2, 0));
            if (hollowRatio == 0)
            {
                structure.CreateFace(side, false, cornerUp, cornerUp, cornerDown, cornerDown);
                structure.CreateFace(upperCap, true, cornerUp);
                structure.CreateFace(lowerCap, true, cornerDown);
            }
            else
            {
                Vertex cornerUpInner   = structure.CreateVertex(new Vector3(hollowRadius, height / 2, 0));
                Vertex cornerDownInner = structure.CreateVertex(new Vector3(hollowRadius, -height / 2, 0));
                structure.CreateFace(side, false, cornerUp, cornerUp, cornerDown, cornerDown);
                structure.CreateFace(sideInner, false, cornerDownInner, cornerDownInner, cornerUpInner, cornerUpInner);
                structure.CreateFace(upperCap, true, cornerUpInner, cornerUpInner, cornerUp, cornerUp);
                structure.CreateFace(lowerCap, true, cornerDownInner, cornerDownInner, cornerDown, cornerDown);
            }
        }
        else
        {
            SurfaceComponentGeometry wall1 = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentH, 3);
            SurfaceComponentGeometry wall2 = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentH, 4);

            Vertex cornerUp1   = structure.CreateVertex(new Vector3(radius * Mathf.Cos(cutAngle), height / 2, -radius * Mathf.Sin(cutAngle)));
            Vertex cornerUp2   = structure.CreateVertex(new Vector3(radius, height / 2, 0));
            Vertex cornerDown1 = structure.CreateVertex(new Vector3(radius * Mathf.Cos(cutAngle), -height / 2, -radius * Mathf.Sin(cutAngle)));
            Vertex cornerDown2 = structure.CreateVertex(new Vector3(radius, -height / 2, 0));
            if (hollowRatio == 0)
            {
                Vertex cornerUpC   = structure.CreateVertex(new Vector3(0, height / 2, 0));
                Vertex cornerDownC = structure.CreateVertex(new Vector3(0, -height / 2, 0));
                structure.CreateFace(side, false, cornerUp2, cornerUp1, cornerDown1, cornerDown2);
                structure.CreateFace(upperCap, true, cornerUp1, cornerUp2, cornerUpC);
                structure.CreateFace(lowerCap, true, cornerDown2, cornerDown1, cornerDownC);
                structure.CreateFace(wall1, true, cornerUpC, cornerDownC, cornerDown1, cornerUp1);
                structure.CreateFace(wall2, true, cornerDownC, cornerUpC, cornerUp2, cornerDown2);
            }
            else
            {
                Vertex cornerUp1Inner   = structure.CreateVertex(new Vector3(hollowRadius * Mathf.Cos(cutAngle), height / 2, -hollowRadius * Mathf.Sin(cutAngle)));
                Vertex cornerUp2Inner   = structure.CreateVertex(new Vector3(hollowRadius, height / 2, 0));
                Vertex cornerDown1Inner = structure.CreateVertex(new Vector3(hollowRadius * Mathf.Cos(cutAngle), -height / 2, -hollowRadius * Mathf.Sin(cutAngle)));
                Vertex cornerDown2Inner = structure.CreateVertex(new Vector3(hollowRadius, -height / 2, 0));
                structure.CreateFace(side, false, cornerUp2, cornerUp1, cornerDown1, cornerDown2);
                structure.CreateFace(sideInner, false, cornerDown2Inner, cornerDown1Inner, cornerUp1Inner, cornerUp2Inner);
                structure.CreateFace(upperCap, true, cornerUp2Inner, cornerUp1Inner, cornerUp1, cornerUp2);
                structure.CreateFace(lowerCap, true, cornerDown1Inner, cornerDown2Inner, cornerDown2, cornerDown1);
                structure.CreateFace(wall1, true, cornerUp1Inner, cornerDown1Inner, cornerDown1, cornerUp1);
                structure.CreateFace(wall2, true, cornerDown2Inner, cornerUp2Inner, cornerUp2, cornerDown2);
            }
        }
        return(structure.Build());
    }
 public static RenderGeometry CreateCubeGeometry(Vector3 size, int[] segments)
 {
     return(CreateCubeGeometryInternal(size, dim => SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, segments[(dim + 2) % 3], segments[(dim + 1) % 3], dim)));
 }
예제 #12
0
    private static void CreateStraightRampPart(
        StructureGeometry structure, bool isLeftRamp,
        Vertex cornerTopLeft1, Vertex cornerTopLeft2, Vertex cornerTopRight1, Vertex cornerTopRight2,
        Vertex cornerBottomLeft1, Vertex cornerBottomLeft2, Vertex cornerBottomRight1, Vertex cornerBottomRight2,
        bool addLeftSide, bool addRightSide, int segmentWidth, int segmentLength, float curvature, RenderGeometry.FaceType rampFaceType, RenderGeometry.FaceType sideFaceType)
    {
        bool hasBase = (cornerTopLeft1 != cornerBottomLeft1) && (cornerTopRight1 != cornerBottomRight1);

        SurfaceComponentGeometry rampFace = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, segmentWidth, segmentLength, 0, rampFaceType);
        SurfaceComponentGeometry rampBottom = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentLength, 1, sideFaceType);
        SurfaceComponentGeometry rampLeftSide = null, rampRightSide = null;

        if (addLeftSide && (cornerTopLeft1 != cornerBottomLeft1))
        {
            rampLeftSide = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentLength, 2, sideFaceType);
        }
        if (addRightSide && (cornerTopRight1 != cornerBottomRight1))
        {
            rampRightSide = SurfaceComponentGeometries.CreatePlaneGeometry(1, 1, 1, segmentLength, 3, sideFaceType);
        }

        if (curvature != 0)
        {
            float angle = -curvature * Mathf.PI / 2;
            rampFace.ApplySpaceWarp(new SpaceWarp($"sin(x*{angle})/{angle}", $"(1-cos(x*{angle}))/{angle}", "z"));
        }
        // Fit to a 45 degree ramp, then scale.
        rampFace.ApplyLinearTransform(
            Matrix4x4.Translate(cornerTopLeft1.p) *
            Matrix4x4.Scale(VectorUtil.Abs(cornerTopRight2.p - cornerTopLeft1.p)) *
            MatrixUtil.PointToPointTransform(
                rampFace.corners[0].p, rampFace.corners[3].p, rampFace.corners[1].p,
                Vector3.zero, new Vector3(1, isLeftRamp ? 1 : -1, 0), Vector3.forward));

        structure.CreateFace(rampFace, false, cornerTopLeft1, cornerTopLeft2, cornerTopRight2, cornerTopRight1);
        structure.CreateFace(rampBottom, true, cornerBottomRight1, cornerBottomRight2, cornerBottomLeft2, cornerBottomLeft1);
        if (rampLeftSide != null)
        {
            structure.CreateFace(rampLeftSide, true, cornerBottomLeft1, cornerBottomLeft2, cornerTopLeft2, cornerTopLeft1);
        }
        if (rampRightSide != null)
        {
            structure.CreateFace(rampRightSide, true, cornerTopRight1, cornerTopRight2, cornerBottomRight2, cornerBottomRight1);
        }

        var backVertices = new List <Vector3>();

        backVertices.Add(isLeftRamp ? cornerBottomRight1.p : cornerBottomLeft1.p);
        if (isLeftRamp && hasBase)
        {
            backVertices.Add(cornerBottomLeft1.p);
        }
        backVertices.Add(rampFace.boundaries[3].Last().prev.vertex.p);
        backVertices.AddRange(rampFace.boundaries[3].Select(e => e.vertex.p).Reverse());
        if (!isLeftRamp && hasBase)
        {
            backVertices.Add(cornerBottomRight1.p);
        }
        var movedBackVertices = backVertices.Select(p => p + (cornerTopLeft2.p - cornerTopLeft1.p));
        var frontVertices = movedBackVertices.Take(1).Concat(movedBackVertices.Reverse().Take(backVertices.Count - 1)).ToList();

        SurfaceComponentGeometry backFace  = SurfaceComponentGeometries.CreateStarConvexPolygonGeometry(backVertices, 4, RenderGeometry.FaceType.Smooth);
        SurfaceComponentGeometry frontFace = SurfaceComponentGeometries.CreateStarConvexPolygonGeometry(frontVertices, 5, RenderGeometry.FaceType.Smooth);

        if (hasBase)
        {
            if (isLeftRamp)
            {
                backFace.CombineBoundaries(1, 1, segmentWidth, 1);
                frontFace.CombineBoundaries(1, segmentWidth, 1, 1);
                structure.CreateFace(backFace, false, cornerBottomRight1, cornerBottomLeft1, cornerTopLeft1, cornerTopRight1);
                structure.CreateFace(frontFace, false, cornerBottomRight2, cornerTopRight2, cornerTopLeft2, cornerBottomLeft2);
            }
            else
            {
                backFace.CombineBoundaries(1, segmentWidth, 1, 1);
                frontFace.CombineBoundaries(1, 1, segmentWidth, 1);
                structure.CreateFace(backFace, false, cornerBottomLeft1, cornerTopLeft1, cornerTopRight1, cornerBottomRight1);
                structure.CreateFace(frontFace, false, cornerBottomLeft2, cornerBottomRight2, cornerTopRight2, cornerTopLeft2);
            }
        }
        else
        {
            backFace.CombineBoundaries(1, segmentWidth, 1);
            frontFace.CombineBoundaries(1, segmentWidth, 1);
            structure.CreateFace(backFace, false, isLeftRamp ? cornerBottomRight1 : cornerBottomLeft1, cornerTopLeft1, cornerTopRight1);
            structure.CreateFace(frontFace, false, isLeftRamp ? cornerBottomRight2 : cornerBottomLeft2, cornerTopRight2, cornerTopLeft2);
        }
    }
예제 #13
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));
        }