Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. Be respectful, on topic and if you see a problem, Flag it.

If you would like to contact our Community Manager personally, feel free to send a private message or an email.

How to make a light source that lets my model cast a shadow

GunterGunter Member Posts: 8 ✭✭
I reconstructed the digital sundial from www.mojoptix.com in Onshape but since it will take upwards of 20 hours to 3D-print I need to test it first.  My model is here:
Testing means shining a far-away light on it and checking the light/shadow pattern of dot matrix numbers resulting below the gnomon.
I tried suspending a large rectangle above the gnomon and extruding it, but of course the extrusion flows around obstructions - o good.  Extruding up to next and up to part failed.
I tried the ray tracer featurescript but it has no check box for simply blocking, i.e. absorbing light.  Possibly I could manage to add absorption to the code but the problem is I'd need ~100,000 rays to image the whole gnomon and 30,000 even to check one digit at a time with rays in a 2D field of 60mm x 20mm spaced about 0.25mm apart.
The renderer/shader built into Onshape almost does what I need, it just doesn't cast light around objects and make shadows.  Is there any way to bend that to my needs?
Thanks


Best Answer

Answers

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,686
    This is a bit rudimentary, but should do what you need:
    https://cad.onshape.com/documents/72598ea70a78b9bf66126b3a


    Senior Director, Technical Services, EMEAI
  • GunterGunter Member Posts: 8 ✭✭
    Thanks, Neil, you're as responsive as ever.
    Your feature doesn't work for me yet:  No matter what part of my gnomon I select, it complains that it "cannot determine rotation axis".  I'll have to analyze the code for why; maybe my structure is too complex.

    Thinking about Onshape's built-in shader I came up with a partial solution of my own:  Instead of the "sun" casting a shadow from above, reverse the view and look into the pixel holes from below.  Depending on the viewing angle the "sun" should be visible through the active pixels.  With a black gnomon and a bright red "sky" wrapped around the cylindrical top of the gnomon I can indeed see which pixels are active at what view.  The solution is partial because I don't know how to define a viewing vector such as [0, sin(angle), cos(angle)].  I kludged up a fan of transparent flat sheets at angles between -45⁰ (10AM) and +45⁰ (4PM) in 5⁰ steps corresponding to the 20-minute resolution of the sundial.  Now I can count the sheet edges on both side of the centerline to roughly figure the angle.  But dragging the view with the mouse is awkward and I keep veering off the straight line which tilts the view on the wrong axes.
    Is there a way to define the viewing vector?
    Thanks
  • GunterGunter Member Posts: 8 ✭✭
    Awesome!
    I didn't know that I had to have the light source on a line.  Thank you very much, also for the mate connector idea.
  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,050 ✭✭✭✭✭
    @NeilCooke

    Wouldn't you be able to use the opSplitBySelfShadow function and then offset the invisibleFaces that are returned?
    https://cad.onshape.com/FsDoc/library.html#opSplitBySelfShadow-Context-Id-map
    mb - draftsman - also FS author: View FeatureScripts
    IR for AS/NZS 1100
  • GunterGunter Member Posts: 8 ✭✭
    I saw some suspicious differences in the results of the shadow feature script compared to looking into the pixels from below and made a test case with "secondary" surfaces not directly connected to the "object" face.  The results differ between applying the feature script before and after re-selecting the foot of the column as the object:
    Edit (re-apply) shadow script after adding the extra shapes but without changing the object selection:
    Re-apply the shadow script, selecting the column foot again:
    Both shadows are wrong but in different ways.
    It seems that the shadow script needs to somehow recurse to collect shapes/surfaces that are touching the original object shape.  I'll have a look but that may be beyond my feature script programming capabilities.
  • GunterGunter Member Posts: 8 ✭✭
    OK, here is my favorite solution to my particular shadow casting problem; particular in that I need to check which pixels on my sundial gnomon light up, i.e. which paths through my object are clear when illuminated at a given angle.
    I made a new empty assembly and inserted my gnomon,  I change the view to look at the bottom of the gnomon by clicking on the view cube so I know I'm exactly normal.    The active pixels will have a clear path through which I see the background.  Now I grab the mate connector that sits on the part's axis of rotation and drag to rotate it.  This opens a small dialog for the angle where I type in the exact angle I want.  And the dialog stays open so I can just keep typing in new numbers.
    The response is instantaneous because the model itself is static, unlike when I rotate the part in a part studio.  There it's part of the whole model which gets re-evaluated with every change - much slower (several seconds) on my slow hardware.

  • sebastian_glanznersebastian_glanzner Member, Developers Posts: 423 PRO
    @Gunter

    Another solution would be the rendering software KeyShot Pro.
    • Set the environment to "Sun and Sky"
    • Chose a location, date and time
    • Or set the Sun to a custom inclination
    • Set the Lighting to "Product"
    You can get a trial version of KeyShot Pro here:
    https://www.keyshot.com/resources/downloads/

    Here is a quick example how it would look like:





  • ethan_barbourethan_barbour Member Posts: 4 EDU
    I was able to recreate @NeilCooke 's demonstration. But when I try it on my existing model, I get the message "No faces were selected for the extract surface operation.". Here is the model: https://cad.onshape.com/documents/a3888ef888ccf8a28b67c6f8/w/5416dfa1fbfc52c9ed6c9fc4/e/8b15ec5c03268f75a375858e?renderMode=0&uiState=624b4f4dbaf8243b56c33ec2

    This is a house with the back porch, which has a post in the middle. The sun is facing the porch. I am trying to generate the shadow of this post. Any help would be appreciated. (BTW, when I recreated Neil's demonstration, it only worked if my light vector originated at the origin. I couldn't get it to work if I used any other point to make this vector. In my current model of the house, I am using the origin to make the light vector.)
  • S1monS1mon Member Posts: 2,986 PRO
    Since this thread was last active, there's also the addition of Render Studio (for Pro/Enterprise). Seems like it should be able to cast correct shadows, but I'm just getting started with it.

    https://www.onshape.com/en/resource-center/videos/render-studio-photo-realistic-rendering-in-the-onshape-platform
Sign In or Register to comment.