accessing individual components of a compound

43 views
Skip to first unread message

Gilles Dubois

unread,
Jul 6, 2025, 1:53:19 AMJul 6
to VPython-users
T is a compound object
I checked the documentation 
T.objectlist gives an error
T.first_argument gives an error
for obj in T: gives an error
so what ?
Thank you for reading

Gilles Dubois

unread,
Jul 6, 2025, 2:06:24 AMJul 6
to VPython-users
Here is Grok's (X|Ai) point of view :
Key Points About Compound Objects
  1. No Direct Access to Components: After creating a compound object, the individual objects (e.g., spheres, boxes) lose their independent identities. You cannot access them as separate objects because they are merged into a single mesh.
  2. Attributes of the Compound: The compound object has a single pos (position), axis (orientation), color, opacity, etc., which apply to the entire object.
  3. Workarounds: If you need to manipulate individual parts, you can either avoid using a compound object or recreate the compound with modified components.
If this is true, I'm afraid that there's no solution

Bruce Sherwood

unread,
Jul 6, 2025, 2:08:03 PMJul 6
to VPython-users
One other thing one can do is, before creating the compound, save the  bounding_box() information for each of the components.

Bruce

Michael Burns-Kaurin

unread,
Jul 6, 2025, 2:58:38 PMJul 6
to vpytho...@googlegroups.com
What are you trying to accomplish by breaking the compound into its original objects?  Is it possible to make a copy of the original object list before compounding?

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vpython-users/0d340c35-f512-446b-869f-57073c8870d2n%40googlegroups.com.

Michael Burns-Kaurin

unread,
Jul 6, 2025, 3:07:02 PMJul 6
to vpytho...@googlegroups.com
No, that won't work since the original objects are gone.  

John

unread,
Jul 6, 2025, 4:26:01 PMJul 6
to VPython-users
The documentation for compound mentioned the "group" object but that currently only works in webvpython and it currently is undocumented. However there is a demo of it where the car is a group object and the rotating wheels are also part of the group.
https://glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Car
In the demo the wheels are compound objects. The group object was announced in the forum in this post.
https://groups.google.com/g/glowscript-users/c/imHHgoyMah8/m/fbxhphm0AQAJ

Note that the group object only works in web vpython but it doesn't work in trinket.io

Gilles Dubois

unread,
Jul 6, 2025, 4:48:14 PMJul 6
to VPython-users
Thanks for your reactions. I need to perform some experiments before answering, it can take time. Please wait .

Gilles Dubois

unread,
Jul 6, 2025, 7:06:39 PMJul 6
to VPython-users
Here are some precisions about my purpose
I want to represent one by one all platonic solids
So I took some inspiration from this sample program (BTW the cube is one of the platonic solids but fortunately the box is a native object in vpython) 
So from my first experiments with vpython I understood that it is a real 3D library and dealing with 'flat' objects can be uneasy. In another program about conic sections I use a thin box to materialize a plane. So I understood that flat things are built in the xy reference plane, then send to space by transformations as rotations, changes of position, etc. etc..
My idea was to start from the patterns, for example as shown on this picture
platonic.png
and to fold by rotating along edges with angles given for example in the wiki.
For three of them it's possible to work with simple triangles, but I wanted to build my own polygon object for general purpose, which I did.
My final solid is a compound of polygons which are themselves compounds of triangles mostly rotated from initial position.
So we can say that such object can be considered as complex.
I want to show any of these solids in slow rotation, the example gives the solution.
To stop and restart again motion  following the example was enough.
My next problem was to change color.
The ideal was a drop list with choices to get an 'on the fly' color change.
See my test program here with a dummy setcolor doing now nothing after all my failing attempts.
For commodity and communication between functions I use global variables which is not necessary, they will disappear in the final release.
For example the init_scene function uses the global couleur, to color vertices, which in turn give their color to triangles, which give their color to polygons, which give their color to solids, but of course I understand that there is nothing like the color of a compound
The way the program is written it is not too difficult to begin with an input from console and to color the tetrahedron according the user's initial wish, but what about changing color dynamically from a drop list ?
My simple idea was to change the value of the global couleur and to call init_scene that would start from the beginning all over again.. Alas! it doesn't work. No error message but the scene canvas simply disappears and only the two widgets stay visible. 
My second idea was to work in depth accessing the polygons individually, then the triangles, then the vertices  which have a color attribute and to alter this attribute, but this I don't know how to do it and it seems that my new friend GROK (I was introduced by John) doesn't know either.

