void Start()
    {
        meshFilter = GetComponent <MeshFilter>();
        switch (shape)
        {
        case PGMesh.Shape.Triangle:
            meshFilter.sharedMesh = PGMesh.Triangle(Vector3.left / 2 + Vector3.down / 2, Vector3.up, Vector3.right / 2 + Vector3.down / 2);
            break;

        case PGMesh.Shape.Quad:
            meshFilter.sharedMesh = PGMesh.Quad(Vector3.left / 2 + Vector3.down / 2, Vector3.right, Vector3.up);
            break;

        case PGMesh.Shape.Plane:
            meshFilter.sharedMesh = PGMesh.Plane(Vector3.left / 2 + Vector3.down / 2, Vector3.right, Vector3.up, 1, 3);
            break;

        case PGMesh.Shape.Tetrahedron:
            meshFilter.sharedMesh = PGMesh.Tetrahedron(1);
            break;

        case PGMesh.Shape.Cube:
            meshFilter.sharedMesh = PGMesh.Cube(1);
            break;

        case PGMesh.Shape.Octahedron:
            meshFilter.sharedMesh = PGMesh.Octahedron(1);
            break;

        case PGMesh.Shape.Icosahedron:
            meshFilter.sharedMesh = PGMesh.Icosahedron(1);
            break;
        }
    }
예제 #2
0
    void Start()
    {
        meshFilter = GetComponent <MeshFilter>();

        var combine = new CombineInstance[count];

        for (int i = 0; i < count; i++)
        {
            var offset = Random.onUnitSphere * radius;
            combine[i].mesh = PGMesh.Triangle(offset + Random.onUnitSphere, offset + Random.onUnitSphere, offset + Random.onUnitSphere);
        }

        var mesh = new Mesh();

        mesh.CombineMeshes(combine, true, false);
        meshFilter.sharedMesh = mesh;
    }
예제 #3
0
    Mesh BalconyPanel(Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3)
    {
        var normal = Vector3.Cross((v1 - v0), (v3 - v0)).normalized;
        var v4     = v0 + (v1 - v0) * 0.4f;
        var v5     = v3 + (v2 - v3) * 0.4f;

        var combine     = new List <Mesh>();
        var submeshMask = new List <List <int> >();

        combine.Add(PGMesh.Quad(v0, v4, v4 + normal, v0 + normal));
        submeshMask.Add(new List <int> {
            0
        });
        combine.Add(PGMesh.Quad(v0 + normal, v4 + normal, v5 + normal, v3 + normal));
        submeshMask.Add(new List <int> {
            0
        });
        combine.Add(PGMesh.Quad(v3 + normal, v5 + normal, v5, v3));
        submeshMask.Add(new List <int> {
            0
        });
        combine.Add(PGMesh.Quad(v0, v0 + normal, v3 + normal, v3));
        submeshMask.Add(new List <int> {
            0
        });

        combine.Add(PGMesh.Quad(v4, v1, v1 + normal, v4 + normal));
        submeshMask.Add(new List <int> {
            1
        });
        combine.Add(PGMesh.Quad(v4 + normal, v1 + normal, v2 + normal, v5 + normal));
        submeshMask.Add(new List <int> {
            1
        });
        combine.Add(PGMesh.Quad(v5 + normal, v2 + normal, v2, v5));
        submeshMask.Add(new List <int> {
            1
        });

        combine.Add(PGMesh.Quad(v2, v2 + normal, v1 + normal, v1));
        submeshMask.Add(new List <int> {
            0
        });

        return(PGMesh.CombineMeshes(combine));
    }
