예제 #1
0
파일: CityGen.cs 프로젝트: nothke/Muprox
    void DoStreets(Street[,] streets)
    {
        float dist = (tileSize - streetWidth) / 2;

        foreach (var street in streets)
        {
            street.exists = Random.value > 0.2f;

            Plot leftPlot  = street.isNS ? street.E as Plot : street.S as Plot;
            Plot rightPlot = street.isNS ? street.W as Plot : street.N as Plot;

            bool surrounded = false;

            if ((leftPlot && leftPlot.type != Plot.Type.Water) ||
                (rightPlot && rightPlot.type != Plot.Type.Water))
            {
                surrounded = true;
            }

            if (!surrounded)
            {
                street.exists = false;
                continue;
            }

            Mesh mesh = null;

            Material mat;

            if (!street.exists)
            {
                float width  = street.isNS ? streetWidth : tileSize - streetWidth;
                float height = street.isNS ? tileSize - streetWidth : streetWidth;

                mesh = MeshX.Quad(Vector3.zero, width, height, Vector3.up);
                mat  = plotMat;
            }
            else
            {
                Vector3   direction = street.isNS ? Vector3.forward : Vector3.right;
                Vector3[] points    = new Vector3[] { direction * -dist, direction *dist };


                Shape leftShape  = GetShape(leftPlot);
                Shape rightShape = GetShape(rightPlot);

                Mesh streetMeshR = MeshX.Sweep(leftShape.GetPoints2D(), points);
                Mesh streetMeshL = MeshX.Sweep(rightShape.GetPoints2DMirrored(), points);

                mesh = MeshX.Combine(new Mesh[] { streetMeshL, streetMeshR });
                mat  = streetMat;
            }

            GameObject streetGO = gameObject.InitializeSeparateMesh(mesh, mat);
            streetGO.AddComponent <MeshCollider>();

            streetGO.transform.position = street.Position() * tileSize;
        }
    }
예제 #2
0
    public static Mesh Stairwell(float stepWidth, float length, float floorHeight, float slabDepth, float separation, float slabThickness = 0.3f)
    {
        List <Mesh> meshes = new List <Mesh>();

        float hH = floorHeight / 2;
        float y  = 0;

        float stairLength = length - 2 * slabDepth;

        // STAIRS

        Mesh leftFlight  = MeshX.StairsBounds(stepWidth, hH, stairLength, true, 0.18f);
        Mesh rightFlight = MeshX.StairsBounds(stepWidth, hH, stairLength, true, 0.18f);

        leftFlight.Translate(new Vector3(0, y, slabDepth));

        rightFlight.Rotate(180, Vector3.up);
        rightFlight.Translate(new Vector3(stepWidth + separation, y + hH, length - slabDepth));

        // SLABS

        Mesh backSlab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth));

        backSlab.Translate(new Vector3((stepWidth + separation) / 2, y + hH - slabThickness / 2, length - (slabDepth / 2)));

        Mesh frontSlab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth));

        frontSlab.Translate(new Vector3((stepWidth + separation) / 2, y - slabThickness / 2, slabDepth / 2));

        meshes.Add(leftFlight);
        meshes.Add(rightFlight);
        meshes.Add(backSlab);
        meshes.Add(frontSlab);

        Mesh combined = MeshX.Combine(meshes.ToArray());

        return(combined);
    }
