Example #1
0
    public static SurfaceComponentGeometry CreateTrianglesCombinedRegularPolygonGeometry(float radius, int segmentP, Func <SurfaceComponentGeometry> triangleSurfaceComponentProvider)
    {
        SurfaceComponentGeometry polygonGeometry = SurfaceComponentGeometries.CreateFanCapGeometry(radius, segmentP, 1);

        polygonGeometry.SplitBoundaries();
        List <Vertex> corners = polygonGeometry.corners;

        var structure = new StructureGeometry(polygonGeometry);

        structure.faces.ForEach(f => structure.SetFaceComponent(f, triangleSurfaceComponentProvider(), true));
        var geometry = new SurfaceComponentGeometry(structure.Build());

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

        return(geometry);
    }
    public static RenderGeometry CreateConeGeometry(float radius, float height, int segmentP, int segmentH, bool smoothH, bool smoothV, float cutTop = 0, float cutAngle = 0)
    {
        if (cutTop == 0)
        {
            StructureGeometry       structure = new StructureGeometry();
            RenderGeometry.FaceType faceType  = GetFaceType(smoothH, smoothV);

            SurfaceComponentGeometry coneCap = SurfaceComponentGeometries.CreateConeCapGeometry(radius, height, segmentP, segmentH, cutAngle, 1, faceType);
            if (cutAngle == 0)
            {
                SurfaceComponentGeometry bottom = SurfaceComponentGeometries.CreateRegularPolygonGeometry(radius, segmentP, 2);
                bottom.ApplyRotation(Quaternion.AngleAxis(180, Vector3.right));

                Vertex corner = structure.CreateVertex();
                structure.CreateFace(coneCap, false, corner);
                structure.CreateFace(bottom, false, corner);
            }
            else
            {
                SurfaceComponentGeometry bottom = SurfaceComponentGeometries.CreateFanCapGeometry(radius, segmentP, 1, cutAngle, 2);
                SurfaceComponentGeometry wall1  = SurfaceComponentGeometries.CreateTriangleGeometry(1, 1, 0, segmentH, true, 3);
                SurfaceComponentGeometry wall2  = SurfaceComponentGeometries.CreateTriangleGeometry(1, 1, 0, segmentH, true, 4);

                Vertex cornerUp    = structure.CreateVertex(new Vector3(0, height, 0));
                Vertex cornerDownC = structure.CreateVertex(Vector3.zero);
                Vertex cornerDown1 = structure.CreateVertex(new Vector3(radius * Mathf.Cos(cutAngle), 0, -radius * Mathf.Sin(cutAngle)));
                Vertex cornerDown2 = structure.CreateVertex(new Vector3(radius, 0, 0));

                structure.CreateFace(coneCap, true, cornerDown1, cornerDown2, cornerUp);
                structure.CreateFace(bottom, true, cornerDown2, cornerDown1, cornerDownC);
                structure.CreateFace(wall1, true, cornerDown1, cornerUp, cornerDownC);
                structure.CreateFace(wall2, true, cornerDownC, cornerUp, cornerDown2);
            }
            return(structure.Build());
        }
        else
        {
            RenderGeometry geometry = CreateCylinderGeometry(radius, height, segmentP, segmentH, smoothH, smoothV, cutAngle);
            geometry.ApplyOffset(Vector3.up * (height / 2));

            float     shrinkCoeff = (1 - cutTop) / height;
            SpaceWarp warp        = new SpaceWarp($"x*(1-y*{shrinkCoeff})", "y", $"z*(1-y*{shrinkCoeff})");
            geometry.ApplySpaceWarp(warp);
            return(geometry);
        }
    }
Example #3
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());
    }