WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Identifying different nodes (https://forum.worldviz.com/showthread.php?t=2213)

omidbrb 08-16-2009 06:07 PM

Identifying different nodes
 
Hi,

I´m using the screenToWorld and intersectLine functions to identify the object being seen at a specific point on the screen, like this:

http://www.worldviz.com/vizhelp/comm...ersectLine.htm

My question is, is it possible to distinguish between different polygons/subobjects in a 3D model? For example, different leaves of a tree model?

Thanks,
Omid

Jeff 08-19-2009 12:38 PM

The link you provided is for finding intersections with physics shapes, from your question though it sounds like you just want to see which sub-object was picked.

You can use viz.pick() to do that. This code uses the gallery model and prints out the name of the child object that is clicked on. If you right cick on gallery.ive in Vizard's resource window you can look through the hierarchy and see the matching names.

The name returned is for lowest object in the scene graph that was picked. If this sub-object does not have a name then the first named object above it will be returned.
Code:

import viz
viz.go()

#use keyboard navigation, mouse for picking
import vizcam
viz.cam.setHandler(vizcam.KeyboardCamera())

viz.add('gallery.ive')

def showPicked():
       
        #use viz.pick with mode = 1.  This will return a Vizintersect
        #object which we can use to retrieve the object' name
        object = viz.pick(1)
        if object.valid:
                print 'object name:  ', object.name
               
vizact.onmousedown(viz.MOUSEBUTTON_LEFT, showPicked)


omidbrb 08-25-2009 03:58 PM

Hi Jeff,

Thanks a lot for the reply. Pick works exactly as I expected. Unfortunately it doesn't return an id for unnamed objects.

Apart from that, I want to have a function similar to pick, but with arbitrary point in the screen (not bound to the mouse pointer). I wrote the following code, but it's far slower than the pick function. It takes about 5 seconds on each call, but the pick functions looks to be very fast. My question is, how can I implemnet "pick" function with arbitrary coordinate on the 2D screen to be as fast as pick?

Code:

def fireLineAtPointAndReturnIntersectingPoint(normX, normY):
    line = viz.screentoworld([normX, normY])
    dir = viz.Vector(line.dir)
    dir.setLength(200)
    begin = line.begin
    end = line.begin + dir
    info = viz.phys.intersectLine(begin,end)
    return info.point

By the way, I appreciate your instant replies in the forum.

Best,
Omid

farshizzo 08-28-2009 02:54 PM

Have a look at the documentation for the .pick command. You can specify an optional pos parameter that says where on the screen to perform the pick. If you don't specify a position, then it defaults to using the current mouse position.


All times are GMT -7. The time now is 10:21 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC