Пример #1
0
        public void RayIntersectsWhenOriginLiesOnFace()
        {
            var polygon = new Polygon(new[]
            {
                new Vector3(0, 0, 0),
                new Vector3(4, 0, 0),
                new Vector3(0, 4, 0)
            });
            var extrude       = new solids.Extrude(polygon, 10, new Vector3(1, 1, 1), false);
            var ray           = new Ray(new Vector3(2.88675, 4.88675, 2.88675), new Vector3(-1, 0, 1));
            var doesIntersect = ray.Intersects(extrude, out List <Vector3> result);

            Assert.True(doesIntersect);
            Assert.Equal(ray.Origin, result[0]);
        }
Пример #2
0
        public void RayIntersectsAlongEdge()
        {
            var polygon = new Polygon(new[]
            {
                new Vector3(0, 0, 0),
                new Vector3(4, 0, 0),
                new Vector3(0, 4, 0)
            });
            var extrude = new solids.Extrude(polygon, 10, new Vector3(1, 1, 1), false);

            var ray2           = new Ray(new Vector3(6, 6, 6), new Vector3(1, 1, 1));
            var doesIntersect2 = ray2.Intersects(extrude, out List <Vector3> result2);

            Assert.True(doesIntersect2);
        }
Пример #3
0
        public void RayDoesNotIntersectWhenPointingAwayFromSolid()
        {
            var polygon = new Polygon(new[]
            {
                new Vector3(0, 0, 0),
                new Vector3(4, 0, 0),
                new Vector3(0, 4, 0)
            });
            var extrude = new solids.Extrude(polygon, 10, new Vector3(1, 1, 1), false);

            var ray           = new Ray(new Vector3(6, 6, 0), new Vector3(1, 0, 0));
            var doesIntersect = ray.Intersects(extrude, out List <Vector3> result3);

            Assert.False(doesIntersect);
        }
Пример #4
0
        public void RayIntersectsSolidAtVertex()
        {
            var polygon = new Polygon(new[]
            {
                new Vector3(0, 0, 0),
                new Vector3(4, 0, 0),
                new Vector3(0, 4, 0)
            });
            var extrude = new solids.Extrude(polygon, 10, new Vector3(1, 1, 1), false);

            var ray           = new Ray(new Vector3(4, 0, 0), new Vector3(1, 0, 0));
            var doesIntersect = ray.Intersects(extrude, out List <Vector3> result);

            Assert.True(doesIntersect);
            Assert.Equal(new Vector3(4, 0, 0), result[0]);
        }
