On 25/01/2013 at 03:00, xxxxxxxx wrote:
Hi,
You can retrieve the current BaseDraw and call the methods to convert a point from world space to screen space (BaseView.WS()), screen space to camera space (BaseView.SC()) etc.
EDIT:
Here's how we can use BaseView methods (WS(), GetSafeFrame()) to test if the active object will be completely rendered:
import c4d
def TestPointInFrame(pt, frame) :
return pt.x > frame['cl'] and pt.x < frame['cr'] and \n pt.y > frame['ct'] and pt.y < frame['cb']
def main() :
if op is None:
return
# Get the current BaseDraw
bd = doc.GetActiveBaseDraw()
# Get the active object bouding box center and radius
rd = op.GetRad()
mp = op.GetMp()
# Build the active object bouding box
box = [c4d.Vector() for x in xrange(8)]
box[0] = c4d.Vector()
box[0].x = mp.x - rd.x
box[0].y = mp.y - rd.y
box[0].z = mp.z - rd.z
box[0] *= op.GetMgn()
box[1] = c4d.Vector()
box[1].x = mp.x + rd.x
box[1].y = mp.y - rd.y
box[1].z = mp.y - rd.z
box[1] *= op.GetMgn()
box[2] = c4d.Vector()
box[2].x = mp.x - rd.x
box[2].y = mp.y + rd.y
box[2].z = mp.y - rd.z
box[2] *= op.GetMgn()
box[3] = c4d.Vector()
box[3].x = mp.x - rd.x
box[3].y = mp.y - rd.y
box[3].z = mp.y + rd.z
box[3] *= op.GetMgn()
box[4] = c4d.Vector()
box[4].x = mp.x + rd.x
box[4].y = mp.y + rd.y
box[4].z = mp.z - rd.z
box[4] *= op.GetMgn()
box[5] = c4d.Vector()
box[5].x = mp.x - rd.x
box[5].y = mp.y + rd.y
box[5].z = mp.y + rd.z
box[5] *= op.GetMgn()
box[6] = c4d.Vector()
box[6].x = mp.x - rd.x
box[6].y = mp.y - rd.y
box[6].z = mp.y + rd.z
box[6] *= op.GetMgn()
box[7] = c4d.Vector()
box[7].x = mp.x + rd.x
box[7].y = mp.y + rd.y
box[7].z = mp.y + rd.z
box[7] *= op.GetMgn()
# Calculate bouding box coordinates in screen space
points = [c4d.Vector() for x in xrange(8)]
for i in xrange(len(box)) :
points[i] = bd.WS(box[i])
# Test if the current object is completely visible in the rendered safe frame
safeFrame = bd.GetSafeFrame()
for i in xrange(len(points)) :
visible = TestPointInFrame(points[i], safeFrame)
if not visible:
break
print "Active Object Completely Visible:", visible
if __name__=='__main__':
main()