Ray collision face id hits not producing desired results_ c4d python


Hi there,

i am trying to hide polygons not visible in a camera path animation. I have the script working to some degree. I am using the ray collider functions and storing the face_id hits in a list, this is producing some weird results. I have checked the path of the rays which seem correct. The rays don’t all seem to be registering a face hit when they definitely should be and some faces are being hit when they shouldn’t be. This is a test file I am working with (see attached) The polygons that are stored in the face_id hit list are then updating the polygon selection tag.

I have attached the script in a null in a python tag, so please run it from the script manager to test it. I couldn’t seem to attach the python file to this separately.

Any help would be much appreciated

A220522_raycol_0001.c4d (1.6 MB)


The raycollider works in the coordinate system of the target object. You are using the local point coordinates everywhere, which cannot work as your objects are all transformed.

raycollider_0001.c4d (1.6 MB)

Also, you do things unnecessarily twice, and you don’t deselect the selection tag content before adding to the selection.
There are still a few dubious polygons but it is possible that these stem from the patterned ray test. You may want to check the normals of the hit polygon (should point at the camera) to verify whether you got a backside. And very narrow polys may not get hit at all.


Hi Cairyn,
ah i’m a spoon face, that is brilliant thank you so much for your help. i’ve not seen the “~” being used before, what does this symbol mean in relation to this line ?
cameraStartRayPos * ~collisionMg


Matrix inversion (prefix), since you need to transform into that coord system (not out of)


I will need to brush up on my matrix maths


I am now trying to run the script using multi threading so that I can calculate the ray hits faster, but the hit list is empty currently in threaded mode, so no polys are selected. I’ve attached a test scene and my updated script.

220608_model with path.c4d (27.9 MB)
220608_occlusion_frustrum_threaded02.py (10.8 KB)