This documentation is for the free plugin Py4D in CINEMA 4D R11.5 and not for the C4DSDK of Python in CINEMA 4D R12. For R12, please visit PluginCafe.com

c4d.utils.GeRayCollider - a ray collider class

Evaluates intersections between a ray and a polygon object. The ray is defined by two points. The vector between these two points represents the ray. Ray Point1 defines the starting position of the ray, Ray Point2 its end position. These two points enable you to define not only the direction of the ray, but its length also.

../../../_images/main.jpg

In the example above, a ray is generated between the two triangles.

class c4d.utils.GeRayCollider

Methods

GeRayCollider.__init__()
Return type:GeRayCollider
Returns:A new ray collider.
GeRayCollider.Init(goal[, force=False])

Initalizes the ray collider with the object specified by goal.

Parameters:
  • goal (BaseObject) – The object to check for intersections. The object is copied.
  • force (bool) – If force==False then the app checks if the passed object’s GetDirty(DIRTY_DATA) is unchanged. If yes, it does nothing and returns True. If force==True it always rebuilds the cache.
Return type:

bool

Returns:

True if successful, otherwise False.

GeRayCollider.Intersect(ray_p, ray_dir, length[, only_test=False])

Checks if the line segment specified by ray_p to ray_p + ray_dir*ray_length intersects the object.

Parameters:
  • ray_p (Vector) – Start point of the ray in object coordinates
  • ray_dir (Vector) – Ray direction in object coordinates.
  • ray_length (number) – Ray length
  • only_test (bool) – If this is True no information about the intersections are stored, so only the return value can be used to tell if there were intersections or not.
Return type:

bool

Returns:

True if there was in intersection, otherwise False

GeRayCollider.GetIntersectionCount()

eturns the number of intersections found by GeRayCollider.Intersect().

Return type:int
Returns:Number of intersections.
GeRayCollider.GetIntersection(number)

Retrieves the intersection, found by GeRayCollider.Intersect(), by index:

intersection = rc.GetIntersection(id)

intersect["face_id"] # The polygon index, int
intersect["tri_face_id"] # If first half of quad or triangle face_id + 1, else -(face_id + 1), int
intersect["hitpos"] # Position of the intersection, c4d.Vector
intersect["distance"] # Distance to the intersection, float
intersect["f_normal"] # Face normal. (Not normalized.), c4d.Vector
intersect["barrycoords"] #Barrycentric coordinates of the intersection. (x = u, y = v, z = d), c4d.Vector
intersect["backface"] # True if the intersected face's normal points away from the camera, otherwise False, bool
Parameter:number (int) – Intersection index, 0 <= number < GeRayCollider.GetIntersectionCount().
Raises IndexError:
 Raise if intersection index is out of range.
Return type:dict
Returns:The intersection.
GeRayCollider.GetNearestIntersection()

Retrieves the intersection, found by GeRayCollider.Intersect(), closest to the start of the ray.

Return type:dict
Returns:The nearest intersection or None if there was no intersection.

Table Of Contents

This Page