private MeshDraft RodBack(Vector3 center, float width, float length, float height)
        {
            var   draft          = new MeshDraft();
            int   rodCount       = Random.Range(1, 5);
            float maxWidth       = (width - length * 2) / rodCount;
            float rodWidth       = RandomE.Range(maxWidth / 4, maxWidth * 3 / 4, 3);
            float interval       = (width - length * 2 - rodWidth * rodCount) / (rodCount + 1);
            float upperRodHeight = Mathf.Min(height * 3 / 4, length * Random.Range(1, 4));
            float rodHeight      = height - upperRodHeight;

            var leftRod = MeshE.HexahedronDraft(length, length, rodHeight);

            leftRod.Move(Vector3.left * (width - length) / 2 + Vector3.down * upperRodHeight / 2);
            draft.Add(leftRod);
            leftRod.Move(Vector3.right * (width - length));
            draft.Add(leftRod);

            var startPosition = Vector3.left * (width / 2 - length - interval - rodWidth / 2) + Vector3.down * upperRodHeight / 2;

            for (int i = 0; i < rodCount; i++)
            {
                var rod = MeshE.HexahedronDraft(rodWidth, length, rodHeight);
                rod.Move(startPosition + Vector3.right * i * (rodWidth + interval));
                draft.Add(rod);
            }
            var upperRod = MeshE.HexahedronDraft(width, length, upperRodHeight);

            upperRod.Move(Vector3.up * rodHeight / 2);
            draft.Add(upperRod);
            draft.Move(center + Vector3.up * height / 2);
            return(draft);
        }
