Example #1
0
        public override MeshDraft Construct(Vector2 parentLayoutOrigin)
        {
            List <Vector2> roofPolygon2;
            List <Vector3> roofPolygon3;
            var            roofDraft = ConstructRoofBase(out roofPolygon2, out roofPolygon3);

            var skeletonGenerator = new StraightSkeletonGenerator();
            var skeleton          = skeletonGenerator.Generate(roofPolygon2);

            var roofTop = new MeshDraft();

            foreach (var skeletonPolygon2 in skeleton.polygons)
            {
                if (skeletonPolygon2.Count == 3)
                {
                    roofTop.Add(ConstructGableDraft(skeletonPolygon2, RoofPitch));
                }
                else
                {
                    roofTop.Add(ConstructContourDraft(skeletonPolygon2, RoofPitch));
                }
            }
            roofTop.Move(Vector3.up * roofConfig.thickness);

            roofDraft.Add(roofTop)
            .Paint(roofColor);
            return(roofDraft);
        }
Example #2
0
        private static MeshDraft Platform(float radius, float baseOffset, int segments, float heignt)
        {
            float segmentAngle = 360f / segments;
            float currentAngle = 0;

            var lowerRing = new List <Vector3>(segments);
            var upperRing = new List <Vector3>(segments);

            for (var i = 0; i < segments; i++)
            {
                var lowerPoint = PTUtils.PointOnCircle3XZ(radius + baseOffset, currentAngle);
                lowerRing.Add(lowerPoint + Vector3.down * heignt);

                var upperPoint = PTUtils.PointOnCircle3XZ(radius, currentAngle);
                upperRing.Add(upperPoint);
                currentAngle -= segmentAngle;
            }

            var platform = new MeshDraft {
                name = "Platform"
            };
            var bottom = MeshDraft.TriangleFan(lowerRing);

            bottom.Add(MeshDraft.Band(lowerRing, upperRing));
            bottom.Paint(new Color(0.5f, 0.5f, 0.5f, 1));
            platform.Add(bottom);

            upperRing.Reverse();
            var top = MeshDraft.TriangleFan(upperRing);

            top.Paint(new Color(0.8f, 0.8f, 0.8f, 1));
            platform.Add(top);

            return(platform);
        }
Example #3
0
        public static 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 = MeshDraft.Hexahedron(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);

            Vector3 startPosition = Vector3.left*(width/2 - length - interval - rodWidth/2) +
                                    Vector3.down*upperRodHeight/2;
            for (int i = 0; i < rodCount; i++)
            {
                var rod = MeshDraft.Hexahedron(rodWidth, length, rodHeight);
                rod.Move(startPosition + Vector3.right*i*(rodWidth + interval));
                draft.Add(rod);
            }
            var upperRod = MeshDraft.Hexahedron(width, length, upperRodHeight);
            upperRod.Move(Vector3.up*rodHeight/2);
            draft.Add(upperRod);
            draft.Move(center + Vector3.up*height/2);
            return draft;
        }
Example #4
0
        public static MeshDraft Platform(float radius, float heignt, int segments = 128)
        {
            float segmentAngle = 360f / segments;
            float currentAngle = 0;

            var lowerRing = new List <Vector3>(segments);
            var upperRing = new List <Vector3>(segments);

            for (var i = 0; i < segments; i++)
            {
                var lowerPoint = PTUtils.PointOnCircle3XZ(radius + heignt, currentAngle);
                lowerRing.Add(lowerPoint + Vector3.down * heignt);

                var upperPoint = PTUtils.PointOnCircle3XZ(radius, currentAngle);
                upperRing.Add(upperPoint);
                currentAngle -= segmentAngle;
            }

            var platform = new MeshDraft {
                name = "Platform"
            };

            platform.Add(new MeshDraft()
                         .AddTriangleFan(lowerRing)
                         .Add(MeshDraft.Band(lowerRing, upperRing))
                         .Paint(new Color(0.5f, 0.5f, 0.5f, 1)));

            upperRing.Reverse();
            platform.Add(new MeshDraft()
                         .AddTriangleFan(upperRing)
                         .Paint(new Color(0.8f, 0.8f, 0.8f, 1)));

            return(platform);
        }
Example #5
0
        public static 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);
            }
            Vector3 startPosition = Vector3.up * (-height / 2 + plankStep - plankHeight / 2 - offeset);

            for (int i = 0; i < plankCount; i++)
            {
                var plank = MeshDraft.Hexahedron(plankWidth, length, plankHeight);
                plank.Move(startPosition + Vector3.up * i * plankStep);
                draft.Add(plank);
            }
            var rod = MeshDraft.Hexahedron(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
        public static 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 = MeshDraft.Hexahedron(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);

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

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

            upperRod.Move(Vector3.up * rodHeight / 2);
            draft.Add(upperRod);
            draft.Move(center + Vector3.up * height / 2);
            return(draft);
        }
Example #7
0
        public static MeshDraft Armrests1(Vector3 seatDimensions, Vector3 backCenter, float backHeight, float legWidth)
        {
            var draft = new MeshDraft();
            float armrestHeight = RandomE.Range(backHeight/4, backHeight*3/4, 3);
            float armrestLength = RandomE.Range(seatDimensions.z*3/4, seatDimensions.z, 2);
            legWidth = RandomE.Range(legWidth*3/4, legWidth, 2);

            Vector3 corner = backCenter + Vector3.left*(seatDimensions.x/2 + legWidth/2) +
                             Vector3.forward*legWidth/2;

            float offset = 0;
            if (RandomE.Chance(0.5f))
            {
                offset = RandomE.Range(armrestLength/4, armrestLength/2, 2) - legWidth/2;
            }
            Vector3 v0 = corner + Vector3.back*(armrestLength - legWidth/2 - offset) + Vector3.down*legWidth;
            Vector3 v1 = v0 + Vector3.up*(armrestHeight + legWidth/2);
            Vector3 v2 = corner + Vector3.up*armrestHeight;
            Vector3 v3 = v2 + Vector3.back*armrestLength;

            var armrest = ChairGenerator.BeamDraft(v0, v1, legWidth);
            armrest.Add(ChairGenerator.BeamDraft(v2, v3, legWidth));
            draft.Add(armrest);
            armrest.Move(Vector3.right*(seatDimensions.x + legWidth));
            draft.Add(armrest);
            return draft;
        }
        private MeshDraft Armrests1(Vector3 seatDimensions, Vector3 backCenter, float backHeight, float legWidth)
        {
            var   draft         = new MeshDraft();
            float armrestHeight = RandomE.Range(backHeight / 4, backHeight * 3 / 4, 3);
            float armrestLength = RandomE.Range(seatDimensions.z * 3 / 4, seatDimensions.z, 2);

            legWidth = RandomE.Range(legWidth * 3 / 4, legWidth, 2);

            var corner = backCenter + Vector3.left * (seatDimensions.x / 2 + legWidth / 2) +
                         Vector3.forward * legWidth / 2;

            float offset = 0;

            if (RandomE.Chance(0.5f))
            {
                offset = RandomE.Range(armrestLength / 4, armrestLength / 2, 2) - legWidth / 2;
            }
            var v0 = corner + Vector3.back * (armrestLength - legWidth / 2 - offset) + Vector3.down * legWidth;
            var v1 = v0 + Vector3.up * (armrestHeight + legWidth / 2);
            var v2 = corner + Vector3.up * armrestHeight;
            var v3 = v2 + Vector3.back * armrestLength;

            var armrest = BeamDraft(v0, v1, legWidth);

            armrest.Add(BeamDraft(v2, v3, legWidth));
            draft.Add(armrest);
            armrest.Move(Vector3.right * (seatDimensions.x + legWidth));
            draft.Add(armrest);
            return(draft);
        }
        public static MeshDraft Armrests0(float seatWidth, float seatDepth, Vector3 backCenter, float backHeight,
                                          float legWidth)
        {
            var   draft         = new MeshDraft();
            float armrestHeight = RandomE.Range(backHeight / 4, backHeight * 3 / 4, 3);
            float armrestLength = seatDepth - legWidth;

            Vector3 corner = backCenter + Vector3.left * (seatWidth / 2 - legWidth / 2) + Vector3.back * legWidth / 2;

            float offset = 0;

            if (RandomE.Chance(0.5f))
            {
                offset = RandomE.Range(legWidth / 2, legWidth, 2);
            }
            Vector3 v0 = corner + Vector3.back * (armrestLength - legWidth / 2);
            Vector3 v1 = v0 + Vector3.up * (armrestHeight - legWidth / 2);
            Vector3 v2 = corner + Vector3.up * armrestHeight;
            Vector3 v3 = v2 + Vector3.back * (armrestLength + offset);

            var armrest = ChairGenerator.BeamDraft(v0, v1, legWidth);

            armrest.Add(ChairGenerator.BeamDraft(v2, v3, legWidth));
            draft.Add(armrest);
            armrest.Move(Vector3.right * (seatWidth - legWidth));
            draft.Add(armrest);
            return(draft);
        }