예제 #4
0
    void GenerateBuilding()
    {
        width                     = random.Next(10, 13);
        length                    = random.Next(30, 55);
        floors                    = random.Next(1, 7);
        entrances                 = (int)(length / 10 - 1);
        height                    = ceilingHeight * floors + socleHeight;
        entranceMeshIndex         = random.Next(entrance25.Count);
        entranceWallMeshIndex     = random.Next(entranceWall25.Count);
        entranceWallLastMeshIndex = random.Next(entranceWallLast25.Count);
        attic                     = Random.value > 0.5f;
        var roofHeight = Vector3.up * height;

        if (attic)
        {
            roofHeight += Vector3.up;
        }
        roofType = RandomItem(new List <RoofType> {
            RoofType.Flat, RoofType.FlatOverhang, RoofType.Gabled, RoofType.Hipped
        });

        var corner0 = Vector3.back * width / 2 + Vector3.left * length / 2;
        var corner1 = Vector3.forward * width / 2 + Vector3.left * length / 2;
        var corner2 = Vector3.forward * width / 2 + Vector3.right * length / 2;
        var corner3 = Vector3.back * width / 2 + Vector3.right * length / 2;

        var wallSizes0    = ExteriorWallSizes(width);
        var panelPattern0 = FacadePattern(wallSizes0.Count, floors, attic);
        var wallSizes1    = ExteriorWallSizes(length);
        var panelPattern1 = FacadePattern(wallSizes1.Count, floors, attic, true);
        var wallSizes2    = ExteriorWallSizes(width);
        var panelPattern2 = FacadePattern(wallSizes2.Count, floors, attic);
        var wallSizes3    = ExteriorWallSizes(length);
        var panelPattern3 = FacadePattern(wallSizes3.Count, floors, attic, true, entrances);

        var combine  = new List <Mesh>();
        var matrices = new List <Matrix4x4>();

        combine.Add(Facade(corner0, Vector3.forward, wallSizes0, panelPattern0));
        matrices.Add(Matrix4x4.identity);
        combine.Add(Facade(corner1, Vector3.right, wallSizes1, panelPattern1));
        matrices.Add(Matrix4x4.identity);
        combine.Add(Facade(corner2, Vector3.back, wallSizes2, panelPattern2));
        matrices.Add(Matrix4x4.identity);
        combine.Add(Facade(corner3, Vector3.left, wallSizes3, panelPattern3));
        matrices.Add(Matrix4x4.identity);
        switch (roofType)
        {
        case RoofType.Flat:
            combine.Add(RandomItem(roofFlat));
            matrices.Add(Matrix4x4.TRS(roofHeight, Quaternion.identity, new Vector3(length, 1, width)));
            break;

        case RoofType.FlatOverhang:
            combine.Add(RandomItem(roofFlat));
            matrices.Add(Matrix4x4.TRS(roofHeight, Quaternion.identity, new Vector3(length + 1, 1, width + 1)));
            break;

        case RoofType.Gabled:
            combine.Add(RandomItem(roofGabled));
            matrices.Add(Matrix4x4.TRS(roofHeight, Quaternion.identity, new Vector3(length, 1, width + 1)));
            break;

        case RoofType.Hipped:
            combine.Add(RandomItem(roofHipped));
            matrices.Add(Matrix4x4.TRS(roofHeight, Quaternion.identity, new Vector3(length + 1, 1, width + 1)));
            break;
        }

        meshFilter.mesh.Clear();
        meshFilter.mesh = PGMesh.CombineMeshes(combine, matrices);
        meshFilter.mesh.RecalculateBounds();
        meshFilter.mesh.Optimize();
        renderer.material.color = new Color(Random.value, Random.value, Random.value);
    }
예제 #5
0
    Mesh Facade(Vector3 origin, Vector3 direction, List <float> wallSizes, List <List <PanelType> > panelPattern)
    {
        var floorMeshes  = new List <Mesh>();
        var facadeMeshes = new List <Mesh>();
        var matrices     = new List <Matrix4x4>();
        var panelOrigin  = origin;

        for (var i = 0; i < panelPattern.Count; i++)
        {
            for (var j = 0; j < panelPattern[i].Count; j++)
            {
                if (Mathf.Abs(wallSizes[j] - 2.5f) < Mathf.Epsilon)
                {
                    switch (panelPattern[i][j])
                    {
                    case PanelType.Window:
                        floorMeshes.Add(RandomItem(window25));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Balcony:
                        floorMeshes.Add(RandomItem(balcony25));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Wall:
                        floorMeshes.Add(RandomItem(wall25));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Socle:
                        floorMeshes.Add(RandomItem(socle25));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Entrance:
                        floorMeshes.Add(entrance25[entranceMeshIndex]);
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.EntranceWall:
                        floorMeshes.Add(entranceWall25[entranceWallMeshIndex]);
                        matrices.Add(Matrix4x4.TRS(panelOrigin + Vector3.up * (ceilingHeight - socleHeight), Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.EntranceWallLast:
                        floorMeshes.Add(entranceWallLast25[entranceWallLastMeshIndex]);
                        matrices.Add(Matrix4x4.TRS(panelOrigin + Vector3.up * (ceilingHeight - socleHeight), Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Attic:
                        floorMeshes.Add(RandomItem(attic25));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;
                    }
                }
                else
                {
                    switch (panelPattern[i][j])
                    {
                    case PanelType.Window:
                        floorMeshes.Add(RandomItem(window30));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Balcony:
                        floorMeshes.Add(RandomItem(balcony30));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Wall:
                        floorMeshes.Add(RandomItem(wall30));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Socle:
                        floorMeshes.Add(RandomItem(socle30));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Entrance:
                        floorMeshes.Add(entrance30[entranceMeshIndex]);
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.EntranceWall:
                        floorMeshes.Add(entranceWall30[entranceWallMeshIndex]);
                        matrices.Add(Matrix4x4.TRS(panelOrigin + Vector3.up * (ceilingHeight - socleHeight), Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.EntranceWallLast:
                        floorMeshes.Add(entranceWallLast30[entranceWallLastMeshIndex]);
                        matrices.Add(Matrix4x4.TRS(panelOrigin + Vector3.up * (ceilingHeight - socleHeight), Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;

                    case PanelType.Attic:
                        floorMeshes.Add(RandomItem(attic30));
                        matrices.Add(Matrix4x4.TRS(panelOrigin, Quaternion.LookRotation(Vector3.Cross(direction, Vector3.up)), Vector3.one));
                        break;
                    }
                }
                panelOrigin += direction * wallSizes[j];
            }
            facadeMeshes.Add(PGMesh.CombineMeshes(floorMeshes, matrices));
            floorMeshes.Clear();
            matrices.Clear();
            panelOrigin = origin + Vector3.up * (i * ceilingHeight + socleHeight);
        }

        return(PGMesh.CombineMeshes(facadeMeshes));
    }