Пример #5
0
        private static Element[] MakeEnvelopesFromMass(ADSK.Element revitElement)
        {
            var mass        = revitElement as Autodesk.Revit.DB.FamilyInstance;
            var geom        = mass.get_Geometry(new ADSK.Options());
            var solids      = geom.Where(g => g is ADSK.Solid).Cast <ADSK.Solid>().Where(s => s.Volume > 0).ToList();
            var bottomFaces = solids.SelectMany(g => g.GetMostLikelyHorizontalFaces(downwardFacing: true));

            var envelopes = new List <Envelope>();
            var height    = mass.get_BoundingBox(null).Max.Z - mass.get_BoundingBox(null).Min.Z;

            foreach (var face in bottomFaces)
            {
                var profiles = face.GetProfiles();

                foreach (var profile in profiles)
                {
                    var extrude = new Elements.Geometry.Solids.Extrude(profile, height, Vector3.ZAxis, false);
                    var rep     = new Representation(new List <SolidOperation> {
                        extrude
                    });
                    var newEnvelope = new Envelope(profile,
                                                   0,
                                                   height,
                                                   Vector3.ZAxis,
                                                   0,
                                                   new Transform(),
                                                   BuiltInMaterials.Steel,
                                                   rep,
                                                   false,
                                                   Guid.NewGuid(),
                                                   "");
                    envelopes.Add(newEnvelope);
                }
            }

            return(envelopes.ToArray());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A VicGovResiEnvelopeOutputs instance containing computed results and the model with any new elements.</returns>
        public static VicGovResiEnvelopeOutputs Execute(Dictionary <string, Model> inputModels, VicGovResiEnvelopeInputs input)
        {
            // Get site model dependency
            var siteModel   = inputModels["Site"];
            var siteElement = getSite(siteModel);

            // Get Setbacks
            double sideSetback     = GetSideSetbackFromBldgHeight(input.ProposedBuildingHeights);
            string allotmentType   = input.AllotmentDesignation.ToString();
            string facingCondition = input.BuildingFacing.ToString();
            double frontSetback    = GetFrontSetback(allotmentType, facingCondition, sideSetback);
            double maxHeight       = GetMaxHeightAllowance(input.ProposedBuildingHeights);
            var    output          = new VicGovResiEnvelopeOutputs(sideSetback, frontSetback);


            // Boundary & sort
            var         perimeter           = siteElement.Perimeter.Offset(sideSetback * -1);
            var         siteArea            = siteElement.Area;
            var         siteBoundaryProfile = new Profile(perimeter);
            List <Line> lotBoundarySegments = siteBoundaryProfile.Segments();

            // Create lotBoundary as Curve object
            var lotBoundaryCurveLoop = CreatePolylineFromLineSegments(lotBoundarySegments);

            // Get front & back lot edge and render to Hypar
            Vector3 frontLotClosestPt         = input.FrontBoundary;
            var     frontBoundary             = CurveClosestPt(lotBoundarySegments, frontLotClosestPt);
            var     rearBoundary              = CurveFurthestPt(lotBoundarySegments, frontLotClosestPt);
            var     sideBoundary              = lotBoundarySegments.ElementAt(1);
            var     frontBoundaryLength       = frontBoundary.Length();
            var     frontBoundaryLengthHalved = frontBoundaryLength / 2;

            // Create front offset
            var translationVec                = rearBoundary.PointAt(0.5) - frontBoundary.PointAt(0.5);
            var unitTranslationVec            = translationVec.Unitized();
            var frontSetbackTranslationVector = unitTranslationVec * frontSetback;
            var frontBoundaryXformed          = frontBoundary.TransformedLine(new Transform(frontSetbackTranslationVector));

            // Draw lot centreline
            var lotCentreLine = new Line(frontBoundaryXformed.PointAt(0.5), rearBoundary.PointAt(0.5));

            // Create planning Envelope Polygon
            var planningEnvelopePolgyon = CreatePlanningEnvelopePolygon(input.ProposedBuildingHeights, frontBoundaryLengthHalved).First();

            // Orient envelope to lot centreline
            planningEnvelopePolgyon.Transform(new Transform(lotCentreLine.TransformAt(0)));

            // Create envelope geom representation
            var envelopeProfile        = new Profile(planningEnvelopePolgyon);
            var sweep                  = new Elements.Geometry.Solids.Sweep(envelopeProfile, lotBoundaryCurveLoop, 0, 0, 0, false);
            var extrude                = new Elements.Geometry.Solids.Extrude(envelopeProfile, lotCentreLine.Length(), lotCentreLine.Direction(), false);
            var geometryRepresentation = new Representation(new List <Elements.Geometry.Solids.SolidOperation>()
            {
                extrude
            });
            var envelopeMaterial = new Material("envelope", new Color(0.3, 0.7, 0.7, 0.6), 0.0f, 0.0f);
            var envelopes        = new List <Envelope>()
            {
                new Envelope(envelopeProfile, 0, maxHeight, lotCentreLine.Direction(), 0.0, new Transform(0, 0, 0), envelopeMaterial, geometryRepresentation, false, Guid.NewGuid(), "")
            };

            output.Model.AddElements(envelopes);
            return(output);
        }
Пример #7
0
        /// <summary>
        /// The BigBoxFacade function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A BigBoxFacadeOutputs instance containing computed results and the model with any new elements.</returns>
        public static BigBoxFacadeOutputs Execute(Dictionary <string, Model> inputModels, BigBoxFacadeInputs input)
        {
            Envelope envelope = null;

            inputModels.TryGetValue("Envelope", out var envelopeModel);
            if (envelopeModel != null)
            {
                var envelopes = new List <Envelope>();
                envelopes.AddRange(envelopeModel.AllElementsOfType <Envelope>());
                var aboveGradeEnvelopes = envelopes.Where(e => e.Elevation >= 0.0).ToList();
                if (aboveGradeEnvelopes.Count() > 0)
                {
                    envelope = aboveGradeEnvelopes.First();
                }
            }
            if (envelope == null)
            {
                var envMatl   = new Material("envelope", new Color(1.0, 1.0, 1.0, 0.2), 0.0f, 0.0f);
                var height    = 15.0;
                var footprint = Polygon.Rectangle(60, 40);
                var extrude   = new Elements.Geometry.Solids.Extrude(footprint, height, Vector3.ZAxis, false);
                var geomRep   = new Representation(new List <Elements.Geometry.Solids.SolidOperation>()
                {
                    extrude
                });
                envelope = new Envelope(footprint, 0.0, height, Vector3.ZAxis, 0.0,
                                        new Transform(), envMatl, geomRep, false, Guid.NewGuid(), "");
            }

            var output           = new BigBoxFacadeOutputs(envelope.Profile.Perimeter.Area());
            var boundarySegments = envelope.Profile.Perimeter.Segments();
            var panelMat         = new Material("envelope", new Color(1.0, 1.0, 1.0, 1), 0.5f, 0.5f);

            var lowestSegment = boundarySegments.OrderBy((s) => s.Start.Average(s.End).Y).First();

            foreach (var s in boundarySegments)
            {
                var d = s.Direction();

                try {
                    var t = new Transform(s.Start + new Vector3(0, 0, 0), d, d.Cross(Vector3.ZAxis));
                    var l = s.Length();

                    if (lowestSegment == s)
                    {
                        var grid             = new Grid1d(s);
                        var doorWidth        = 4;
                        var backwardsLine    = s.Start.X > s.End.X;
                        var reverseDirection = backwardsLine != input.EntranceOnRight;

                        var leftDoor       = 0.0;
                        var rightDoor      = 0.0;
                        var leftDoorWidth  = 0.0;
                        var rightDoorWidth = 0.9;
                        if (reverseDirection)
                        {
                            leftDoor       = l / 10 * 2;
                            rightDoor      = l / 10 * 6;
                            leftDoorWidth  = doorWidth;
                            rightDoorWidth = doorWidth * 2.0;
                        }
                        else
                        {
                            leftDoor       = l / 10 * 4;
                            rightDoor      = l / 10 * 8;
                            leftDoorWidth  = doorWidth * 2.0;
                            rightDoorWidth = doorWidth;
                        }
                        grid.SplitAtPositions(new [] { leftDoor - leftDoorWidth / 2.0, leftDoor + leftDoorWidth / 2.0, rightDoor - rightDoorWidth / 2.0, rightDoor + rightDoorWidth / 2.0 });
                        var lines = grid.GetCells().Select(c => c.GetCellGeometry()).OfType <Line>();
                        if (reverseDirection)
                        {
                            lines = lines.Reverse();
                        }
                        var wallIdx = 0;
                        foreach (var wallLine in lines)
                        {
                            var segmentLength    = wallLine.Length();
                            var segmentTransform = new Transform(wallLine.Start + new Vector3(0, 0, 0), d, d.Cross(Vector3.ZAxis));
                            if (wallIdx == 1)
                            {
                                CreateStandardPanel(segmentLength, 6, envelope.Height - 6, 0.1, segmentTransform, panelMat, out FacadePanel panel);
                                output.model.AddElement(panel);
                                CreateBranding(envelope.Height, 10, 28, true, new Transform(wallLine.Start.Average(wallLine.End), Vector3.ZAxis, 0), output.model);
                            }
                            else if (wallIdx == 3)
                            {
                                CreateStandardPanel(segmentLength, 6, envelope.Height - 6, 0.1, segmentTransform, panelMat, out FacadePanel panel);
                                output.model.AddElement(panel);
                                CreateBranding(envelope.Height * 0.7, 5.5, 6, false, new Transform(wallLine.Start.Average(wallLine.End), Vector3.ZAxis, 0), output.model);
                            }
                            else
                            {
                                CreateStandardPanel(segmentLength, 0, envelope.Height, 0.1, segmentTransform, panelMat, out FacadePanel panel);
                                output.model.AddElement(panel);
                            }
                            wallIdx++;
                        }
                    }
                    else
                    {
                        CreateStandardPanel(l,
                                            0,
                                            envelope.Height,
                                            0.1,
                                            t,
                                            panelMat,
                                            out FacadePanel panel);
                        output.model.AddElement(panel);
                    }

                    var parapetLine = new Line(new Vector3(s.Start.X, s.Start.Y, envelope.Height), new Vector3(s.End.X, s.End.Y, envelope.Height));
                    var parapet     = new StandardWall(parapetLine, 0.4, 0.9, panelMat);
                    output.model.AddElement(parapet);
                }
                catch (System.Exception ex)
                {
                    System.Console.WriteLine(ex);
                }
            }

            return(output);
        }