If that M thing is using the RayShoot Method, that’s expected since trims are NOT supported (see SDK comments on geometry). However you can do that with other ways (Notify if you need a C# that does it).
1, I have related stuff (classic ccx + normal at closest point + reflection + …) but I’m not in the practice right now (and since there’s a critical F1 race in Japan this w/e [and MotoGP] … ).
2, I don’t use components (or add-ons) for baking by beans: just C# code. But you can pretend that this is some sort of add-on.
Until Monday … and staying on that RayShoot theme get this and have fun: Random (even or not) points are created on a Sphere (center at t on track curve) and then rays are shooted from the center to every point.
Well … other than Kim’s native thingy … I’ve found at home a C# that does RayShoot stuff (without RayShoot) meaning that he respects trims and multi reflections (obviously: recursion at work here). For a refraction option it requires some lines of code more.
i gues that solution works I just tried it for one triangle and seems to be a good solution. Do you know if there is a fast way to do a large amount of trimmed surfaces at the same time (and not doing them manually)
I am very knew to GH (about 3weeks of use)
I thought of this but I am sure there is a better solution
I Just took a look at this. This looks promising. I have a script using mosquito components (see my long comment bellow). but this only works with surfaces. no breps meshes or untrimmed surfaces. this would be a good solution in changing that without having to have any knowladge of C#.
i can manage on simple objects like a sphere. Each color is one part of the image above. just reflection. refraction refraction and then so.
I always culled away the rays that don’t end up hitting the ground plane because these don’t end up as caustics:
You are very kind but I don’t think so: since your beans (native stuff) and mine (code) have nothing in common … I can hardly see any practical help from my side.
The C# things (about 5 on that matter) that I have they don’t do business with meshes because I hate meshes. Meaning that some lines of code more are required. Since the general approach is “kinda” a RayShoot one (In fact is using classic Curve/Brep ccx events via a recursive Method) this is not a big deal. That said by Brep think any combo (solid or not) of trimmed BrepFaces or untrimmed ones. Like :
Anyway I’ve found 10 minutes to write a basic refraction Method: amuse yourself with these freaky lines that do freaky/ominous things (used in other freaky things) for computing the refraction of a given ray (inside or outside a solid).
You can’t do that (general case: anything around [open, closed Breps] + multi ray bending with regard all present Breps) without some sort of loop technique (in coding the most efficient is recursion). Anyway, found 15 minutes more to continue on that.
2 modes would be available: Multi Reflection or Multi Refraction (on solids) + Multi Reflection (BrepFaces). See some WIP results here: (either reflection or refraction):
Here’s a very simple demo thingy on that Snell law. You can do it obviously witth native components (but the other things that the forthcoming C# does … well … er … you can’t).
BTW: angleIn is the Vector3d angle between the Brep Normal (inversed if ray is inside) and the rayDirection (always inversed) with respect a plane defined from the hit point (origin) and the CrossProduct (rayDirection, Normal). Google: CrossProduct and given the opportunity do the DotProduct search as well. There’s native GH stuff on these I believe.
Observe that going from air to some material (with some R) is OK … but the other thing MAY or MAY NOT yield an “escaped ray”. If the ray is trapped inside we have a reflection (life sucks).
This means that the critical angle is related with the rayState (in/out) AND the angleIN AND the R value … meaning that there’s no need to include it as var (if the NaN test is considered an “elegant” way to cut the mustard) - NaN means Not a Number.
After all these Greek things here’s the general algo (Mode 1: Reflections, Mode 2: Refractions and Reflections):
For a given ray segment (last element on a Polyline describing the ray) get the hitPoint: sample all the ccxPts (ray segment as LineCurve VS a BrepList) and sort them against the ray start point distance. Get the first on the sorted List that IS NOT the hit point.
Get the hitBrepIndex: what is the Brep that bends the ray?
If Mode = 1 do a Reflection.
if Mode = 2
4.0 if the Brep is not a solid do a Reflection.
4.1. if the Brep is solid.
4.1.1 get the outAngle (taking into account the ray segment state [is inside/outside : this is where the hitBrepIndex comes to play]).
4.1.2 If the outAngle is valid (not Nan) do a Refraction.
4.1.3.If the outAngle is NaN do a Reflection (case: ray inside trying to go outside)
BTW: Reflection: rotate the ray segment Math.PI with respect the Brep Normal plane at the hit point. Reverse the new segment.
BTW: Refraction: rotate the ray segment (angleIn+ Math.PI-angleOut) with respect the plane defined via the CrossProduct as above. Reverse the new segment.
Put all the above into a loop (controlled via a loopCount var) and deal with any Brep List VS any ray List.
Here’s a visual demo on that trapped inside (Refraction) ray matter. Shooting from the inside of a Sphere that has R values (see overrideR) from 1.31 (Ice) to 2.41 (diamond). As the R grows less and less rays can escape … and for these values/settings captured and for that emit Topology diamond yields the same results as Mode 1 (Reflection).
sorry for replying so late. but I was super busy
Uptill now i haven’t even taken the critical angle into acount. I knew at some point I had to but not sure how.
Your small C# component just took care of that. I don’t really know about coding but I managed to modify it slightly for it to be usefull to me thank you for that!!
OK … try to do it with components (+ some Loop thingy the likes of Anemone) and if you fail: drop a word for the salvation.
Some tips more:
ALWAYS deal with any challenge having the general case in mind: For this thread this means any collection of Breps (open, closed, valid, invalid, good, bad, whatever) VS any collection of Rays.
DO NOT assume that if a given ray segment is inside in some Brep then the next one is outside: because you may have overlapping solids (that’s not possible in real-life but we are not living in real-life anyway). Take into account the direction of the Normal as well (for a closed Brep this points outwards - unless you Flip the Brep (LOL)) for reversing it (case: segment inside) etc etc.
Thus (at the expense of a few milliseconds more) test a segment by using a Point for inclusion (using say Curve.PointAtNormalizedLength (0.95)) for every ray segment.
DO NOT exclude any Brep (hitted previously) in any loop stage: because a blob type of Brep may intersect with a ray segment many times.
As a challenge try to mastermind a connectivity thingy as well: for any node of any final polyline ray … compute the index of the Brep that caused the bending (that’s a classic connectivity Tree - A MUST for any engineer worth the name).
You can assign different R values for any valid solid Brep present in the bList. geomRList samples these values. If is empty (as delivered) the 1.31 is assosiated to every solid. If geomRList has less values than the solids present then these are consumed in order and the last is assosiated with the remaining solids. If overrideR is != 0 then that value is assosiated with every solid. You can add any R value (but avoid R > 2.5).
The total Ray length (the length of the polyline, that is) is managed via the RL parameter. If some segment length is < document tolerance => segment is discarded.
The max hits is managed via the reflections parameter (should be named: hits or bounces, but anyway). So if you see some weird results increase that limit.
2 Modes are available: Reflection or Refraction (solids) + Reflection (non solids). If a given ray segment can’t escape then a Reflection is made.
Rays are either grid like or radial. They are made internally (that’s not very user friendly … I could add a few lines more in order to accept any user collection).
The critical angle is auto managed internally (acc the angleIn, the state of ray (in/out) and the R value per Brep).
Connectivity (as explained above) is also made: what Brep caused the bounce per node (ordered) per polyline ray.
R values are in fact complex numbers (real + imaginary) … but … let’s deal with the entry level case first.
Nurbs type of Breps yield bigger Elapsed times (for obvious reasons).
Use the best quality of espresso (and cigars) when playing with the thing.
All in all: you can pretend that this is some kind of add-on … or … learn C#, double click it and discover the big rabbit hole called coding. But why bother? in a few years from now an AI computer could do it for you (rendering you obsolete - no pain no gain).