Example #10
0
        public static 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);
            }
            Vector3 startPosition = Vector3.up*(-height/2 + plankStep - plankHeight/2 - offeset);
            for (int i = 0; i < plankCount; i++)
            {
                var plank = MeshDraft.Hexahedron(plankWidth, length, plankHeight);
                plank.Move(startPosition + Vector3.up*i*plankStep);
                draft.Add(plank);
            }
            var rod = MeshDraft.Hexahedron(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 #11
0
        public static MeshDraft Armrests0(float seatWidth, float seatDepth, Vector3 backCenter, float backHeight,
            float legWidth)
        {
            var draft = new MeshDraft();
            float armrestHeight = RandomE.Range(backHeight/4, backHeight*3/4, 3);
            float armrestLength = seatDepth - legWidth;

            Vector3 corner = backCenter + Vector3.left*(seatWidth/2 - legWidth/2) + Vector3.back*legWidth/2;

            float offset = 0;
            if (RandomE.Chance(0.5f))
            {
                offset = RandomE.Range(legWidth/2, legWidth, 2);
            }
            Vector3 v0 = corner + Vector3.back*(armrestLength - legWidth/2);
            Vector3 v1 = v0 + Vector3.up*(armrestHeight - legWidth/2);
            Vector3 v2 = corner + Vector3.up*armrestHeight;
            Vector3 v3 = v2 + Vector3.back*(armrestLength + offset);

            var armrest = ChairGenerator.BeamDraft(v0, v1, legWidth);
            armrest.Add(ChairGenerator.BeamDraft(v2, v3, legWidth));
            draft.Add(armrest);
            armrest.Move(Vector3.right*(seatWidth - legWidth));
            draft.Add(armrest);
            return draft;
        }
        private MeshDraft Armrests0(Vector3 seatDimensions, Vector3 backCenter, float backHeight, float legWidth)
        {
            var draft = new MeshDraft();
            float armrestHeight = RandomE.Range(backHeight/4, backHeight*3/4, 3);
            float armrestLength = seatDimensions.z - legWidth;

            var corner = backCenter + Vector3.left*(seatDimensions.x/2 - legWidth/2) + Vector3.back*legWidth/2;

            float offset = 0;
            if (RandomE.Chance(0.5f))
            {
                offset = RandomE.Range(legWidth/2, legWidth, 2);
            }
            var v0 = corner + Vector3.back*(armrestLength - legWidth/2);
            var v1 = v0 + Vector3.up*(armrestHeight - legWidth/2);
            var v2 = corner + Vector3.up*armrestHeight;
            var v3 = v2 + Vector3.back*(armrestLength + offset);

            var armrest = BeamDraft(v0, v1, legWidth);
            armrest.Add(BeamDraft(v2, v3, legWidth));
            draft.Add(armrest);
            armrest.Move(Vector3.right*(seatDimensions.x - legWidth));
            draft.Add(armrest);
            return draft;
        }
Example #13
0
 public static MeshDraft XStretchers(Vector3[] legCenters, float legWidth, float legHeight)
 {
     var draft = new MeshDraft();
     legWidth = RandomE.Range(legWidth/2, legWidth*3/4, 2);
     draft.Add(ChairGenerator.BeamDraft(legCenters[0], legCenters[2], legWidth));
     draft.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[3], legWidth));
     draft.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight/2, 2));
     return draft;
 }
Example #14
0
        public static MeshDraft XStretchers(Vector3[] legCenters, float legWidth, float legHeight)
        {
            var draft = new MeshDraft();

            legWidth = RandomE.Range(legWidth / 2, legWidth * 3 / 4, 2);
            draft.Add(ChairGenerator.BeamDraft(legCenters[0], legCenters[2], legWidth));
            draft.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[3], legWidth));
            draft.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight / 2, 2));
            return(draft);
        }
Example #15
0
        public static MeshDraft Chair(
            float legWidth,
            float legHeight,
            float seatWidth,
            float seatDepth,
            float seatHeight,
            float backHeight,
            bool hasStretchers,
            bool hasArmrests,
            Color color)
        {
            Vector3 right = Vector3.right*(seatWidth - legWidth)/2;
            Vector3 forward = Vector3.forward*(seatDepth - legWidth)/2;

            var chair = new MeshDraft {name = "Chair"};

            // Generate legs
            var legCenters = new Vector3[]
            {
                -right - forward,
                right - forward,
                right + forward,
                -right + forward
            };
            chair.Add(Leg0(legCenters[0], legWidth, legHeight));
            chair.Add(Leg0(legCenters[1], legWidth, legHeight));
            chair.Add(Leg0(legCenters[2], legWidth, legHeight));
            chair.Add(Leg0(legCenters[3], legWidth, legHeight));

            // Generate stretchers
            if (hasStretchers)
            {
                var stretchersConstructor = stretchersConstructors.GetRandom();
                chair.Add(stretchersConstructor(legCenters, legWidth, legHeight));
            }

            // Generate seat
            chair.Add(Seat0(Vector3.up*legHeight, seatWidth, seatDepth, seatHeight));

            // Generate chair back
            Vector3 backCenter = Vector3.up*(legHeight + seatHeight) + Vector3.forward*(seatDepth - legWidth)/2;
            var backConstructor = backConstructors.GetRandom();
            chair.Add(backConstructor(backCenter, seatWidth, legWidth, backHeight));

            // Generate armrests
            if (hasArmrests)
            {
                var armrestsConstructor = armrestsConstructors.GetRandom();
                chair.Add(armrestsConstructor(seatWidth, seatDepth, backCenter, backHeight, legWidth));
            }

            chair.Paint(color);

            return chair;
        }
