예제 #1
0
 public MeshXController(MainForm topform, MeshX item, FileController targetFile) : base(topform, item, targetFile)
 {
     Data = item;
     AddMenu("Open mesh viewer", Menu_OpenViewer);
     IsLoaded = false;
     //LoadMeshData(); TODO preferences
 }
예제 #2
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;
        }
    }
예제 #3
0
파일: CityGen.cs 프로젝트: nothke/Muprox
    void Generate()
    {
        // create meshes
        foreach (var plot in city.plots)
        {
            if (Random.value < 0.3f)
            {
                plot.type = Plot.Type.Water;
            }

            if (plot.type == Plot.Type.Water)
            {
                continue;
            }

            Mesh       quad   = MeshX.Quad(Vector3.zero, tileSize - streetWidth, tileSize - streetWidth, Vector3.up);
            GameObject plotGO = gameObject.InitializeSeparateMesh(quad, plotMat);
            plotGO.AddComponent <MeshCollider>();

            plotGO.transform.localPosition = plot.Position() * tileSize;

            PlaceBuildings(plot);
        }

        DoStreets(city.horizontalStreets);
        DoStreets(city.verticalStreets);

        foreach (var corner in city.corners)
        {
            if (!corner.HasNeighbourStreets())
            {
                continue;
            }

            Mesh       quad     = MeshX.Quad(Vector3.zero, streetWidth, streetWidth, Vector3.up);
            GameObject cornerGO = gameObject.InitializeSeparateMesh(quad, cornerMat);

            cornerGO.transform.localPosition = corner.Position() * tileSize;
            cornerGO.AddComponent <MeshCollider>();
        }

        float dist = (tileSize - streetWidth) / 2;
    }
예제 #4
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);
    }
예제 #5
0
    void Start()
    {
        Mesh mesh = new Mesh();

        bounds = GetComponent <Renderer>().bounds;

        List <Vector3> v3s = new List <Vector3>();

        for (int i = 0; i < numOfPoints; i++)
        {
            Vector3 v1 = RandomPointsOnBoundsTop(bounds);

            RaycastHit hit;
            Physics.Raycast(v1, Vector3.down, out hit, Mathf.Infinity);

            if (hit.point == null)
            {
                continue;
            }

            v3s.Add(hit.point);
        }

        mesh.SetVertices(v3s);

        List <int> tris = new List <int>();

        for (int i = 0; i < v3s.Count; i++)
        {
            tris.Add(i);
            tris.Add(i);
            tris.Add(i);
        }

        mesh.SetTriangles(tris, 0);

        go = MeshX.InitializeSeparateMesh(gameObject, mesh, grassMat);
    }
예제 #6
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);
    }
예제 #7
0
 void Start()
 {
     gameObject.InitializeMesh(MeshX.Stairs(stairsNum, stepWidth, stepHeight, stepDepth));
 }
예제 #8
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()));
    }