Vpython faces

104 views
Skip to first unread message

Saeed Akbar

unread,
Oct 15, 2016, 2:45:43 PM10/15/16
to VPython-users
I have imported .stl model using vpython faces with the example code mentioned by bruce sherwood in one of his replies to a post.. but the problem is i have to put the object in frame... and to move the object i have to move the frame... but scene.mouse.pick selects only one object all the time... may b the frame takes the whole space... i am not sure... can anyone help me in moving face object with mouse drag when there are multiple faces in the scene... thanks in advance

Bruce Sherwood

unread,
Oct 16, 2016, 9:55:02 AM10/16/16
to VPython-users
I don't understand the situation. Here is a program with a sphere and faces object in a moving frame, and I can pick either the sphere or the faces object (and if I click elsewhere I correctly get None):

from visual import *
scene.range = 2
fr = frame(pos=(1,1,0))
sphere(frame=fr, pos=(0,-2,0), color=color.orange, radius=0.3)
f = faces(frame=fr, pos=[(-1,-1,0), (1,-1,0), (1,1,0), (1,1,0), (-1,1,0), (-1,-1,0)],
          color=[color.red, color.red, color.red, color.cyan, color.cyan, color.cyan])
f.make_normals()
f.make_twosided()
t = 0
while True:
    rate(30)
    fr.pos = (-0.5+sin(t),1,0)
    t += .02
    if scene.mouse.events > 0:
        scene.mouse.getevent()
        print(scene.mouse.pick)

Saeed Akbar

unread,
Oct 16, 2016, 12:56:24 PM10/16/16
to VPython-users
thanks for your reply... the problem is still there... the problem arises when you import an external model from .stl file. In that case when i click anywhere on the scene the same object gets selected everytime even if i click on an empty area. thanks for your cooperation... it would be nice if you give it a try but by importing .stl object... 

Bruce Sherwood

unread,
Oct 16, 2016, 3:43:30 PM10/16/16
to VPython-users
You need to post an entire working program that displays the problem, as I cannot reproduce it.

I started from Convert STL 3D graphics files (Derek Lura and Bruce Sherwood) in the Contributed section of vpython.org, and I replaced the final part of convert_stl.py with this:

if __name__ == '__main__':
    #print "Choose an stl file to display. Rotate!"
    # Open .stl file
    #fd = get_file()
    #if not fd: continue
    scene.width = scene.height = 800
    #scene.autocenter = True
    #newobject = stl_to_faces(fd)
    newobject = stl_to_faces('Part1.stl')
    newobject.smooth() # average normals at a vertex
    newobject.color = color.orange
    newobject.material = materials.wood
    f = newobject.frame
    t = 0
    sphere(pos=(0,-2,0), radius=0.5, color=color.red)
    while True:
        rate(30)
        f.pos = (-0.5+sin(t),-1,0)
        t += .02
        if scene.mouse.events > 0:
            scene.mouse.getevent()
            p = scene.mouse.pick
            print(p)
            if p is not None:
                scene.mouse.pick.color = color.green

When I click on the faces object the print statement shows that I clicked on it, and the object turns green. When I click on the sphere object the print statement shows that I clicked on it, and the object turns green. When I click on the background the print statement correctly shows None.

Saeed Akbar

unread,
Oct 17, 2016, 3:31:03 PM10/17/16
to VPython-users
I tried my code on my friend's computer.... it works fine there... i can select individual object there... So the problem is in my computer and i have to figure it out... thanks for ur time and consideration Bruce Sherwood....
Reply all
Reply to author
Forward
0 new messages