Example #2
0
        private static MeshDraft FlatRoof(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
        {
            var draft = MeshE.QuadDraft(a, d, c, b);

            draft.Paint(roofColor);
            return(draft);
        }
        private MeshDraft Back0(Vector3 center, float width, float length, float height)
        {
            var draft = MeshE.HexahedronDraft(width, length, height);

            draft.Move(center + Vector3.up * height / 2);
            return(draft);
        }
Example #4
0
        private void Awake()
        {
            template = MeshE.TetrahedronDraft(0.3f);

            swarmCount       = Mathf.Min(65000 / template.vertices.Count, swarmCount);
            simulationUpdate = Mathf.RoundToInt(swarmCount * simulationPercent);
            var vertexCount = swarmCount * template.vertices.Count;

            draft = new MeshDraft
            {
                name      = "Boids",
                vertices  = new List <Vector3>(vertexCount),
                triangles = new List <int>(vertexCount),
                normals   = new List <Vector3>(vertexCount),
                uv        = new List <Vector2>(vertexCount),
                colors    = new List <Color>(vertexCount)
            };
            for (var i = 0; i < swarmCount; i++)
            {
                boids.Add(new Boid());
                draft.Add(template);
            }

            mesh = draft.ToMesh();
            mesh.MarkDynamic();
            GetComponent <MeshFilter>().mesh = mesh;

            Generate();

            StartCoroutine(Simulate());
        }
        private MeshDraft Back1(Vector3 center, float width, float length, float height)
        {
            var   draft       = new MeshDraft();
            int   plankCount  = Random.Range(1, 5);
            float plankStep   = height / plankCount;
            float plankHeight = plankStep * Random.Range(0.3f, 0.8f);
            float plankWidth  = width - length * 2;

            float offeset = 0;

            if (plankCount > 1)
            {
                offeset = RandomE.Range(0, (plankStep - plankHeight) / 2, 3);
            }
            var startPosition = Vector3.up * (-height / 2 + plankStep - plankHeight / 2 - offeset);

            for (int i = 0; i < plankCount; i++)
            {
                var plank = MeshE.HexahedronDraft(plankWidth, length, plankHeight);
                plank.Move(startPosition + Vector3.up * i * plankStep);
                draft.Add(plank);
            }
            var rod = MeshE.HexahedronDraft(length, length, height);

            rod.Move(Vector3.left * (width / 2 - length / 2));
            draft.Add(rod);
            rod.Move(Vector3.right * (width - length));
            draft.Add(rod);
            draft.Move(center + Vector3.up * height / 2);
            return(draft);
        }
Example #6
0
        private static MeshDraft Socle(Vector3 origin, Vector3 width, Vector3 height)
        {
            var draft = MeshE.QuadDraft(origin, width, height);

            draft.Paint(socleColor);
            return(draft);
        }
Example #7
0
        public static void Icosahedron()
        {
            var go = GameObject.CreatePrimitive(PrimitiveType.Quad);

            Object.DestroyImmediate(go.GetComponent <Collider>());
            go.name = icosahedron;
            go.GetComponent <MeshFilter>().mesh = MeshE.Icosahedron(1);
            Undo.RegisterCreatedObjectUndo(go, create + icosahedron);
        }
Example #8
0
        private static MeshDraft FlatOverhangRoof(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
        {
            var width      = b - a;
            var length     = c - b;
            var roofHeight = Vector3.up * 0.3f;
            var draft      = MeshE.HexahedronDraft(width + width.normalized, length + length.normalized, roofHeight);

            draft.Move((a + c) / 2 + roofHeight / 2);
            draft.Paint(roofColor);
            return(draft);
        }
Example #9
0
        /// <summary>
        /// Returns a cylindrical mesh to fit a ring shape with given radius. Cylinder will have the given number of sides, and height.
        /// </summary>
        static Mesh CreateCylinderMesh(int sides, float radius, float height)
        {
            // circumradius = r sec(Ï€/n)
            var circumradius = radius * 1 / Mathf.Cos(Mathf.PI / sides);

            var cylinderMesh = MeshE.Cylinder(circumradius, sides, height);

            cylinderMesh.Rotate(Quaternion.Euler(0f, (360f / sides) / 2f, 0f));

            return(cylinderMesh);
        }
Example #10
0
        private static MeshDraft EntranceRoofed(Vector3 origin, Vector3 width, Vector3 height)
        {
            var draft      = Entrance(origin, width, height);
            var roofLength = Vector3.Cross(width, height).normalized *EntranceRoofLength;
            var roofHeight = Vector3.up * EntranceRoofHeight;
            var roof       = MeshE.HexahedronDraft(width, roofLength, roofHeight);

            roof.Move(origin + width / 2 - roofLength / 2 + height - roofHeight / 2);
            roof.Paint(roofColor);
            draft.Add(roof);
            return(draft);
        }
Example #11
0
        private static MeshDraft GabledRoof(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
        {
            var ridgeHeight = Vector3.up * 2;
            var ridge0      = (a + d) / 2 + ridgeHeight;
            var ridge1      = (b + c) / 2 + ridgeHeight;
            var draft       = MeshE.QuadDraft(a, ridge0, ridge1, b);

            draft.Add(MeshE.TriangleDraft(b, ridge1, c));
            draft.Add(MeshE.QuadDraft(c, ridge1, ridge0, d));
            draft.Add(MeshE.TriangleDraft(d, ridge0, a));
            draft.Paint(roofColor);
            return(draft);
        }
Example #12
0
        private static MeshDraft Entrance(Vector3 origin, Vector3 width, Vector3 height)
        {
            var doorWidth  = width.normalized * EntranceDoorWidth;
            var doorOrigin = origin + width / 2 - doorWidth / 2;
            var doorHeight = Vector3.up * EntranceDoorHeight;
            var draft      = Bracket(origin, width, height, doorOrigin, doorWidth, doorHeight);

            draft.Paint(wallColor);

            var door = MeshE.QuadDraft(doorOrigin, doorWidth, doorHeight);

            door.Paint(doorColor);
            draft.Add(door);
            return(draft);
        }
Example #13
0
 private static MeshDraft Bracket(Vector3 origin, Vector3 width, Vector3 length, Vector3 innerOrigin,
                                  Vector3 innerWidth, Vector3 innerLength)
 {
     return(MeshE.TriangleStripDraft(new List <Vector3>
     {
         innerOrigin,
         origin,
         innerOrigin + innerLength,
         origin + length,
         innerOrigin + innerLength + innerWidth,
         origin + length + width,
         innerOrigin + innerWidth,
         origin + width
     }));
 }
Example #14
0
        private MeshDraft KhrushchyovkaDraft()
        {
            float width      = Random.Range(widthLB, widthUB);
            float length     = Random.Range(lengthLB, lengthUB);
            int   floorCount = Random.Range(floorCountLB, floorCountUB);

            var   hasAttic = RandomE.Chance(0.5f);
            float height   = FloorHeight * floorCount + SocleHeight + (hasAttic ? AtticHeight : 0);

            var draft = new MeshDraft {
                name = "Khrushchyovka"
            };
            var corners = new Vector3[]
            {
                Vector3.left *length / 2 + Vector3.back *width / 2,
                Vector3.right *length / 2 + Vector3.back *width / 2,
                Vector3.right *length / 2 + Vector3.forward *width / 2,
                Vector3.left *length / 2 + Vector3.forward *width / 2
            };

            commonPanelConstructors[PanelType.Entrance]     = panelConstructors[PanelType.Entrance].GetRandom();
            commonPanelConstructors[PanelType.EntranceWall] = panelConstructors[PanelType.EntranceWall].GetRandom();

            wallColor = RandomE.colorHSV.WithA(0);

            var facadePlan0 = FacadeGenerator(length, floorCount, hasAttic, true, true);

            draft.Add(Facade(corners[0], Vector3.right, facadePlan0));
            var facadePlan1 = FacadeGenerator(width, floorCount, hasAttic);

            draft.Add(Facade(corners[1], Vector3.forward, facadePlan1));
            var facadePlan2 = FacadeGenerator(length, floorCount, hasAttic, false, true);

            draft.Add(Facade(corners[2], Vector3.left, facadePlan2));
            var facadePlan3 = FacadeGenerator(width, floorCount, hasAttic);

            draft.Add(Facade(corners[3], Vector3.back, facadePlan3));

            draft.Add(Roof(corners[0], corners[1], corners[2], corners[3], Vector3.up * height));

            var basement = MeshE.QuadDraft(corners[0], corners[1], corners[2], corners[3]);

            basement.Paint(roofColor);
            draft.Add(basement);

            return(draft);
        }
        public static MeshDraft BeamDraft(Vector3 from, Vector3 to, float width, float rotation = 0)
        {
            var up        = to - from;
            var draft     = MeshE.HexahedronDraft(width, width, up.magnitude);
            var direction = up;

            direction.y = 0;
            var quaternion = Quaternion.identity;

            if (direction != Vector3.zero)
            {
                quaternion = Quaternion.LookRotation(direction);
            }
            draft.Rotate(Quaternion.FromToRotation(Vector3.up, up) * Quaternion.Euler(0, rotation, 0) * quaternion);
            draft.Move((from + to) / 2);
            return(draft);
        }
Example #16
0
        private static MeshDraft Windowpane(Vector3 origin, Vector3 width, Vector3 heigth)
        {
            var right  = width.normalized;
            var normal = Vector3.Cross(width, heigth).normalized;
            var draft  = new MeshDraft();

            int   rodCount = Mathf.FloorToInt(width.magnitude / WindowSegmentMinWidth);
            float interval = width.magnitude / (rodCount + 1);

            var frameWidth    = right * WindowFrameWidth / 2;
            var frameHeight   = Vector3.up * WindowFrameWidth / 2;
            var frameLength   = normal * WindowFrameWidth / 2;
            var startPosition = origin + heigth / 2 + frameLength / 2;

            for (int i = 0; i < rodCount; i++)
            {
                var frame = MeshE.HexahedronDraft(frameWidth * 2, frameLength, heigth - frameHeight * 2,
                                                  Directions.Left | Directions.Back | Directions.Right);
                frame.Move(startPosition + right * (i + 1) * interval);
                draft.Add(frame);
            }

            var windowCorner = origin + frameWidth + frameHeight;
            var windowWidth  = width - frameWidth * 2;
            var windowHeigth = heigth - frameHeight * 2;
            var window       = PerforatedQuad(origin, width, heigth, windowCorner, windowWidth, windowHeigth);

            draft.Add(window);

            var hole = MeshE.HexahedronDraft(windowWidth, frameLength, windowHeigth, Directions.All & ~Directions.ZAxis);

            hole.Move(startPosition + width / 2);
            hole.FlipFaces();
            draft.Add(hole);

            draft.Paint(frameColor);

            var glass = MeshE.QuadDraft(windowCorner + frameLength, windowWidth, windowHeigth);

            glass.Paint(glassColor);
            draft.Add(glass);

            return(draft);
        }
Example #17
0
        private void Awake()
        {
            GetComponent <MeshRenderer>().material = GraphicsE.diffuseVertexColor;

            var template = MeshE.TetrahedronFlat(0.3f);

            templateVertices        = template.vertices;
            templateVerticesLength  = template.vertices.Length;
            templateTriangles       = template.triangles;
            templateTrianglesLength = template.triangles.Length;
            swarmCount = Mathf.Min(65000 / templateVerticesLength, swarmCount);

            vertices  = new Vector3[swarmCount * templateVerticesLength];
            triangles = new int[swarmCount * templateTrianglesLength];
            colors32  = new Color32[swarmCount * templateVerticesLength];
            for (var i = 0; i < swarmCount; i++)
            {
                var boid = new Boid
                {
                    position = Random.insideUnitSphere * spawnSphere,
                    rotation = Random.rotation,
                    velocity = Random.onUnitSphere * maxSpeed
                };
                boids.Add(boid);

                SetBoidVertices(boid, i);
                SetBoidTriangles(i);
                SetBoidColors(boid, i);
            }

            mesh = new Mesh
            {
                name      = "Boids",
                vertices  = vertices,
                triangles = triangles,
                colors32  = colors32
            };
            mesh.RecalculateNormals();
            mesh.MarkDynamic();
            GetComponent <MeshFilter>().mesh = mesh;

            StartCoroutine(SimulateCoroutine());
        }
Example #18
0
        private static MeshDraft AtticVented(Vector3 origin, Vector3 width, Vector3 height)
        {
            var right      = width.normalized;
            var center     = origin + width / 2 + height / 2;
            var holeOrigin = center - right * AtticHoleWidth / 2 - Vector3.up * AtticHoleHeight / 2;
            var holeWidth  = right * AtticHoleWidth;
            var holeHeight = Vector3.up * AtticHoleHeight;
            var holeDepth  = Vector3.Cross(width, height).normalized *AtticHoleDepth;

            var draft = PerforatedQuad(origin, width, height, holeOrigin, holeWidth, holeHeight);

            draft.Paint(wallColor);

            var hexahedron = MeshE.HexahedronDraft(holeWidth, holeDepth, holeHeight, Directions.All & ~Directions.Back);

            hexahedron.Move(center + holeDepth / 2);
            hexahedron.FlipFaces();
            hexahedron.Paint(roofColor);
            draft.Add(hexahedron);
            return(draft);
        }
Example #19
0
        private static MeshDraft Window(Vector3 origin, Vector3 width, Vector3 height, float widthOffset,
                                        float heightOffset, float windowHeight)
        {
            var right       = width.normalized;
            var frameOrigin = origin + right * widthOffset + Vector3.up * heightOffset;
            var frameWidth  = right * (width.magnitude - widthOffset * 2);
            var frameHeight = Vector3.up * windowHeight;
            var frameDepth  = Vector3.Cross(width, height).normalized *WindowDepth;

            var draft = PerforatedQuad(origin, width, height, frameOrigin, frameWidth, frameHeight);

            var frame = MeshE.HexahedronDraft(frameWidth, -frameDepth, frameHeight, Directions.All & ~Directions.ZAxis);

            frame.Move(frameOrigin + frameWidth / 2 + frameHeight / 2 + frameDepth / 2);
            draft.Add(frame);

            draft.Paint(wallColor);

            draft.Add(Windowpane(frameOrigin + frameDepth, frameWidth, frameHeight));

            return(draft);
        }
Example #20
0
        private static MeshDraft BalconyGlazed(Vector3 origin, Vector3 width, Vector3 height)
        {
            var balconyWidth  = width;
            var balconyHeight = height.normalized * BalconyHeight;
            var balconyDepth  = Vector3.Cross(height, width).normalized *BalconyDepth;

            var draft   = new MeshDraft();
            var balcony = MeshE.HexahedronDraft(balconyWidth, balconyDepth, balconyHeight,
                                                Directions.All & ~Directions.Up & ~Directions.Back);

            balcony.FlipFaces();
            balcony.Move(origin + width / 2 + balconyDepth / 2 + balconyHeight / 2);
            balcony.Paint(wallColor);
            draft.Add(balcony);

            var roof0 = origin + height;
            var roof1 = roof0 + balconyWidth;
            var roof2 = roof1 + balconyDepth;
            var roof3 = roof0 + balconyDepth;
            var roof  = MeshE.QuadDraft(roof0, roof1, roof2, roof3);

            roof.Paint(roofColor);
            draft.Add(roof);

            var glassHeight = height - balconyHeight;
            var glass0      = origin + balconyHeight;
            var glass1      = glass0 + balconyDepth;
            var glass2      = glass1 + balconyWidth;
            var glass       = Windowpane(glass0, balconyDepth, glassHeight);

            glass.Add(Windowpane(glass1, balconyWidth, glassHeight));
            glass.Add(Windowpane(glass2, -balconyDepth, glassHeight));
            draft.Add(glass);

            return(draft);
        }
Example #21
0
        private static MeshDraft SocleWindowed(Vector3 origin, Vector3 width, Vector3 height)
        {
            var right        = width.normalized;
            var windowOrigin = origin + width / 2 - right * SocleWindowWidth / 2 + Vector3.up * SocleWindowHeightOffset;
            var windowWidth  = right * SocleWindowWidth;
            var windowHeigth = Vector3.up * SocleWindowHeight;
            var windowDepth  = Vector3.Cross(width, height).normalized *SocleWindowDepth;

            var draft = PerforatedQuad(origin, width, height, windowOrigin, windowWidth, windowHeigth);

            var frame = MeshE.HexahedronDraft(windowWidth, -windowDepth, windowHeigth,
                                              Directions.All & ~Directions.ZAxis);

            frame.Move(windowOrigin + windowWidth / 2 + windowHeigth / 2 + windowDepth / 2);
            draft.Add(frame);
            draft.Paint(socleColor);

            var window = MeshE.QuadDraft(windowOrigin + windowDepth / 2, windowWidth, windowHeigth);

            window.Paint(socleWindowColor);
            draft.Add(window);

            return(draft);
        }
 private void Start()
 {
     GetComponent <MeshFilter>().mesh = MeshE.FlatSphere(radius, longitudeSegments, latitudeSegments);
 }
Example #23
0
 private void Start()
 {
     GetComponent <MeshFilter>().mesh = MeshE.Hexahedron(width, length, height);
 }
Example #24
0
 private void Start()
 {
     GetComponent <MeshFilter>().mesh = MeshE.Prism(radius, segments, height);
 }
Example #25
0
 private void Start()
 {
     GetComponent <MeshFilter>().mesh = MeshE.Teardrop(radius, height, longitudeSegments, latitudeSegments);
 }
Example #26
0
 private void Start()
 {
     GetComponent <MeshFilter>().mesh = MeshE.FlatSpheroid(radius, height, horizontalSegments, verticalSegments);
 }
Example #27
0
 public static void Cylinder()
 {
     PrimitiveTemplate(cylinder, () => MeshE.Cylinder(1, 16, 1));
 }
Example #28
0
 public static void Prism()
 {
     PrimitiveTemplate(prism, () => MeshE.Prism(1, 16, 1));
 }
Example #29
0
 public static void Pyramid()
 {
     PrimitiveTemplate(pyramid, () => MeshE.Pyramid(1, 6, 1));
 }
Example #30
0
 public static void Plane()
 {
     PrimitiveTemplate(plane, () => MeshE.Plane(10, 10, 10, 10));
 }