Cast shadow
Shadows indeed add a beautiful depth to objects. We architects love casting shadows on buildings; it enhances the perception of the structure and adds an artistic touch.
I wondered if it was possible to extract the geometry of shadows for further analysis. This curiosity was resolved when I discovered the ExtrusionAnalyzer
class.
The methodology of this class is straightforward: submit the solid, the plane where the shadows will be cast, and the direction of the shadow. By following these steps, you can obtain the geometric shape of the shadow cast by an object.
Extracting Solid Geometry
To begin, you can get the solid from an element using the Geometry(Options)
function. Here are the recommended settings for the Options
:
new Options {
ComputeReferences = false, // not required
IncludeNonVisibleObjects = false // not required
}
When retrieving a GeometryElement
from instances such as Families or DirectShapes, the solids within may appear merged. For example, DirectShapes return a collection of faces as a single solid, even if multiple solids are present. An interesting case occurs with a Model in Place component containing three geometric shapes: using GeometryInstance.GetGeometry()
results in two solids. One solid includes all necessary information combined with the faces of all three geometries and has a non-zero volume. The second solid contains empty faces with zero volume.
To separate these combined solids, you can use the static function SolidUtils.SplitVolumes(Solid)
. This function returns separated transformed solids and, when used with ExtrusionAnalyzer
, provides the expected results.
Example Code
Below is an example of how to generate model lines that reflect the outer edges of shadows:
foreach (GeometryObject geomObj in ge)
{
if (geomObj is Solid combinedSolids)
{
if (combinedSolids.Volume == 0)
continue;
var solidSplits = SolidUtils.SplitVolumes(combinedSolids);
foreach (var solid in solidSplits)
{
ExtrusionAnalyzer ea = ExtrusionAnalyzer.Create(solid, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero), XYZ.BasisZ);
List<CurveLoop> loops = ea.GetExtrusionBase().GetEdgesAsCurveLoops().ToList();
foreach (CurveLoop loop in loops)
{
foreach (Curve curve in loop)
{
makeLine(doc, curve.GetEndPoint(0), curve.GetEndPoint(1));
}
}
}
}
}
While this approach effectively addresses the task, it does not fully explain why ExtrusionAnalyzer
fails to identify all solid geometries, selecting only the initial one.
this topic was also raised on Autodeskforum
Subscribe to my newsletter
Read articles from Moustafa Khalil directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Moustafa Khalil
Moustafa Khalil
I'm Moustafa Khalil El-Sayed, an Egyptian native with a passion for architecture and technology. After completing high school in 1999, I embarked on my journey into architecture, earning my Bachelor's degree in Architecture in 2004. My academic pursuits continued, and I later acquired my Master's degree in Architecture from Wings University. However, my thirst for knowledge extended beyond architectural design, leading me to pursue a degree in Computer Science as well. Driven by a desire to innovate, I began self-teaching computer science, which later empowered me to achieve my Associate degree in Computer Science from the University of the People more easily. Armed with dual expertise in architecture and computer science, I've cultivated a unique skill set that blends creativity with technical acumen. My career has taken me across borders, from Egypt to Oman and the UAE, where I've honed my skills as an architect. As a graduate architect and a proficient .NET BIM Solution Developer, I specialize in translating unique visions into tangible realities. My role extends beyond conventional architectural practices; I leverage technology to streamline processes and enhance project outcomes. My journey into programming began with developing script-based Excel tools to augment project management efforts, notably during the Sharm El Sheikh development. Over time, I expanded my programming prowess to address practical challenges encountered in bridging Revit and AutoCAD within my professional sphere. Several of my applications, born from this evolution, have gained recognition, with some even being featured on the Autodesk website. I am committed to pushing boundaries and continually enriching the intersection of architecture and technology, ensuring that my clients benefit from cutting-edge solutions tailored to their needs.