Michael Burns-Kaurin

unread,
Jul 6, 2025, 8:48:25 PMJul 6
to vpytho...@googlegroups.com
If I specify a color in polygon (to get around the dummy color function), it seems to work.  Well, at first it did not work, then I played around and then it worked.  Can you put a link to a version with a working color change?
Here is what I did

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.

John

unread,
Jul 6, 2025, 9:21:38 PMJul 6
to VPython-users
Here is a version with the color menu working.

I changed the lines 14 and 15 to not specify the color
      #self.vertices.append(vertex(pos=vector(x, y, 0), color=col,opacity=op))
      self.vertices.append(vertex(pos=vector(x, y, 0), opacity=op))
    #self.center = vertex(pos=vector(c[0],c[1],c[2]), color=col,opacity=op)  # Center point
    self.center = vertex(pos=vector(c[0],c[1],c[2]), opacity=op)  # Center point

and I changed the setcolor(choix) routine to 

 def setcolor(choix):#dummy function does nothing
    global T
    #console.log(choix)
    val=choix.selected
    if choix.index < 1:
        pass
    elif val=='bleu':
        T.color=color.blue
    elif val=='rouge':
        T.color=color.red
    else:
        T.color=color.green

If you remove the comment on the line
#console.log(choix)
you can check the javascript console to see the value of choix passed into setcolor routine.

John

unread,
Jul 6, 2025, 9:36:15 PMJul 6
to VPython-users
I also added 

    T.color=couleur

in init_scene() after T is created and I added green to the list of colors in the menu.


def setcolor(choix):#dummy function does nothing
    global T
    #console.log(choix)
    val=choix.selected
    if choix.index < 1:
        pass
    elif val=='bleu':
        T.color=color.blue
    elif val=='rouge':
        T.color=color.red
    elif val=='vert':
        T.color=color.green
    else:
        T.color=color.cyan


stopbtn = button(bind=stop_restart, text='stop', background=color.red)
menu(choices=['Choisir une couleur', 'bleu', 'rouge', 'vert'], index=0, bind=setcolor)

John

unread,
Jul 6, 2025, 10:01:39 PMJul 6
to VPython-users
You can also change the color the shape using sliders. I used the code from one of the vpython demo programs to add sliders to adjust the color.

https://glowscript.org/#/user/johncoady/folder/AI/program/Platonic3

Gilles Dubois

unread,
Jul 7, 2025, 9:53:02 AMJul 7
to VPython-users
Thanks again John for your help.
Your suggestion works perfectly.
I rewrote the program according your modifications and add a few others.
I removed the console input from the beginning.
I canceled the color and opacity parameters of the constructor of class Polygon. In fine what is useful is only the last two instructions of init_scene
T.color=couleur
T.opacity=opa
And just to make tests I changed in editor the value of opa to check that effect was as expected.
So I decided to adjust opacity on the fly as well and repeated for opacity what your did for color with a slider instead of a droplist
Result is here
Unfortunately it doesn't work, I changed both the value of global opa and directly of T.opacity as well with sl.value() and nothing happens, opacity stays 0.5 as it was decided in init_scene
Do you see any possible reason ?

John

unread,
Jul 7, 2025, 10:37:46 AMJul 7
to VPython-users
When you put the line 
console.log(sl)
back into the program to debug it and check the javascript console for error messages you will find the following error message.

Uncaught (in promise) TypeError: sl.value is not a function

So I modified your setopacity() to the following where I pass in parameter sl

def setopacity(sl):
    global T,opa
    #console.log(sl)
    wt.text='{:1.2f}'.format(sl.value)
    opa=sl.value
    T.opacity=sl.value
    
and it works now

Gilles Dubois

unread,
Jul 7, 2025, 10:39:06 AMJul 7
to vpytho...@googlegroups.com

Thank you, John !

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.

Gilles Dubois

unread,
Jul 12, 2025, 3:30:42 AMJul 12
to VPython-users
Showing all 5 platonic solids with 2 associated spheres and contact points 
Reply all
Reply to author
Forward
0 new messages