On 08/11/2017 at 16:44, xxxxxxxx wrote:
I also can't get CalculateVisiblePoints to work.
But I come with tree ways for testing if a point is visible or not.
Check if it's on the screen (didn't check if it's hide by other polygons)
def main() :
obj = op
if not obj:
return
bd = doc.GetActiveBaseDraw()
ptWithinScreen = list()
mg = obj.GetMg()
for pt in obj.GetAllPoints() :
screenPt = bd.WS(pt*mg) # Get point in world space to screen space
# Get if is in the screen
ptWithinScreen.append(bd.TestPoint(screenPt.x, screenPt.y))
#Ordered by ptID
print ptWithinScreen
Check if point is within the safe frame (didn't check if it's hide by others polygons)
def main() :
obj = op
if not obj:
return
bd = doc.GetActiveBaseDraw()
ptWithinScreen = list()
mg = obj.GetMg()
sf = bd.GetSafeFrame()
for pt in obj.GetAllPoints() :
screenPt = bd.WS(pt*mg) # Get point in world space to screen space
# Get if is withing safe frame or not
ptWithinSafeFrame.append(sf["cl"] <= screenPt.x <= sf["cr"] and sf["ct"] <= screenPt.y <= sf["cb"])
#Ordered by ptID
print ptWithinSafeFrame
And finally check if a point is hidden by another polygon from the camera (actually only check for self, you may have to take a look at this thread https://plugincafe.maxon.net/topic/708/13870_geraycollider-intersection-test-with-whole-scene and of course you can combine to see if bounding box of another object is within the direction of the ray), and of course you can combine this method with the two previous one, in order to only test points within screen.
def main() :
obj = op
if not obj:
return
bd = doc.GetActiveBaseDraw()
ptVisibleFromCamera = list()
mg = obj.GetMg()
# Init our Ray outside of the loop for efficiency
ray = c4d.utils.GeRayCollider()
ray.Init(obj)
for pt in obj.GetAllPoints() :
# Get if it's visible from camera
start = pt*mg
end = bd.GetMg().off
angle = (end - start).GetNormalized()
lenght = (end - start).GetLength()
result = ray.Intersect(pt, angle, lenght)
isVisible = True
for rayId in range(0, ray.GetIntersectionCount()) :
if ray.GetIntersection(rayId)["hitpos"] != pt:
isVisible = False
break
ptVisibleFromCamera.append(isVisible)
#Ordered by ptID
print ptVisibleFromCamera
Hope it's help !