PDA

View Full Version : Create a clipping box


pswaney
02-26-2013, 02:48 PM
I was wondering if it is possible to create a clipping box, such that an object inside the box would appear fully, but if the object was scaled such that any part of it fell outside the box, that portion would be clipped.

I have tried to use multiple clipping planes, but when creating the box, I am only able to create clipping planes on three sides of the box, and never two parallel sides. If, for example, I try to create two clipping planes that would form the top and bottom of the box, the plane I create second supersedes the first. See the example below for this behavior. Any help would be greatly appreciated, thanks!

import viz
import vizshape
viz.go()

vizshape.addGrid(color=[0.2]*3)
viz.clearcolor(viz.GRAY)

sphere = vizshape.addSphere(radius=3)

sphere.clipPlane([1,0,0,-1],num=1)
sphere.clipPlane([1,0,0,1],num=2)

import vizcam
vizcam.PivotNavigate(center=[0,2,0],distance=10)

farshizzo
03-01-2013, 12:19 PM
It doesn't look like you are specifying the clip planes correctly. Here is a sample script that shows how to apply a clip box to the model:
import viz
import vizact
import vizshape
viz.go()

model = viz.add('logo.ive')

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)

def applyClipBox(node, center, size):

x,y,z = center
sx,sy,sz = [ v / 2.0 for v in size ]

node.clipPlane([1,0,0,x-sx],num=0)
node.clipPlane([-1,0,0,-x-sx],num=1)
node.clipPlane([0,1,0,y-sy],num=2)
node.clipPlane([0,-1,0,-y-sy],num=3)
node.clipPlane([0,0,1,z-sz],num=4)
node.clipPlane([0,0,-1,-z-sz],num=5)

BOX_CENTER = [0,2,0]
BOX_SIZE = [2,2,2]

applyClipBox(model,center=BOX_CENTER,size=BOX_SIZE )

box = vizshape.addBox(size=BOX_SIZE,pos=BOX_CENTER,color =viz.RED,lighting=False)
box.polyMode(viz.POLY_WIRE)

viz.clearcolor(viz.GRAY)
vizshape.addGrid(color=[0.2]*3)

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