Example #1
0
        /// <summary>
        /// Does this ray intersect with the provided GeometricElement? Only GeometricElements with Solid Representations are currently supported, and voids will be ignored.
        /// </summary>
        /// <param name="element">The element to intersect with.</param>
        /// <param name="result">The list of intersection results.</param>
        /// <returns></returns>
        public bool Intersects(GeometricElement element, out List <Vector3> result)
        {
            if (element.Representation == null || element.Representation.SolidOperations == null || element.Representation.SolidOperations.Count == 0)
            {
                element.UpdateRepresentations();
            }
            List <Vector3> resultsOut           = new List <Vector3>();
            var            transformFromElement = new Transform(element.Transform);

            transformFromElement.Invert();
            var transformToElement        = new Transform(element.Transform);
            var transformMinusTranslation = new Transform(transformFromElement);

            // This transform ignores position so it can be used to transform the ray direction vector
            transformMinusTranslation.Move(transformMinusTranslation.Origin.Negate());

            var transformedRay = new Ray(transformFromElement.OfPoint(Origin), transformMinusTranslation.OfVector(Direction));
            //TODO: extend to handle voids when void solids in Representations are supported generally
            var intersects = false;

            foreach (var solidOp in element.Representation.SolidOperations.Where(e => !e.IsVoid))
            {
                if (transformedRay.Intersects(solidOp, out List <Vector3> tempResults))
                {
                    intersects = true;
                    resultsOut.AddRange(tempResults.Select(t => transformToElement.OfPoint(t)));
                }
                ;
            }
            result = resultsOut;
            return(intersects);
        }
Example #2
0
        public static Elements.Floor[] FloorsFromRevitFloor(ADSK.Document doc, ADSK.Floor revitFloor)
        {
            var profiles  = GetProfilesOfTopFacesOfFloor(doc, revitFloor);
            var thickness = revitFloor.LookupParameter("Thickness")?.AsDouble();

            var floors = new List <Elements.Floor>();

            foreach (var profile in profiles)
            {
                var zMove     = profile.Perimeter.Vertices.Max(v => v.Z);
                var transform = new ElemGeom.Transform(0, 0, -zMove);

                var zeroedProfile = transform.OfProfile(profile);

                transform.Invert();
                var floorThickness = thickness.HasValue ? Elements.Units.FeetToMeters(thickness.Value) : Elements.Units.FeetToMeters(1);
                // Revit floors are extrusions down, and currently Hypar floors are extrusions up, so we also must move by the floor thickness
                transform.Move(new Vector3(0, 0, -floorThickness));
                var floor = new Elements.Floor(zeroedProfile,
                                               floorThickness,
                                               transform);
                floors.Add(floor);
            }
            return(floors.ToArray());
        }