TraceGeometryEnhanced() [SOLVED]

On 21/01/2016 at 15:37, xxxxxxxx wrote:

User Information:
Cinema 4D Version:    
Language(s) :


I can't get VolumeData::TraceGeometryEnhanced() to work properly for me. Maybe I don't understand
the docs correctly. I've previously been using TraceGeometry(), but now I need to exclude certain objects
from the tracing, thus I want to use TraceGeometryEnhanced() to do another trace, ignoring the
previous hit (at least that is what I understand that this method can be used for).

vps->vd->GetRay(x, y, &ray);
Bool hit = false;
RayHitID lhit;
Vector64 oldray;
RAYBIT const raybits = RAYBIT_0;
Int32 const raydepth = 0;
while (true) {
  hit = vps->vd->TraceGeometryEnhanced(&ray, MAXREALr, lhit, raydepth, raybits, &oldray, &si);
  if (!hit || !si.op || !si.op->link) {
  if (!needs_to_be_excluded(si.op->link)) {
  lhit =;

I run into an infinite loop when an object is to be excluded. Is the function used for what I think it
is used? If yes (or not) how can I make it work?


On 22/01/2016 at 01:18, xxxxxxxx wrote:


I'm not quite sure about your code, can you explain a little bit more how it is supposed to work? What does needs_to_be_excluded() do?

Best wishes,

On 22/01/2016 at 03:16, xxxxxxxx wrote:

not sure where the problem lies.
but a notice:
in the first iteration: make oldray = NULL "just pass NULL"
oldray = ray at the loop end

On 22/01/2016 at 05:47, xxxxxxxx wrote:

Hey Sebastian,

I want to ignore some objects when using TraceGeometryEnhanced(). The needs_to_be_excluded()
function is a place holder for any logic that determines whether the object that was currently hit should
be ignored or not.


Well the ray at the loop end is the same as before, no? But you actually gave me an idea! And it seems
to work exactly the way I want it to! I just need to offset the ray position to the hit position.

This is the actual code, without placeholders:

        // Compute the camera ray for the current pixel.
        Ray ray;
        vps->vd->GetRay(x, y, &ray);
        // Trace geometry from the ray. We trace until we find geometry
        // that we actually want to render (we can exclude objects with
        // a Paint & Stick tag).
        BaseTag* tag = nullptr;
        Bool hit = false;
        RayHitID lhit;
        while (true) {
          hit = vps->vd->TraceGeometryEnhanced(&ray, MAXREALr, lhit, 0, RAYBIT_0, nullptr, &si);
          if (!hit || !si.op || !si.op->link) {
          // Determine if the object should be excluded from the tracing.
          tag = pns::find_pns_tag(si.op->link);
          Bool const exclude = tag && pns::get_param(tag, PAINTNSTICK_TAG_EXCLUDEFROMRENDER).GetBool();
          if (!exclude) {
          tag = nullptr;
          lhit =;
          ray.p = si.p;    //< That does what I want
        if (!hit) {

Sometimes you just need to pose the question and eventually get the slightest input for a new idea. :joy:

PS: If there is a more efficient solution (eg. something like "marking" objects as invisible for TraceGeometry()) please let me know!