Example #16
0
 public static MeshDraft HStretchers(Vector3[] legCenters, float legWidth, float legHeight)
 {
     var draft = new MeshDraft();
     legWidth = RandomE.Range(legWidth/2, legWidth, 3);
     draft.Add(ChairGenerator.BeamDraft(legCenters[0], legCenters[3], legWidth));
     draft.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[2], legWidth));
     Vector3 leftCenter = (legCenters[3] + legCenters[0])/2;
     Vector3 rightCenter = (legCenters[2] + legCenters[1])/2;
     draft.Add(ChairGenerator.BeamDraft(leftCenter, rightCenter, legWidth));
     draft.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight*3/4, 3));
     return draft;
 }
Example #17
0
        private static MeshDraft WindowpaneOuterFrame(Vector3 min, Vector3 max, Vector3 widthVector, Vector3 frameDepth, Vector3 startPosition,
                                                      Vector3 windowMin, Vector3 windowWidth, Vector3 windowHeight, Vector3 windowMax)
        {
            var outerFrame = new MeshDraft();

            outerFrame.Add(PerforatedQuad(min, max, windowMin, windowMax));
            var box = MeshDraft.PartialBox(windowWidth, frameDepth, windowHeight, Directions.All & ~Directions.ZAxis, false)
                      .FlipFaces()
                      .Move(startPosition + widthVector / 2);

            outerFrame.Add(box);
            return(outerFrame);
        }
        private MeshDraft HStretchers(Vector3[] legCenters, float legWidth, float legHeight)
        {
            var draft = new MeshDraft();

            legWidth = RandomE.Range(legWidth / 2, legWidth, 3);
            draft.Add(BeamDraft(legCenters[0], legCenters[3], legWidth));
            draft.Add(BeamDraft(legCenters[1], legCenters[2], legWidth));
            var leftCenter  = (legCenters[3] + legCenters[0]) / 2;
            var rightCenter = (legCenters[2] + legCenters[1]) / 2;

            draft.Add(BeamDraft(leftCenter, rightCenter, legWidth));
            draft.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3));
            return(draft);
        }
Example #19
0
 public static MeshDraft BoxStretchers(Vector3[] legCenters, float legWidth, float legHeight)
 {
     var draft = new MeshDraft();
     legWidth = RandomE.Range(legWidth/2, legWidth, 3);
     MeshDraft stretcher0 = ChairGenerator.BeamDraft(legCenters[0], legCenters[1], legWidth);
     stretcher0.Add(ChairGenerator.BeamDraft(legCenters[2], legCenters[3], legWidth));
     stretcher0.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight*3/4, 3));
     MeshDraft stretcher1 = ChairGenerator.BeamDraft(legCenters[0], legCenters[3], legWidth);
     stretcher1.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[2], legWidth));
     stretcher1.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight*3/4, 3));
     draft.Add(stretcher0);
     draft.Add(stretcher1);
     return draft;
 }
Example #20
0
        public static MeshDraft HStretchers(Vector3[] legCenters, float legWidth, float legHeight)
        {
            var draft = new MeshDraft();

            legWidth = RandomE.Range(legWidth / 2, legWidth, 3);
            draft.Add(ChairGenerator.BeamDraft(legCenters[0], legCenters[3], legWidth));
            draft.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[2], legWidth));
            Vector3 leftCenter  = (legCenters[3] + legCenters[0]) / 2;
            Vector3 rightCenter = (legCenters[2] + legCenters[1]) / 2;

            draft.Add(ChairGenerator.BeamDraft(leftCenter, rightCenter, legWidth));
            draft.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3));
            return(draft);
        }
        public static MeshDraft Chair(
            float legWidth,
            float legHeight,
            float seatWidth,
            float seatDepth,
            float seatHeight,
            float backHeight,
            bool hasStretchers,
            bool hasArmrests,
            Color color)
        {
            Vector3 right   = Vector3.right * (seatWidth - legWidth) / 2;
            Vector3 forward = Vector3.forward * (seatDepth - legWidth) / 2;

            var chair = new MeshDraft {
                name = "Chair"
            };

            // Generate legs
            var legCenters = new Vector3[]
            {
                -right - forward,
                right - forward,
                right + forward,
                -right + forward
            };

            chair.Add(Leg0(legCenters[0], legWidth, legHeight));
            chair.Add(Leg0(legCenters[1], legWidth, legHeight));
            chair.Add(Leg0(legCenters[2], legWidth, legHeight));
            chair.Add(Leg0(legCenters[3], legWidth, legHeight));

            // Generate stretchers
            if (hasStretchers)
            {
                var stretchersConstructor = stretchersConstructors.GetRandom();
                chair.Add(stretchersConstructor(legCenters, legWidth, legHeight));
            }

            // Generate seat
            chair.Add(Seat0(Vector3.up * legHeight, seatWidth, seatDepth, seatHeight));

            // Generate chair back
            Vector3 backCenter      = Vector3.up * (legHeight + seatHeight) + Vector3.forward * (seatDepth - legWidth) / 2;
            var     backConstructor = backConstructors.GetRandom();

            chair.Add(backConstructor(backCenter, seatWidth, legWidth, backHeight));

            // Generate armrests
            if (hasArmrests)
            {
                var armrestsConstructor = armrestsConstructors.GetRandom();
                chair.Add(armrestsConstructor(seatWidth, seatDepth, backCenter, backHeight, legWidth));
            }

            chair.Paint(color);

            return(chair);
        }
Example #22
0
        public static MeshDraft Chair(Config config)
        {
            Assert.IsTrue(config.legWidth > 0);
            Assert.IsTrue(config.legHeight > 0);
            Assert.IsTrue(config.seatWidth > 0);
            Assert.IsTrue(config.seatDepth > 0);
            Assert.IsTrue(config.seatHeight > 0);
            Assert.IsTrue(config.backHeight > 0);

            Vector3 right   = Vector3.right * (config.seatWidth - config.legWidth) / 2;
            Vector3 forward = Vector3.forward * (config.seatDepth - config.legWidth) / 2;

            var chair = new MeshDraft {
                name = "Chair"
            };

            // Generate legs
            var legCenters = new Vector3[]
            {
                -right - forward,
                right - forward,
                right + forward,
                -right + forward
            };

            chair.Add(Leg0(legCenters[0], config.legWidth, config.legHeight));
            chair.Add(Leg0(legCenters[1], config.legWidth, config.legHeight));
            chair.Add(Leg0(legCenters[2], config.legWidth, config.legHeight));
            chair.Add(Leg0(legCenters[3], config.legWidth, config.legHeight));

            // Generate stretchers
            if (config.hasStretchers)
            {
                var stretchersConstructor = stretchersConstructors.GetRandom();
                chair.Add(stretchersConstructor(legCenters, config.legWidth, config.legHeight));
            }

            // Generate seat
            chair.Add(Seat0(Vector3.up * config.legHeight, config.seatWidth, config.seatDepth, config.seatHeight));

            // Generate chair back
            Vector3 backCenter = Vector3.up * (config.legHeight + config.seatHeight) +
                                 Vector3.forward * (config.seatDepth - config.legWidth) / 2;
            var backConstructor = backConstructors.GetRandom();

            chair.Add(backConstructor(backCenter, config.seatWidth, config.legWidth, config.backHeight));

            // Generate armrests
            if (config.hasArmrests)
            {
                var armrestsConstructor = armrestsConstructors.GetRandom();
                chair.Add(armrestsConstructor(config.seatWidth, config.seatDepth, backCenter, config.backHeight,
                                              config.legWidth));
            }

            chair.Paint(config.color);

            return(chair);
        }
