Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Register
    • Register
    • Login

    How to get the number of points in an object?

    Cinema 4D SDK
    c++
    2
    3
    564
    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.
    • R
      rui_mac
      last edited by

      I have this code to check if an object op is a polygonal object and if it is a plane object.

      PointObject* polyop;
      Bool all_ok = false;
      		
      Bool isPoly = (op->GetType() == Opolygon);
      if (isPoly)
      	{
      		polyop = static_cast<PointObject*>(op);
      		all_ok = true;
      	}
      			
      Bool isPlane = op->GetType() == Oplane;
      if (isPlane)
      	{
      		polyop = ToPoint(op);
      		all_ok = true;
      	}
      		
      if (all_ok == false)
      	return Vector(0);
      		
      Int32 pcnt = polyop->GetPointCount();
      GePrint(maxon::ToString(pcnt, nullptr, false));
      		
      if (pcnt == 4)
      	return Vector(1);
      ...
      

      If it is a polygonal object, I can easily check the number of points. But if it is a plane, I always get a count of 0 (zero) points, even if I convert the plane into a polygonal object, with ToPoly.
      How can I get a polygonal version of the object?

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @rui_mac
        last edited by

        Hi @rui_mac ,

        you can distinguish between different types of the BaseObject* op using GetType() function, this part is correct in your code.

        If op->GetType() == Opolygon gives you true, it means that your op is actually a polygon object, so you can easily cast it to PolygonObject* using one of the following approaches:

        1. static_cast<PolygonObject*>(op)
        2. ToPoly(op), which is just an alias for the 1.

        Since PolygonObject is inherited from the PointObject, the same stands for PointObject class too:

        1. static_cast<PointObject*>(op)
        2. ToPoint(op), just an alias for the 1.

        In case your op is effectively Oplane (or any other object that's not a raw polygon), you're not able to easily access its points, because sometimes there's an entire hierarchy hidden behind the op. In this case you'd need to bake your object to a single polygon object. There're actually two ways you can follow from this point:

        1. The naive and very expensive one. You can use the SendModelingCommand to execute "Current State to Object" command on your object. This is slow and inefficient, but is a low hanging fruit, since these couple of lines would cover all the edge cases.
        2. Access objects geometry cache yourself. By this I mean using GetCache() and GetDeformCache() functions. This approach requires proper coding, since you can have interesting structures there and easily hit some edge cases. However, it will be way faster and more efficient, comparing to 1., especially if you expect it to work with simple objects like Oplane.

        Both approaches have been already extensively discussed on the forum, so you shouldn't have problems searching for example code snippet. Additionally, we have great examples (although using Python API, which in this case will be very similar to C++ API) for both scenarios:
        SendModelingCommand: Current State to Object
        Geometry Caches

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • R
          rui_mac
          last edited by

          Thank you very much, Ilia.
          I will look into both approaches.
          I only have to check it at the begining of the calculations of the shader, so the best way should be to make in the InitRender method, right? That way, all the possibly "slow" stuff only gets calculated once.

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