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
    • Recent
    • Tags
    • Users
    • Login

    Getting the face being rendered

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 113 Views
    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 Offline
      Helper
      last edited by

      On 01/06/2014 at 15:50, xxxxxxxx wrote:

      I'm creating a shader and I need to know what face is being rendered (the index of the face).
      I already have the object that is being rendered (the shader works in junction with a tag and it is easy to get the object that is using the tag) and the object must ALWAYS be polygonal.
      So, inside my shader I already have the object and I'm sure it is polygonal.
      But I want to know how to be able to find what face is being rendered.
      I tried using something like this:

      def Output(self, sh, cd) :
           op=None
           the_tag=sh[VMAP_OBJECT]
           if the_tag is not None:
                op=the_tag.GetObject()
                op_type=op.GetType()
                if op_type != c4d.Opolygon: return c4d.Vector(0) # return black if it isn't a polygonal object

      if cd.vd: #if shader is computated in 3d space
                     volumedata=cd.vd
                     ray=volumedata.ray

      collision=c4d.utils.GeRayCollider()
                     collision.Init(op,False)

      hit=collision.Intersect(ray.p,ray.v,volumedata.dist+1.0,False)

      if hit is True:
                          print collision.GetIntersection(0)["face_id"]

      return c4d.Vector(1.0,0,.5)
                else: #if shader is computated in 2d space
                     return c4d.Vector(0.0,1.0,0.0)

      But it is not detecting any intersection.
      Am I doing it wrong?

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

        On 01/06/2014 at 16:22, xxxxxxxx wrote:

        Ok, found it.
        Instead of simply using the ray.p value I defined:

        op_matrix=op.GetMg()
        start=~op_matrix*ray.p

        And used the start variable in the Intersect instead of ray.p and it worked.
        Also, I used GetNearestIntersection instead of GetIntersection.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post