Example #23
0
        private static CompoundMeshDraft Windowpane(Vector3 min, Vector3 max, Color frameColor, Color glassColor)
        {
            Vector3 size         = max - min;
            Vector3 widthVector  = size.ToVector3XZ();
            Vector3 heightVector = size.ToVector3Y();
            Vector3 right        = widthVector.normalized;
            Vector3 normal       = Vector3.Cross(widthVector, heightVector).normalized;
            var     frame        = new MeshDraft {
                name = WallDraftName
            };

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

            Vector3 frameWidth    = right * WindowFrameWidth / 2;
            Vector3 frameHeight   = Vector3.up * WindowFrameWidth / 2;
            Vector3 frameLength   = normal * WindowFrameWidth / 2;
            Vector3 startPosition = min + heightVector / 2 + frameLength / 2;

            for (int i = 0; i < rodCount; i++)
            {
                var rod = MeshDraft.PartialBox(frameWidth * 2, frameLength, heightVector - frameHeight * 2,
                                               Directions.Left | Directions.Back | Directions.Right, false)
                          .Move(startPosition + right * (i + 1) * interval);
                frame.Add(rod);
            }

            Vector3 windowMin    = min + frameWidth + frameHeight;
            Vector3 windowWidth  = widthVector - frameWidth * 2;
            Vector3 windowHeight = heightVector - frameHeight * 2;
            Vector3 windowMax    = windowMin + windowWidth + windowHeight;

            frame.Add(PerforatedQuad(min, max, windowMin, windowMax));

            var hole = MeshDraft.PartialBox(windowWidth, frameLength, windowHeight, Directions.All & ~Directions.ZAxis, false)
                       .Move(startPosition + widthVector / 2)
                       .FlipFaces();

            frame.Add(hole);
            frame.Paint(frameColor);

            var glass = new MeshDraft().AddQuad(windowMin + frameLength, windowWidth, windowHeight)
                        .Paint(glassColor);

            glass.name = GlassDraftName;

            return(new CompoundMeshDraft().Add(frame).Add(glass));
        }
Example #24
0
        public static MeshDraft Platform(float radius, float height, int segments = 128)
        {
            float segmentAngle = 360f / segments;
            float currentAngle = 0;

            var lowerRing = new List <Vector3>(segments);
            var upperRing = new List <Vector3>(segments);

            for (var i = 0; i < segments; i++)
            {
                lowerRing.Add(Geometry.PointOnCircle3XZ(radius + height, currentAngle) + Vector3.down * height);
                upperRing.Add(Geometry.PointOnCircle3XZ(radius, currentAngle));
                currentAngle += segmentAngle;
            }

            var platform = new MeshDraft {
                name = "Platform"
            }
            .AddFlatQuadBand(lowerRing, upperRing, false);

            lowerRing.Reverse();
            platform.AddTriangleFan(lowerRing, Vector3.down)
            .Paint(new Color(0.5f, 0.5f, 0.5f, 1));

            platform.Add(new MeshDraft()
                         .AddTriangleFan(upperRing, Vector3.up)
                         .Paint(new Color(0.8f, 0.8f, 0.8f, 1)));

            return(platform);
        }
Example #25
0
        public BoidController(MeshFilter meshFilter)
        {
            template = MeshDraft.Tetrahedron(0.3f);

            // Avoid vertex count overflow
            swarmCount = Mathf.Min(65000 / template.vertices.Count, swarmCount);
            // Optimization trick: in each frame we simulate only small percent of all boids
            simulationUpdate = Mathf.RoundToInt(swarmCount * simulationPercent);
            int 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();
            meshFilter.mesh = mesh;
        }
Example #26
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());
        }
Example #27
0
        private MeshDraft Facade(Vector3 origin, Vector3 direction, List <FloorPlan> facadePlan)
        {
            var draft = new MeshDraft();

            Vector3 height = Vector3.zero;

            foreach (FloorPlan floor in facadePlan)
            {
                var panels = floor.panels;

                Vector3 panelOrigin = origin + height;
                foreach (var panel in panels)
                {
                    var offset      = Vector3.up * panel.heightOffset;
                    var panelWidth  = direction.normalized * sizeValues[panel.size];
                    var panelHeight = Vector3.up * panel.height;

                    PanelConstructor panelConstructor;
                    if (commonPanelConstructors.ContainsKey(panel.type))
                    {
                        panelConstructor = commonPanelConstructors[panel.type];
                    }
                    else
                    {
                        panelConstructor = panelConstructors[panel.type].GetRandom();
                    }
                    draft.Add(panelConstructor(panelOrigin + offset, panelWidth, panelHeight));

                    panelOrigin += panelWidth;
                }
                height += Vector3.up * floor.height;
            }

            return(draft);
        }
Example #28
0
        private static MeshDraft Platform(float radius, float baseOffset, int segments, float heignt)
        {
            float segmentAngle = 360f/segments;
            float currentAngle = 0;

            var lowerRing = new List<Vector3>(segments);
            var upperRing = new List<Vector3>(segments);
            for (var i = 0; i < segments; i++)
            {
                var lowerPoint = PTUtils.PointOnCircle3XZ(radius + baseOffset, currentAngle);
                lowerRing.Add(lowerPoint + Vector3.down*heignt);

                var upperPoint = PTUtils.PointOnCircle3XZ(radius, currentAngle);
                upperRing.Add(upperPoint);
                currentAngle -= segmentAngle;
            }

            var platform = new MeshDraft {name = "Platform"};
            var bottom = MeshDraft.TriangleFan(lowerRing);
            bottom.Add(MeshDraft.Band(lowerRing, upperRing));
            bottom.Paint(new Color(0.5f, 0.5f, 0.5f, 1));
            platform.Add(bottom);

            upperRing.Reverse();
            var top = MeshDraft.TriangleFan(upperRing);
            top.Paint(new Color(0.8f, 0.8f, 0.8f, 1));
            platform.Add(top);

            return platform;
        }
