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.

Optics: Custom Feature

EvanReeseEvanReese Member, Mentor Posts: 2,329 ✭✭✭✭✭

It's been a while since I released any in-depth custom features, but I'm excited to finally make this one public! Optics is a tool for real-time feedback of optical designs in Onshape. I won't go into great detail on the ins and outs here since I have a very thorough demo video, but here are some teaser images. Enjoy!

image.png image.png image.png
Evan Reese
Independent Onshape Consultant | Industrial Designer

Comments

  • EvanReeseEvanReese Member, Mentor Posts: 2,329 ✭✭✭✭✭

    special thanks to @jnewth and @Alex_Kempen for code review and wisdom and to @maximilian_schommer for creating and sharing the original Ray Tracer feature way back when which was an inspiration.

    Evan Reese
    Independent Onshape Consultant | Industrial Designer
  • S1monS1mon Member Posts: 3,296 PRO

    This looks great. The one immediate request I would have is how to better simulate typical lambertian LED dispersion patterns.

  • eric_pestyeric_pesty Member Posts: 2,126 PRO

    That looks awesome!
    I second @S1mon 's request for a lambertian distribution (I guess under the "Rays/Shape"?)

    Another thing that could be super useful would if there was a way to visualize a "heatmap" on the target.
    I can see how that could be tricky to do but maybe dividing the target surface in x sub-surfaces and applying a color based on the relative number of hits/area? Or even doing it manually for each selected target (i.e. do a zero offset surface of each one and apply a color based on density of hits).

  • EvanReeseEvanReese Member, Mentor Posts: 2,329 ✭✭✭✭✭

    Thanks!

    Can you both help me understand what you'll use Lambertian for? I looked into it during development, but need to do more reading. My understanding is that it has 2 basic properties: (1) it looks the same no matter the viewing angle (perfect diffusion) and (2) the luminous intensity is dependent on the angle of incidence. This feature currently has no concept of luminous intensity. A ray is a ray is a ray. As for even distribution, I think that's what I'm already getting with the Cone (Randomized) shape. The odds of a ray being anywhere within the cone is equal unless I overlooked something, which is possible.

    @eric_pesty I want to keep it simple (okay it's already not simple), and also not try too hard to develop a replacement for a "real" optical tool. My current thinking on a "heatmap" is to just turn off the ray previews and just look at the intersections of rays and targets like this. It's enough to get an intuitive feel for it I think. Anything else would just be a layer of abstraction on top of this anyway which just means more code and more compute. btw, if you "keep rays" and move the slider at the bottom of the feature UI you can get a very light ghosted preview of the rays. Thoughts?

    image.png image.png
    Evan Reese
    Independent Onshape Consultant | Industrial Designer
  • S1monS1mon Member Posts: 3,296 PRO
    edited December 2024

    LEDs (and other light sources) have distribution patterns. They're often not even - even theoretically. Typically the specs are shown in a polar plot where the 1/2 angle shows where 50% of the intensity and above light is concentrated. It's somewhat like taking a bell curve and wrapping it.

    Ideally your feature would at least take the 1/2 angle, and assume some common distribution pattern to show what's likely to happen.

    Blog-13_Figure-2.png


    https://www.bivar.com/resources/blog/led-emission-patterns-and-how-they-affect-your-application/

  • S1monS1mon Member Posts: 3,296 PRO

    I like the preview of the intersections of the rays and the output surface. That’s pretty helpful and similar to features in more dedicated tools.

  • eric_pestyeric_pesty Member Posts: 2,126 PRO

    Fair enough about keeping things simple and this not being a "full" analysis tool. However it's really not that far off!

    You've got the reflection and refraction covered and methods to shoot a bunch of rays through the geometry and that's really the bulk of it!
    While understand there is no concept of "intensity" of a ray in this model, my thought would be that the density of rays could be a good proxy for that.
    So instead of a cone with evenly distributed rays a lambertian distribution would have fewer and fewer rays at larger angles.

  • eric_pestyeric_pesty Member Posts: 2,126 PRO

    Used this today to get a feel for how realistic a more compact TIR would be (using the tip of hiding the "hits" to show the "density"):

    image.png image.png


    It's nice to be able to get a set of rays coming out from the face of the "LED" instead of a single point (like the Ray Tracer FS did) to take into account the size of the source.

    Detail of the rays used (face is the size of the primary LED lens):

    image.png
  • kenn_sebesta167kenn_sebesta167 Member Posts: 93 ✭✭

    So, so, so incredibly cool.

    A hackish answer in the short term would be to impose a mesh on top of the light source, with the mesh having a density of holes which matches the distribution pattern. Not ideal, perhaps, but offloads from @EvanReese the work of figuring out out to ingest an arbitrary radiation pattern.

  • MichaelPascoeMichaelPascoe Member Posts: 2,242 PRO

    This is very cool, must have missed the announcement a while back.

    Ty for sharing @EvanReese !


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • kenn_sebesta167kenn_sebesta167 Member Posts: 93 ✭✭

    Absolutely brilliant, and perfect timing. I was trying to make a light to illuminate my cockpit from a single source, and this gave me a great lens to try as a first step:

    Source: https://cad.onshape.com/documents/de0ffcf0722e4cb755a935b0/w/66f79fda38e50b49363829fc/e/97519f02910bfe5599a21d76?renderMode=0&uiState=67e0c501afd6660f54d9f74c

    Screenshot_2025-03-23_at_10.30.53_PM.png Screenshot_2025-03-23_at_10.33.28_PM.png
  • EvanReeseEvanReese Member, Mentor Posts: 2,329 ✭✭✭✭✭

    @kenn_sebesta167 I love seeing it used. I haven't had much opportunity to validate the feature with real-world testing, so please report back if you would. I'd love to know that it worked, or more importantly, if it's off somehow.

    Evan Reese
    Independent Onshape Consultant | Industrial Designer
  • kenn_sebesta167kenn_sebesta167 Member Posts: 93 ✭✭

    It worked really well and very easily. The main two hiccups I can think of right:

    1. In my model, I had to increase the ray length because they were not automatically extending to the target.
    2. The area generator makes a grid of rays, irrespective of the area's shape. So if I have a circle, it creates rays outside the circle's perimeter. (See graph.) Ideally, there FS would test to see each ray to see if it connects with the area, and if not would suppress that ray.
    Screenshot 2025-03-24 at 8.05.26 PM.png

    The next step is to print it out in some clear resin.

    (Actually, the real next step is to get a properly dimensioned model of the airplane cockpit, as I made some pretty coarse guesses.)

  • EvanReeseEvanReese Member, Mentor Posts: 2,329 ✭✭✭✭✭

    @kenn_sebesta167 Thanks for the feedback. I suppose I could cull points that aren't on the selected face. Good thought. Your use case makes me think that the point inputs should have something other than cones emanating from one point. They should probably also support some round or square grid shapes.

    I'd also love to know if the lack of lambertian distribution is actually getting in the way of people who are actually using the tool. If, so let me know.

    Evan Reese
    Independent Onshape Consultant | Industrial Designer
  • kenn_sebesta167kenn_sebesta167 Member Posts: 93 ✭✭
    edited April 21

    Another feature request would be to allow the user to keep the color of the lines after exiting the feature dialog. This would make it easier to use Final to see how changes to the lens help focus the light rays.

    Screenshot 2025-04-20 at 6.52.05 PM.png Screenshot 2025-04-20 at 6.52.58 PM.png

    That aside, this is looking really good for the airplane!

  • kenn_sebesta167kenn_sebesta167 Member Posts: 93 ✭✭
    edited April 21

    Whelp, I went ahead and "fixed" it:

    Screenshot 2025-04-20 at 9.05.15 PM.png

    Colors work with Final! Code for doing this is below:

        if (definition.keep && (definition.rayGrouping == RayGroupLevel.Rays))
        {
            opCreateCompositePart(context, id + "composite", { "bodies" : rayChainBody, "closed" : true });
            setProperty(context, {
                        "entities" : qCreatedBy(id + "composite", EntityType.BODY),
                        "propertyType" : PropertyType.NAME,
                        "value" : "Light ray"
                    });
                    
            // Check if the ray hits the target or not.
            result.hitsTarget = rayHitsTarget(context, rayChainBody, definition.targetFaces, definition.highlightTargetFaces);
            if (definition.colorByTarget && !isQueryEmpty(context, definition.targetFaces))
            {
                if (result.hitsTarget && definition.colorHits)
                {
                    setProperty(context, {
                        "entities" : qCreatedBy(id + "composite", EntityType.BODY),
                        "propertyType" : PropertyType.APPEARANCE,
                        "value" : color(0.1, 0.5, 0.2)
                    });
                }
                else if (!result.hitsTarget && definition.colorMisses)
                {
                    setProperty(context, {
                        "entities" : qCreatedBy(id + "composite", EntityType.BODY),
                        "propertyType" : PropertyType.APPEARANCE,
                        "value" : color(1.0, 0.1, 0.2)
                    });        
                }
            }
        }
    

    The above replaces the block at L629. There's no dialog to turn it on/off, I didn't know if you would want the above feature, nor if you did how you'd like the dialog to be done. (Sorry for dropping the code mod here, it would be awesome if OS had some kind of push request like Gitlab!)

  • EvanReeseEvanReese Member, Mentor Posts: 2,329 ✭✭✭✭✭

    @kenn_sebesta167 I like the idea. I went ahead and implemented it in V6, though I went about it a different way in the code. If you set the Grouping to "Rays" and are using a Target, it will keep the red/green for hits and misses. If grouping by Emitters or All it will keep whatever color you already had (like "Cyan").

    Evan Reese
    Independent Onshape Consultant | Industrial Designer
Sign In or Register to comment.