예제 #3
0
    void OnValidate()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        if (!stairWell)
        {
            if (!total)
            {
                gameObject.SetMesh(MeshX.Stairs(stairsNum, stepWidth, stepHeight, stepDepth));
            }
            else
            {
                gameObject.SetMesh(MeshX.StairsBounds(stepWidth, totalHeight, totalDepth));
            }
        }

        if (!stairWell)
        {
            return;
        }

        //floors = 1;

        if (floors < 1)
        {
            return;
        }

        Mesh combined = null;

        List <Mesh> meshes = new List <Mesh>();

        float hH = floorHeight / 2;

        for (int f = 0; f < floors; f++)
        {
            float y = f * floorHeight;


            Mesh leftFlight  = MeshX.StairsBounds(stepWidth, hH, totalDepth);
            Mesh rightFlight = MeshX.StairsBounds(stepWidth, hH, totalDepth);

            leftFlight.Translate(new Vector3(0, y));

            rightFlight.Rotate(180, Vector3.up);
            rightFlight.Translate(new Vector3(stepWidth + separation, y + hH, totalDepth));

            float slabThickness = 0.3f;

            Mesh slab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth));
            slab.Translate(new Vector3((stepWidth + separation) / 2, y + hH - slabThickness / 2, totalDepth + (slabDepth / 2)));


            meshes.Add(leftFlight);
            meshes.Add(rightFlight);
            meshes.Add(slab);
        }

        combined = MeshX.Combine(meshes.ToArray());
        gameObject.SetMesh(combined);
    }
예제 #4
0
    void Generate()
    {
        gameObject.InitializeMesh(null, null);

        List <Mesh> meshes = new List <Mesh>();

        float totalHeight = floorHeight * floors;
        float totalX      = xWidth * xNum;
        float totalZ      = zWidth * zNum;

        Vector3 start = new Vector3(-xWidth / 2, 0, -zWidth / 2);
        Vector3 mid   = new Vector3((-xWidth / 2) + xWidth * xNum / 2, 0, (-zWidth / 2) + zWidth * zNum / 2);

        // Columns
        for (int x = -1; x < xNum; x++)
        {
            for (int z = -1; z < zNum; z++)
            {
                Mesh column = MeshX.Cube(new Vector3(columnWidth, totalHeight - floorHeight, columnWidth));
                column.Translate(-start + new Vector3(x * xWidth + xWidth / 2, (totalHeight - floorHeight) / 2, z * zWidth + zWidth / 2));

                meshes.Add(column);
            }
        }



        for (int f = 0; f < floors; f++)
        {
            float y = f * floorHeight;

            // Slab
            for (int x = 0; x < xNum; x++)
            {
                for (int z = 0; z < zNum; z++)
                {
                    if (x == stairWellX && z == stairWellZ)
                    {
                        continue;
                    }

                    Mesh slab = MeshX.Cube(new Vector3(xWidth, slabThickness, zWidth));
                    slab.Translate(-start + new Vector3(x * xWidth, y - slabThickness * 0.5f, z * zWidth));

                    meshes.Add(slab);
                }
            }

            // Parapet

            if (f > 0)
            {
                Mesh parapetUp    = MeshX.Cube(new Vector3(totalX, parapetHeight, parapetWidth));
                Mesh parapetDown  = MeshX.Cube(new Vector3(totalX, parapetHeight, parapetWidth));
                Mesh parapetLeft  = MeshX.Cube(new Vector3(parapetWidth, parapetHeight, totalZ));
                Mesh parapetRight = MeshX.Cube(new Vector3(parapetWidth, parapetHeight, totalZ));

                parapetUp.Translate(-start + mid + new Vector3(0, y, totalZ / 2));
                parapetDown.Translate(-start + mid + new Vector3(0, y, -totalZ / 2));
                parapetLeft.Translate(-start + mid + new Vector3(-totalX / 2, y, 0));
                parapetRight.Translate(-start + mid + new Vector3(+totalX / 2, y, 0));

                meshes.Add(parapetUp);
                meshes.Add(parapetDown);
                meshes.Add(parapetLeft);
                meshes.Add(parapetRight);
            }

            // Stairs

            if (f == floors - 1)
            {
                continue;
            }

            float stairSeparation = xWidth - 1.2f * 2;

            Mesh stairs = MeshXBuildings.Stairwell(1.2f, zWidth, floorHeight, 1.2f, stairSeparation, slabThickness);
            stairs.Translate(new Vector3(stairWellX * xWidth + 0.6f, y, stairWellZ * zWidth));

            meshes.Add(stairs);
        }

        gameObject.SetMesh(MeshX.Combine(meshes.ToArray()));
    }