Example #29
0
        private static MeshDraft WindowpaneFrameRods(Vector3 min, Vector3 widthVector, Vector3 heightVector,
                                                     out Vector3 frameWidth, out Vector3 frameHeight, out Vector3 frameDepth, out Vector3 startPosition)
        {
            var frame = new MeshDraft {
                name = WallDraftName
            };

            Vector3 right  = widthVector.normalized;
            Vector3 normal = Vector3.Cross(heightVector, right).normalized;

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

            frameWidth    = right * WindowFrameWidth / 2;
            frameHeight   = Vector3.up * WindowFrameWidth / 2;
            frameDepth    = -normal * WindowFrameWidth / 2;
            startPosition = min + heightVector / 2 + frameDepth / 2;
            for (int i = 0; i < rodCount; i++)
            {
                var rod = MeshDraft.PartialBox(frameWidth * 2, frameDepth, heightVector - frameHeight * 2,
                                               Directions.Left | Directions.Back | Directions.Right, false)
                          .Move(startPosition + right * (i + 1) * interval);
                frame.Add(rod);
            }
            return(frame);
        }
Example #30
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 static MeshDraft Windowpane(Vector3 min, Vector3 max, Color frameColor, Color glassColor)
        {
            Vector3 size         = max - min;
            Vector3 widthVector  = size.OnlyXZ();
            Vector3 heightVector = size.OnlyY();
            Vector3 right        = widthVector.normalized;
            Vector3 normal       = Vector3.Cross(widthVector, heightVector).normalized;
            var     draft        = new MeshDraft();

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

            Vector3 frameWidth    = right * WindowFrameWidth / 2;
            Vector3 frameHeight   = Vector3.up * WindowFrameWidth / 2;
            Vector3 frameLength   = normal * WindowFrameWidth / 2;
            Vector3 startPosition = min + heightVector / 2 + frameLength / 2;

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

            Vector3 windowMin    = min + frameWidth + frameHeight;
            Vector3 windowWidth  = widthVector - frameWidth * 2;
            Vector3 windowHeight = heightVector - frameHeight * 2;
            Vector3 windowMax    = windowMin + windowWidth + windowHeight;
            var     window       = PerforatedQuad(min, max, windowMin, windowMax);

            draft.Add(window);

            var hole = MeshDraft.PartialBox(windowWidth, frameLength, windowHeight, Directions.All & ~Directions.ZAxis);

            hole.Move(startPosition + widthVector / 2);
            hole.FlipFaces();
            draft.Add(hole);
            draft.Paint(frameColor);

            var glass = MeshDraft.Quad(windowMin + frameLength, windowWidth, windowHeight);

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

            return(draft);
        }
        private MeshDraft BoxStretchers(Vector3[] legCenters, float legWidth, float legHeight)
        {
            var draft = new MeshDraft();

            legWidth = RandomE.Range(legWidth / 2, legWidth, 3);
            var stretcher0 = BeamDraft(legCenters[0], legCenters[1], legWidth);

            stretcher0.Add(BeamDraft(legCenters[2], legCenters[3], legWidth));
            stretcher0.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3));
            var stretcher1 = BeamDraft(legCenters[0], legCenters[3], legWidth);

            stretcher1.Add(BeamDraft(legCenters[1], legCenters[2], legWidth));
            stretcher1.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3));
            draft.Add(stretcher0);
            draft.Add(stretcher1);
            return(draft);
        }
Example #33
0
        public static MeshDraft BoxStretchers(Vector3[] legCenters, float legWidth, float legHeight)
        {
            var draft = new MeshDraft();

            legWidth = RandomE.Range(legWidth / 2, legWidth, 3);
            MeshDraft stretcher0 = ChairGenerator.BeamDraft(legCenters[0], legCenters[1], legWidth);

            stretcher0.Add(ChairGenerator.BeamDraft(legCenters[2], legCenters[3], legWidth));
            stretcher0.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3));
            MeshDraft stretcher1 = ChairGenerator.BeamDraft(legCenters[0], legCenters[3], legWidth);

            stretcher1.Add(ChairGenerator.BeamDraft(legCenters[1], legCenters[2], legWidth));
            stretcher1.Move(Vector3.up * RandomE.Range(legHeight / 4, legHeight * 3 / 4, 3));
            draft.Add(stretcher0);
            draft.Add(stretcher1);
            return(draft);
        }
Example #34
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 #35
0
        public override MeshDraft GetMeshDraft()
        {
            UpdateLayout();

            var meshDraft = new MeshDraft();

            for (int i = 0; i < facadePanels.Count; i++)
            {
                meshDraft.Add(facadePanels[i].GetMeshDraft());
            }
            return(meshDraft);
        }
Example #36
0
        private static MeshDraft CreateMesh(VOX.Model model, Dictionary <ColorPlanePos, ColorPlane> planes, float scale = 1.0f, float halfTexelShift = 0.0f)
        {
            MeshDraft mesh = new MeshDraft();

            foreach (KeyValuePair <ColorPlanePos, ColorPlane> plane in planes)
            {
                mesh.Add(CreateOptimizedFaces(model, plane.Key, plane.Value, halfTexelShift));
            }

            mesh.Scale(scale);
            return(mesh);
        }
        protected static MeshDraft BalconyGlazed(Vector3 origin, float width, float height, Color wallColor,
                                                 Color frameColor, Color glassColor, Color roofColor)
        {
            Vector3 widthVector  = Vector3.right * width;
            Vector3 heightVector = Vector3.up * height;

            Vector3 balconyHeight = Vector3.up * BalconyHeight;
            Vector3 balconyDepth  = Vector3.back * BalconyDepth;

            var draft   = new MeshDraft();
            var balcony = MeshDraft.PartialBox(widthVector, balconyDepth, balconyHeight,
                                               Directions.All & ~Directions.Up & ~Directions.Back);

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

            Vector3 roof0 = origin + heightVector;
            Vector3 roof1 = roof0 + widthVector;
            Vector3 roof2 = roof1 + balconyDepth;
            Vector3 roof3 = roof0 + balconyDepth;
            var     roof  = MeshDraft.Quad(roof0, roof1, roof2, roof3);

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

            Vector3 glassHeight = heightVector - balconyHeight;
            Vector3 glass0      = origin + balconyHeight;
            Vector3 glass1      = glass0 + balconyDepth;
            Vector3 glass2      = glass1 + widthVector;
            var     glass       = Windowpane(glass0, glass0 + balconyDepth + glassHeight, frameColor, glassColor);

            glass.Add(Windowpane(glass1, glass1 + widthVector + glassHeight, frameColor, glassColor));
            glass.Add(Windowpane(glass2, glass2 - balconyDepth + glassHeight, frameColor, glassColor));
            draft.Add(glass);

            return(draft);
        }
        private static MeshDraft Balcony(Vector3 origin, float width, Color wallColor)
        {
            Vector3 widthVector   = Vector3.right * width;
            Vector3 balconyHeight = Vector3.up * BalconyHeight;
            Vector3 balconyDepth  = Vector3.back * BalconyDepth;

            var balconyOuter = MeshDraft.PartialBox(widthVector, balconyDepth, balconyHeight,
                                                    Directions.All & ~Directions.Up & ~Directions.Back);

            balconyOuter.FlipFaces();
            Vector3 balconyCenter = origin + widthVector / 2 + balconyDepth / 2 + balconyHeight / 2;

            balconyOuter.Move(balconyCenter);

            Vector3 innerWidthOffset  = Vector3.right * BalconyThickness;
            Vector3 innerWidth        = widthVector - innerWidthOffset * 2;
            Vector3 innerHeightOffset = Vector3.up * BalconyThickness;
            Vector3 innerHeight       = balconyHeight - innerHeightOffset;
            Vector3 innerDepthOffset  = Vector3.back * BalconyThickness;
            Vector3 innerDepth        = balconyDepth - innerDepthOffset;
            var     balconyInner      = MeshDraft.PartialBox(innerWidth, innerDepth, innerHeight,
                                                             Directions.All & ~Directions.Up & ~Directions.Back);

            balconyInner.Move(balconyCenter - innerDepthOffset / 2 + innerHeightOffset / 2);

            Vector3 borderOrigin      = origin + widthVector + balconyHeight;
            Vector3 borderInnerOrigin = borderOrigin - innerWidthOffset;
            var     balconyBorder     = Bracket(borderOrigin, -widthVector, balconyDepth,
                                                borderInnerOrigin, -innerWidth, innerDepth);

            var balcony = new MeshDraft();

            balcony.Add(balconyOuter);
            balcony.Add(balconyInner);
            balcony.Add(balconyBorder);
            balcony.Paint(wallColor);
            return(balcony);
        }
