Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    TraceGeometry

    SDK Help
    0
    6
    490
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 11/05/2015 at 12:08, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   15 
      Platform:   Windows  ;   Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      Working on a shader that calculates the distance from front surface of object to back surface of object.

      basic code is:

      if (sd->vd != nullptr)
          {
              SurfaceIntersection si = SurfaceIntersection();
              Vector64 point = sd->vd->p;
              
              while (sd->vd->TraceGeometry(sd->vd->ray, 999999, sd->vd->lhit, &si) == true)
              {
                  if (sd->vd->op == si.op)
                  {
                    distance += (si.p - point).GetLength();
                      point = si.p;
                  }
              }
          }

      In theory this should intersect the first point, trace to the next unique object intersection incrementing the distance.  This will continue until the ray exits ( which should occur because the material has no refraction, internal reflections ).  Removed the normal checks to simplify.

      The trace is bouncing between the traced intersection and the original intersection forever.

      Ama

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 11/05/2015 at 14:44, xxxxxxxx wrote:

        try to add ray "epsilon" , for floating point errors, this may be the problem.
        so if you trace from point (px,py,pz) to a direction (dx,dy,dz).
        make the point = (px + dx*epsilon, py + dy*epsilon, pz + dz*epsilon) , epsilon should be small "1e-3f for example"

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 11/05/2015 at 15:06, xxxxxxxx wrote:

          I thought that is why you pass sd->vd->lhit?  Isn't that supposed to be the intersection to ignore?

          Ama

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 11/05/2015 at 15:32, xxxxxxxx wrote:

            your code needs a little logic change, you don't modify sd->vd->ray , modify the point with epsilon, and the ray, and it should work!!

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 11/05/2015 at 16:21, xxxxxxxx wrote:

              the following?

              sd->vd->p + ( !sd->vd->ray->v * 0.001 )

              It does not seem necessary to alter the ray using this approach?

              Ama

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 11/05/2015 at 17:19, xxxxxxxx wrote:

                this code should work if the problem is numerical precision error.

                  
                if(sd->vd)  
                {  
                    SurfaceIntersection si = SurfaceIntersection();  
                    const float eps = 1e-3f;  
                    Vector64 point = sd->vd->p + sd->vd->ray->v * eps;  
                    Ray r;  
                    r.p = point;  
                    r.v = sd->vd->ray->v;  
                    while(sd->vd->TraceGeometry(r, 999999, sd->vd->lhit, &si) == true)  
                    {  
                        if(sd->vd->op == si.op)
                        {
                            distance += (si.p - point).GetLength();
                            point = si.p;
                            r.p = point;
                        }  
                    }
                }
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post