WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-18-2012, 11:19 AM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
PickRect code snippet

Example of window.pickRect that I though could be handy for other folks out in vizland:

Code:
import viz
import vizact

viz.go()

model = viz.add("mini.osg")
viz.MainView.setPosition([0, 1.2, -5])

viz.mouse.setOverride(viz.ON)
vizact.onkeydown(' ', viz.mouse.setOverride, viz.TOGGLE)

print model.getNodeNames()
parts = []
for name in model.getNodeNames():
    part = model.getChild(name)
    part.nodeName = name
    parts.append(part)


#Rectangle Pick 
viz.startLayer(viz.LINE_LOOP)
viz.vertex([0, 0, 0])
viz.vertex([0, 0, 0])
viz.vertex([0, 0, 0])
viz.vertex([0, 0, 0])
box = viz.endLayer(parent=viz.SCREEN)
box.alpha(.8)

firstPoint = [0,0]
def startPickRect():
    global firstPoint
    firstPoint = viz.mouse.getPosition()
    box.setVertex(0, firstPoint+[0])
vizact.onmousedown(viz.MOUSEBUTTON_LEFT, startPickRect)

def updateBoxVisual():
    if viz.mouse.getState() & viz. MOUSEBUTTON_LEFT:
        mouseScreenPos = viz.mouse.getPosition()
        box.setVertex(1, [mouseScreenPos[0],firstPoint[1],0])
        box.setVertex(2, mouseScreenPos+[0])
        box.setVertex(3, [firstPoint[0],mouseScreenPos[1],0])
vizact.onupdate(viz.PRIORITY_DEFAULT, updateBoxVisual)

def endPickRect():
    mouseScreenPos = viz.mouse.getPosition()
    #update box visual
    box.setVertex(1, [mouseScreenPos[0],firstPoint[1],0])
    box.setVertex(2, mouseScreenPos+[0])
    box.setVertex(3, [firstPoint[0],mouseScreenPos[1],0])
    
    rect = firstPoint + mouseScreenPos    
    # Get all nodes within the rectangle
    picked = viz.MainWindow.pickRect(rect)
    for node in picked:
        print node.nodeName
vizact.onmouseup(viz.MOUSEBUTTON_LEFT, endPickRect)
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Sphinx to generate code documents nabrahamson Vizard 0 10-31-2011 07:38 AM
Suggestion: Code Browser kopper Vizard 5 05-23-2011 03:39 AM
Any ideas on linking chess 3ds file with source code? djones1010 Vizard 1 04-24-2009 09:56 PM
Trying to integrate Source Code with Vizard djones1010 Vizard 1 03-10-2009 02:58 PM
Vizard Tip of the Month: Use Tasks to Simplify your Code Gladsomebeast Vizard 5 05-02-2008 04:30 PM


All times are GMT -7. The time now is 01:16 AM.


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