Example #39
0
        public static MeshDraft GenerateFacadesMeshDraft(List <Vector2> foundationPolygon, List <FacadeLayout> facadeLayouts)
        {
            var facadesDraft = new MeshDraft {
                name = "Facades"
            };

            for (int i = 0; i < foundationPolygon.Count; i++)
            {
                Vector3 a = foundationPolygon[i].ToVector3XZ();
                Vector3 b = foundationPolygon.GetLooped(i + 1).ToVector3XZ();
                facadesDraft.Add(GenerateFacadeMeshDraft(a, b, facadeLayouts[i]));
            }
            return(facadesDraft);
        }
Example #40
0
        /// <summary>
        /// Generate new colors and positions for boids
        /// </summary>
        public Mesh Generate(Color colorA, Color colorB)
        {
            template = MeshDraft.Tetrahedron(0.3f);

            // Avoid vertex count overflow
            swarmCount = Mathf.Min(65000 / template.vertices.Count, swarmCount);
            // Optimization trick: in each frame we simulate only small percent of all boids
            maxSimulationSteps = Mathf.RoundToInt(swarmCount * simulationPercent);
            // int vertexCount = swarmCount*template.vertices.Count;

            // Paint template in random color
            template.colors.Clear();
            // Assuming that we are dealing with tetrahedron, first vertex should be boid's "nose"
            template.colors.Add(colorA);
            for (int i = 1; i < template.vertices.Count; i++)
            {
                template.colors.Add(Tile.Lighten(colorB, i * 0.1f));
            }

            draft = new MeshDraft
            {
                name      = "Boids",
                vertices  = new List <Vector3>(),
                triangles = new List <int>(),
                normals   = new List <Vector3>(),
                uv        = new List <Vector2>(),
                colors    = new List <Color>()
            };

            for (var i = 0; i < swarmCount; i++)
            {
                // Assign random starting values for each boid
                var boid = new Boid
                {
                    position = Random.onUnitSphere * worldSphere,
                    rotation = Random.rotation,
                    velocity = Random.onUnitSphere * maxSpeed
                };
                boid.position.y = Mathf.Abs(boid.position.y);
                boid.velocity.y = Mathf.Abs(boid.velocity.y);
                boids.Add(boid);

                draft.Add(template);
            }

            mesh = draft.ToMesh();
            mesh.MarkDynamic();

            return(mesh);
        }
        public static MeshDraft GenerateFacades(List <Vector2> foundationPolygon, List <FacadeLayout> facadeLayouts)
        {
            var buildingDraft = new MeshDraft {
                name = "Building"
            };

            for (int i = 0; i < foundationPolygon.Count; i++)
            {
                Vector3 a            = foundationPolygon[i].ToVector3XZ();
                Vector3 b            = foundationPolygon.GetLooped(i + 1).ToVector3XZ();
                var     facadeLayout = facadeLayouts[i];
                buildingDraft.Add(GenerateFacade(a, b, facadeLayout));
            }
            return(buildingDraft);
        }
        public static MeshDraft Chair(float legWidth, float legHeight, Vector3 seatDimensions, float backHeight,
            bool hasStretchers, bool hasArmrests)
        {
            Vector3 right = Vector3.right*(seatDimensions.x - legWidth)/2;
            Vector3 forward = Vector3.forward*(seatDimensions.z - legWidth)/2;

            var chair = new MeshDraft {name = "Chair"};

            // Generate legs
            var legCenters = new Vector3[]
            {
                -right - forward,
                right - forward,
                right + forward,
                -right + forward
            };
            chair.Add(Leg0(legCenters[0], legWidth, legHeight));
            chair.Add(Leg0(legCenters[1], legWidth, legHeight));
            chair.Add(Leg0(legCenters[2], legWidth, legHeight));
            chair.Add(Leg0(legCenters[3], legWidth, legHeight));

            // Generate stretchers
            if (hasStretchers)
            {
                var stretcherFunc = new Func<Vector3[], float, float, MeshDraft>[]
                {
                    Stretchers.XStretchers,
                    Stretchers.HStretchers,
                    Stretchers.BoxStretchers
                }.GetRandom();
                chair.Add(stretcherFunc(legCenters, legWidth, legHeight));
            }

            chair.Add(Seat0(Vector3.up*legHeight, seatDimensions.x, seatDimensions.z, seatDimensions.y));

            // Generate chair back
            var backFunc = new Func<Vector3, float, float, float, MeshDraft>[]
            {
                Backs.Back0,
                Backs.Back1,
                Backs.RodBack
            }.GetRandom();
            Vector3 backCenter = Vector3.up*(legHeight + seatDimensions.y) +
                                 Vector3.forward*(seatDimensions.z - legWidth)/2;
            chair.Add(backFunc(backCenter, seatDimensions.x, legWidth, backHeight));

            // Generate armrests
            if (hasArmrests)
            {
                var armrestsFunc = new Func<Vector3, Vector3, float, float, MeshDraft>[]
                {
                    Armrests.Armrests0,
                    Armrests.Armrests1
                }.GetRandom();
                chair.Add(armrestsFunc(seatDimensions, backCenter, backHeight, legWidth));
            }

            chair.Paint(RandomE.colorHSV);

            return chair;
        }
        private MeshDraft Facade(Vector3 origin, Vector3 direction, List<FloorPlan> facadePlan)
        {
            var draft = new MeshDraft();

            Vector3 height = Vector3.zero;
            foreach (FloorPlan floor in facadePlan)
            {
                List<Panel> panels = floor.panels;

                Vector3 panelOrigin = origin + height;
                foreach (var panel in panels)
                {
                    Vector3 offset = Vector3.up*panel.heightOffset;
                    Vector3 panelWidth = direction.normalized*sizeValues[panel.size];
                    Vector3 panelHeight = Vector3.up*panel.height;

                    PanelConstructor panelConstructor;
                    if (commonPanelConstructors.ContainsKey(panel.type))
                    {
                        panelConstructor = commonPanelConstructors[panel.type];
                    }
                    else
                    {
                        panelConstructor = panelConstructors[panel.type].GetRandom();
                    }
                    draft.Add(panelConstructor(panelOrigin + offset, panelWidth, panelHeight));

                    panelOrigin += panelWidth;
                }
                height += Vector3.up*floor.height;
            }

            return draft;
        }
        private MeshDraft KhrushchyovkaDraft()
        {
            float width = Random.Range(widthLB, widthUB);
            float length = Random.Range(lengthLB, lengthUB);
            int floorCount = Random.Range(floorCountLB, floorCountUB);

            bool 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);

            List<FloorPlan> facadePlan0 = FacadeGenerator(length, floorCount, hasAttic, true, true);
            draft.Add(Facade(corners[0], Vector3.right, facadePlan0));
            List<FloorPlan> facadePlan1 = FacadeGenerator(width, floorCount, hasAttic);
            draft.Add(Facade(corners[1], Vector3.forward, facadePlan1));
            List<FloorPlan> facadePlan2 = FacadeGenerator(length, floorCount, hasAttic, false, true);
            draft.Add(Facade(corners[2], Vector3.left, facadePlan2));
            List<FloorPlan> 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 = MeshDraft.Quad(corners[0], corners[1], corners[2], corners[3]);
            basement.Paint(roofColor);
            draft.Add(basement);

            return draft;
        }
