WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Moveable clipping box (https://forum.worldviz.com/showthread.php?t=6140)

simrus 05-08-2018 12:42 PM

Moveable clipping box
 
Hi

I'd like to create a clipping box like this
http://forum.worldviz.com/showthread...light=clipping

but where I can move (translate and rotate) the clipping box.

I'm struggling to find a solution. Can anyone help?

simon

Jeff 05-08-2018 05:21 PM

Here's an example. Use the left and right arrow keys to move the box:

Code:

'''
Move the clip box left and right
with the arrow keys
'''

import viz
import vizact
import vizshape
import vizinfo
viz.go()

vizinfo.InfoPanel()

class MovingClipBox():
        def __init__(self,node,center,size):
               
                self.node = node
                self.x,self.y,self.z = center
                self.sx,self.sy,self.sz = [ v / 2.0 for v in size ]
                self.applyClipBox()       
                self.box = vizshape.addBox(size=size,pos=center,color=viz.RED,lighting=False)
                self.box.polyMode(viz.POLY_WIRE)

        def applyClipBox(self):
               
                self.node.clipPlane([1,0,0,self.x-self.sx],num=0)
                self.node.clipPlane([-1,0,0,-self.x-self.sx],num=1)
                self.node.clipPlane([0,1,0,self.y-self.sy],num=2)
                self.node.clipPlane([0,-1,0,-self.y-self.sy],num=3)
                self.node.clipPlane([0,0,1,self.z-self.sz],num=4)
                self.node.clipPlane([0,0,-1,-self.z-self.sz],num=5)
               
        def getBoxCenter(self):
                return [self.x,self.y,self.z]

        def setBoxCenter(self,center):
                self.x,self.y,self.z = center
                self.applyClipBox()
                self.box.setPosition(center)
               
viz.clearcolor(viz.GRAY)
vizshape.addGrid(color=[0.2]*3)
model = viz.add('logo.osgb')

expand = vizact.sizeTo([3,3,3],speed=0.5)
shrink = vizact.sizeTo([1,1,1],speed=0.5)
model.runAction(vizact.sequence(expand,shrink,viz.FOREVER))
model.runAction(vizact.spin(0,1,0,20,viz.FOREVER),pool=1)
                               
BOX_CENTER = [0,2,0]
BOX_SIZE = [2,2,2]
movingClipBox = MovingClipBox(model,center=BOX_CENTER,size=BOX_SIZE)

import vizcam
vizcam.PivotNavigate(center = BOX_CENTER, distance = 10.0)

def updateClipBox():
       
        x_change = 0
        if viz.key.isDown(viz.KEY_LEFT):
                x_change -= 0.01
        elif viz.key.isDown(viz.KEY_RIGHT):
                x_change += 0.01
        if x_change != 0:
                center = movingClipBox.getBoxCenter()
                center[0] += x_change
                movingClipBox.setBoxCenter(center)

vizact.onupdate(0,updateClipBox)



All times are GMT -7. The time now is 06:50 AM.

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