예제 #1
0
        /// <summary>
        /// Create the Polygonal Faces for a new Tessellated Solid by extruding the given loop along the given normal.
        /// </summary>
        /// <param name="loops"></param>
        /// <param name="extrudeDirection"></param>
        /// <param name="extrusionHeight"></param>
        /// <param name="midPlane"></param>
        /// <returns></returns>
        public static List <PolygonalFace> ExtrusionFacesFrom3DLoops(this IEnumerable <IEnumerable <Vector3> > loops, Vector3 extrudeDirection,
                                                                     double extrusionHeight, bool midPlane = false)
        {
            // for consistency with adding the extrusionHeight to the base plane, negate if it comes in negative
            if (extrusionHeight < 0)
            {
                extrusionHeight  = -extrusionHeight;
                extrudeDirection = -1 * extrudeDirection;
            }
            // find transform to the XY plane and store the backTransform (the transform back to the original)
            var transform = MiscFunctions.TransformToXYPlane(extrudeDirection, out var backTransform);
            // make paths, the 2D polygons represening the 3D loops
            var paths = loops.Select(loop => loop.ProjectTo2DCoordinates(transform, 0, true));
            // the basePlaneDistance defines the plane closer to the origin. we can get this from the any input coordinate
            var basePlaneDistance = extrudeDirection.Dot(loops.First().First());

            if (midPlane)
            {
                basePlaneDistance -= extrusionHeight / 2.0;
            }
            var polygons = paths.CreateShallowPolygonTrees(false);

            return(polygons.SelectMany(polygon => Extrude.ExtrusionFacesFrom2DPolygons(polygon,
                                                                                       extrudeDirection, basePlaneDistance, extrusionHeight)).ToList());
        }
예제 #2
0
        /// <summary>
        /// Create the triangular faces of an extruded solid from 2D paths.
        /// </summary>
        /// <param name="paths">The paths.</param>
        /// <param name="basePlaneNormal">The base plane normal.</param>
        /// <param name="basePlaneDistance">The base plane distance.</param>
        /// <param name="extrusionHeight">Height of the extrusion.</param>
        /// <returns>List&lt;PolygonalFace&gt;.</returns>
        public static List <PolygonalFace> ExtrusionFacesFrom2DPolygons(this IEnumerable <IEnumerable <Vector2> > paths, Vector3 basePlaneNormal,
                                                                        double basePlaneDistance, double extrusionHeight)
        {
            var polygons = paths.CreateShallowPolygonTrees(false);

            return(polygons.SelectMany(polygon => Extrude.ExtrusionFacesFrom2DPolygons(polygon,
                                                                                       basePlaneNormal, basePlaneDistance, extrusionHeight)).ToList());
        }