Example #45
0
        public BoidController(MeshFilter meshFilter)
        {
            template = MeshDraft.Tetrahedron(0.3f);

            // Avoid vertex count overflow
            swarmCount = Mathf.Min(65000/template.vertices.Count, swarmCount);
            // Optimization trick: in each frame we simulate only small percent of all boids
            simulationUpdate = Mathf.RoundToInt(swarmCount*simulationPercent);
            int 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();
            meshFilter.mesh = mesh;
        }
Example #46
0
        public static MeshDraft BalconyGlazed(Vector3 origin, Vector3 width, Vector3 height)
        {
            Vector3 balconyWidth = width;
            Vector3 balconyHeight = height.normalized*BalconyHeight;
            Vector3 balconyDepth = Vector3.Cross(height, width).normalized*BalconyDepth;

            var draft = new MeshDraft();
            var balcony = MeshDraft.Hexahedron(balconyWidth, balconyDepth, balconyHeight,
                Directions.All & ~Directions.Up & ~Directions.Back);
            balcony.FlipFaces();
            balcony.Move(origin + width/2 + balconyDepth/2 + balconyHeight/2);
            balcony.Paint(BuildingGenerator.wallColor);
            draft.Add(balcony);

            Vector3 roof0 = origin + height;
            Vector3 roof1 = roof0 + balconyWidth;
            Vector3 roof2 = roof1 + balconyDepth;
            Vector3 roof3 = roof0 + balconyDepth;
            var roof = MeshDraft.Quad(roof0, roof1, roof2, roof3);
            roof.Paint(BuildingGenerator.roofColor);
            draft.Add(roof);

            Vector3 glassHeight = height - balconyHeight;
            Vector3 glass0 = origin + balconyHeight;
            Vector3 glass1 = glass0 + balconyDepth;
            Vector3 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 #47
0
        private static MeshDraft Windowpane(Vector3 origin, Vector3 width, Vector3 heigth)
        {
            Vector3 right = width.normalized;
            Vector3 normal = Vector3.Cross(width, heigth).normalized;
            var draft = new MeshDraft();

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

            Vector3 frameWidth = right*WindowFrameWidth/2;
            Vector3 frameHeight = Vector3.up*WindowFrameWidth/2;
            Vector3 frameLength = normal*WindowFrameWidth/2;
            Vector3 startPosition = origin + heigth/2 + frameLength/2;
            for (int i = 0; i < rodCount; i++)
            {
                var frame = MeshDraft.Hexahedron(frameWidth*2, frameLength, heigth - frameHeight*2,
                    Directions.Left | Directions.Back | Directions.Right);
                frame.Move(startPosition + right*(i + 1)*interval);
                draft.Add(frame);
            }

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

            var hole = MeshDraft.Hexahedron(windowWidth, frameLength, windowHeigth, Directions.All & ~Directions.ZAxis);
            hole.Move(startPosition + width/2);
            hole.FlipFaces();
            draft.Add(hole);

            draft.Paint(BuildingGenerator.frameColor);

            var glass = MeshDraft.Quad(windowCorner + frameLength, windowWidth, windowHeigth);
            glass.Paint(BuildingGenerator.glassColor);
            draft.Add(glass);

            return draft;
        }
 private MeshDraft HStretchers(Vector3[] legCenters, float legWidth, float legHeight)
 {
     var draft = new MeshDraft();
     legWidth = RandomE.Range(legWidth/2, legWidth, 3);
     draft.Add(BeamDraft(legCenters[0], legCenters[3], legWidth));
     draft.Add(BeamDraft(legCenters[1], legCenters[2], legWidth));
     var leftCenter = (legCenters[3] + legCenters[0])/2;
     var rightCenter = (legCenters[2] + legCenters[1])/2;
     draft.Add(BeamDraft(leftCenter, rightCenter, legWidth));
     draft.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight*3/4, 3));
     return draft;
 }
        private MeshDraft Chair()
        {
            var legWidth = Random.Range(legWidthLB, legWidthUB);
            var legHeight = Random.Range(legHeightLB, legHeightUB);
            var seatDimensions = RandomE.Range(seatLB, seatUB);
            var backHeight = Random.Range(backHeightLB, backHeightUB);

            var chair = new MeshDraft {name = "Chair"};

            var right = Vector3.right*(seatDimensions.x - legWidth)/2;
            var forward = Vector3.forward*(seatDimensions.z - legWidth)/2;

            var legCenters = new Vector3[]
            {
                -right - forward,
                right - forward,
                right + forward,
                -right + forward
            };
            chair.Add(Leg0(legCenters[0], legWidth, legHeight));
            chair.Add(Leg0(legCenters[1], legWidth, legHeight));
            chair.Add(Leg0(legCenters[2], legWidth, legHeight));
            chair.Add(Leg0(legCenters[3], legWidth, legHeight));

            if (RandomE.Chance(0.3f))
            {
                var stretcherFunc = new Func<Vector3[], float, float, MeshDraft>[]
                {
                    XStretchers,
                    HStretchers,
                    BoxStretchers
                }.GetRandom();
                chair.Add(stretcherFunc(legCenters, legWidth, legHeight));
            }

            chair.Add(Seat0(Vector3.up*legHeight, seatDimensions.x, seatDimensions.z, seatDimensions.y));

            var backFunc = new Func<Vector3, float, float, float, MeshDraft>[]
            {
                Back0,
                Back1,
                RodBack
            }.GetRandom();
            var backCenter = Vector3.up*(legHeight + seatDimensions.y) + Vector3.forward*(seatDimensions.z - legWidth)/2;
            chair.Add(backFunc(backCenter, seatDimensions.x, legWidth, backHeight));

            if (RandomE.Chance(0.3f))
            {
                var armrestsFunc = new Func<Vector3, Vector3, float, float, MeshDraft>[]
                {
                    Armrests0,
                    Armrests1
                }.GetRandom();
                chair.Add(armrestsFunc(seatDimensions, backCenter, backHeight, legWidth));
            }

            chair.Paint(RandomE.colorHSV);

            return chair;
        }
 private MeshDraft BoxStretchers(Vector3[] legCenters, float legWidth, float legHeight)
 {
     var draft = new MeshDraft();
     legWidth = RandomE.Range(legWidth/2, legWidth, 3);
     var stretcher0 = BeamDraft(legCenters[0], legCenters[1], legWidth);
     stretcher0.Add(BeamDraft(legCenters[2], legCenters[3], legWidth));
     stretcher0.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight*3/4, 3));
     var stretcher1 = BeamDraft(legCenters[0], legCenters[3], legWidth);
     stretcher1.Add(BeamDraft(legCenters[1], legCenters[2], legWidth));
     stretcher1.Move(Vector3.up*RandomE.Range(legHeight/4, legHeight*3/4, 3));
     draft.Add(stretcher0);
     draft.Add(stretcher1);
     return draft;
 }
