Funny Behavior for Compounds of Triangles and Quads

22 views
Skip to first unread message

Adam Thompson

unread,
Mar 30, 2017, 12:19:03 AM3/30/17
to Glowscript Users
Bruce,

Apparently, there are some issues with forming compound objects that are a bit subtle. I ran into these issues while writing a program to track collisions (and thus pressure) in a ideal gas box.

However, I have simplified it to a much more approachable scenario.  (see http://www.glowscript.org/#/user/Adam_Thompson/folder/Test/program/Curve).

In this test, I try three different things:
  1. Create a (quad) compound of two triangles in the z=1 plane.
    (WORKS GREAT!)
  2. Create a compound of two triangles where one is in the x=1 plane, but the other is not.
    (WORKS, but appears shadowed)
  3. Create a (quad) compound of two triangles both in the x=1 plane.
    (Compound object completely disappears.)
The final compound appears to actually exist, because I can access its properties. It just doesn't reflect the properties themselves.

I don't see an error, but maybe I just missed something.

Thanks,
Adam Thompson

Bruce Sherwood

unread,
Mar 30, 2017, 10:51:58 AM3/30/17
to Glowscript Users
Comment out the compounding and you'll see that there's a problem with the second and third examples. The normal has to be constructed according to a "winding rule". From the documentation on triangles (the documentation should be improved to emphasize that the same winding rule applies to triangles in the xy plane.):

------------------------------------
If you don't explicitly specify a normal for a vertex, the normal is given the default value vec(0,0,1), pointing out of the screen. If the vertex is to be used in a triangle that does not lie in the xy plane, you need to specify a normal yourself. If the three vertices are ab, and c (in counter-clockwise order), and you want normals that are perpendicular to the triangle, you can calculate the normal like this:

(b-a).cross(c-b).norm()

The "vector cross product" produces a vector that is perpendicular to the plane defined by the two vectors b-a and c-b, the first two edges as you go around the triangle. If the fingers of your relaxed right hand curl in the direction a to b to c, your outstretched thumb points in the direction of the vector cross product.

---------------------------------------

A quick test is to change the normals in your second and third examples to <1,0,0>, and also put pauses between the triangle and compound statements. You'll find that all of the triangles display correctly, and the second compound now works.

However, you've uncovered a bug in compound, because after making the third set of triangles, compounding them does indeed make them disappear. This seems exceedingly odd, since the first and second examples seem very similar but don't behave this way. Interestingly, either of the following two schemes works:

t5=triangle(vs=[v9,va,vb])
t6=triangle(vs=[v9,vb,vc])
s = sphere(pos=vec(-1,0,0), radius=0.2)
scene.pause()
q3=compound([t5,t6,s])

q = quad(vs=[v9,va,vb,vc])
s = sphere(pos=vec(-1,0,0), radius=0.2)
scene.pause()
q3 = compound([q,s])

Thanks for the report, Adam!

Adam Thompson

unread,
Mar 30, 2017, 1:44:20 PM3/30/17
to glowscri...@googlegroups.com
Yes. I tried the compounding with sphere and it worked, but without done other object the triangles disappear. I should have mentioned that, sorry.

Thanks for the ideas about normals. I thought I had done that, but must have missed it. I will take a look when I get home this evening.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Glowscript Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/glowscript-users/bAMm0ZHqeUM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to glowscript-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Thompson

unread,
Mar 31, 2017, 3:10:34 AM3/31/17
to Glowscript Users
I simplified my approach further by removing the 2nd example, and changing the 1st and 3rd examples to a single quad instead of two triangles. Results are exactly the same.

It works in Glowscript 2.3 VPython, but not in Glowscript 2.4 VPython. That narrows it down a bit.

Then, I tried changing the language to Javascript: see http://www.glowscript.org/#/user/Adam_Thompson/folder/Test/program/Curve2-Javascript.
It works in Javascript, any recent version.

A side note:
  • I have noticed in that in each case, the original quad, and the compounded quad seem have different shading.
  • The shading change seems to be version/language dependent.
Hope this helps.

Bruce Sherwood

unread,
Apr 2, 2017, 8:59:58 PM4/2/17
to Glowscript Users
Now fixed. Thanks again for the clear report. The problem was that a compound object, like other objects, must not have an axis that is vec(0,0,0), which could happen with triangles or quads in the yz plane. I also added a bit more to the documentation on triangles and quads about how normals must be specified, with the correct "winding order".
Reply all
Reply to author
Forward
0 new messages