Example #51
0
        public static MeshDraft BuildingDraft(float width, float length, int floorCount, bool hasAttic, Color wallColor)
        {
            float height = FloorHeight*floorCount + SocleHeight + (hasAttic ? AtticHeight : 0);
            BuildingGenerator.wallColor = wallColor.WithA(0);

            var draft = new MeshDraft {name = "Building"};
            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();

            List<FloorPlan> facadePlan0 = FacadeGenerator(length, floorCount, hasAttic, true, true);
            draft.Add(Facade(corners[0], Vector3.right, facadePlan0));
            List<FloorPlan> facadePlan1 = FacadeGenerator(width, floorCount, hasAttic);
            draft.Add(Facade(corners[1], Vector3.forward, facadePlan1));
            List<FloorPlan> facadePlan2 = FacadeGenerator(length, floorCount, hasAttic, false, true);
            draft.Add(Facade(corners[2], Vector3.left, facadePlan2));
            List<FloorPlan> 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 = MeshDraft.Quad(corners[0], corners[1], corners[2], corners[3]);
            basement.Paint(roofColor);
            draft.Add(basement);

            return draft;
        }
Example #52
0
        public static MeshDraft Balcony(Vector3 origin, Vector3 width, Vector3 height)
        {
            Vector3 right = width.normalized;
            Vector3 normal = Vector3.Cross(height, width).normalized;
            Vector3 balconyWidth = width;
            Vector3 balconyHeight = Vector3.up*BalconyHeight;
            Vector3 balconyDepth = normal*BalconyDepth;

            var draft = new MeshDraft();
            var balconyOuter = MeshDraft.Hexahedron(balconyWidth, balconyDepth, balconyHeight,
                Directions.All & ~Directions.Up & ~Directions.Back);
            balconyOuter.FlipFaces();
            Vector3 balconyCenter = origin + width/2 + balconyDepth/2 + balconyHeight/2;
            balconyOuter.Move(balconyCenter);
            balconyOuter.Paint(BuildingGenerator.wallColor);

            Vector3 innerWidthOffset = right*BalconyThickness;
            Vector3 innerWidth = balconyWidth - innerWidthOffset*2;
            Vector3 innerHeightOffset = Vector3.up*BalconyThickness;
            Vector3 innerHeight = balconyHeight - innerHeightOffset;
            Vector3 innerDepthOffset = normal*BalconyThickness;
            Vector3 innerDepth = balconyDepth - innerDepthOffset;
            var balconyInner = MeshDraft.Hexahedron(innerWidth, innerDepth, innerHeight,
                Directions.All & ~Directions.Up & ~Directions.Back);
            balconyInner.Move(balconyCenter - innerDepthOffset/2 + innerHeightOffset/2);

            Vector3 borderOrigin = origin + balconyWidth + balconyHeight;
            Vector3 borderInnerOrigin = borderOrigin - innerWidthOffset;
            var balconyBorder = Bracket(borderOrigin, -balconyWidth, balconyDepth,
                borderInnerOrigin, -innerWidth, innerDepth);

            draft.Add(balconyOuter);
            draft.Add(balconyInner);
            draft.Add(balconyBorder);

            Vector3 windowWidthOffset = right*WindowWidthOffset;
            Vector3 windowHeightOffset = Vector3.up*WindowHeightOffset;
            Vector3 windowWidth = right*(width.magnitude - WindowWidthOffset*2);
            Vector3 windowHeight = Vector3.up*WindowHeight;
            Vector3 windowDepth = normal*WindowDepth;

            int rodCount = Mathf.FloorToInt(windowWidth.magnitude/WindowSegmentMinWidth);
            Vector3 doorWidth = right*windowWidth.magnitude/(rodCount + 1);
            Vector3 doorHeight = windowHeightOffset + windowHeight;

            List<Vector3> outerFrame = new List<Vector3>
            {
                origin + windowWidthOffset + innerHeightOffset,
                origin + windowWidthOffset + doorHeight,
                origin + windowWidthOffset + windowWidth + doorHeight,
                origin + windowWidthOffset + windowWidth + windowHeightOffset,
                origin + windowWidthOffset + doorWidth + windowHeightOffset,
                origin + windowWidthOffset + doorWidth + innerHeightOffset
            };

            var panel = MeshDraft.TriangleStrip(new List<Vector3>
            {
                outerFrame[0],
                origin,
                outerFrame[1],
                origin + height,
                outerFrame[2],
                origin + width + height,
                outerFrame[3],
                origin + width,
                outerFrame[4],
                origin + width,
                outerFrame[5]
            });

            draft.Add(panel);

            List<Vector3> innerFrame = new List<Vector3>();
            foreach (Vector3 vertex in outerFrame)
            {
                innerFrame.Add(vertex - windowDepth);
            }
            var frame = MeshDraft.FlatBand(innerFrame, outerFrame);
            draft.Add(frame);

            draft.Paint(BuildingGenerator.wallColor);

            draft.Add(Windowpane(outerFrame[0] - windowDepth, doorWidth, doorHeight - innerHeightOffset));
            draft.Add(Windowpane(outerFrame[4] - windowDepth, windowWidth - doorWidth, windowHeight));

            return draft;
        }
        /// <summary>
        /// Generate new colors and positions for boids
        /// </summary>
        public Mesh Generate()
        {
            template = MeshDraft.Tetrahedron(0.3f);

            // Avoid vertex count overflow
            swarmCount = Mathf.Min(65000/template.vertices.Count, swarmCount);
            // Optimization trick: in each frame we simulate only small percent of all boids
            maxSimulationSteps = Mathf.RoundToInt(swarmCount*simulationPercent);
            int vertexCount = swarmCount*template.vertices.Count;

            // Paint template in random color
            template.colors.Clear();
            var color = RandomE.colorHSV;
            // Assuming that we are dealing with tetrahedron, first vertex should be boid's "nose"
            template.colors.Add(color.Inverted());
            for (int i = 1; i < template.vertices.Count; i++)
            {
                template.colors.Add(color);
            }

            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++)
            {
                // Assign random starting values for each boid
                var boid = new Boid
                {
                    position = Random.insideUnitSphere*spawnSphere,
                    rotation = Random.rotation,
                    velocity = Random.onUnitSphere*maxSpeed
                };
                boids.Add(boid);

                draft.Add(template);
            }

            mesh = draft.ToMesh();
            mesh.MarkDynamic();
            return mesh;
        }