SOLVED Making a PolygonObject-like object plugin

Hi,
I am trying to make a custom item that works in the same way as a polygon object, but with more options. These options would be simple things, like showing certain parameters in the UI that depend on other parameters and the points and polygons of the object itself, but the problem is creating the object.

I found out that the OBJECT_POLYGONOBJECT tag in RegisterObjectData makes C4D create a PolygonObject, instead of a BaseObject, so one could apply all the PolygonObject methods (like GetAllPolygons or GetAllPoints) to the custom object without getting an error, but with no result. I started with ResizeObject, but the size wouldn't change. SetPoint returns index out of range since the size is 0, and GetAllPoints/Polygons always returns an empty list. Tried to use these methods in ObjectData.Init (using node as the object) and ObjectData.GetVirtualObjects (using op), but the object just refuses to change size without returning any error. Also tried creating a polygon object in GetVirtualObjects, manually giving it points and polygons, and it displays if OBJECT_GENERATOR is set, but when entering point/edge/polygon mode it disappears from the view and can't be edited.

I couldn't find any Python examples for this, and the only thing I found for C++ (which I don't know too much about), was the Lattice Plane Modifier plugin (using OBJECT_POINTOBJECT, not polygon), where it seems to ResizeObject and access the points with GetPointW and replace them with no problem. Also browsed the SDK documentation for ObjectData and NodeData and didn't see anything useful, except maybe ObjectData.Draw, but I don't know how it should be used.

My goal is to make multiple object types that can be edited by the user with the same tools as a polygon object, andthen giving them different icons and displaying different parameters in the UI depending on the object type. Is there a way to do this?

Thanks,
Oscar

Hello @johnnyasdf,

thank you for reaching out to us. First of all I would point out that your stated project goals are not clear to me, as you give two which are not the same. You say (emphasis by me):

I am trying to make a custom [...] polygon object, but with more options. These options would be simple things, like showing certain parameters in the UI [...]

My goal is to make multiple object types that can be edited by the user with the same tools as a polygon object, [...]

These two statements are not the same.

The problem here is also that you are still very early in your search process, and implicitly ask for how to go about these goals of yours. This is out of scope of support, we cannot design applications for you, as stated in our Forum Guidelines. Your question also lacks the code you have already written or excerpts from it, which makes it also hard to give here answers.

I will however try to provide some guidance, but please understand that I cannot do this the whole way. I will also answer in bullet points, as there is so much ground to cover.

  1. Implementing a plugin which has the flags OBJECT_POLYGONOBJECT or OBJECT_POINTOBJECT does not guarantee that 'that [its instances] can be edited [...] with the same tools' as this only means that your plugin implements these interfaces, not that the plugin is that interface. Internal or external tools might test the BaseObject type of passed in operands before even attempting any operations and then simply reject your plugin instances.
  2. It is not possible, at least not without A LOT of work, to implement polygonal geometry that is driven by Attribute Manger parameters and can maintain vertex-by-vertex manipulations of users. Either something is a polygon object generator or it is a static polygon object which can be edited.
  3. When you implement a OBJECT_POLYGONOBJECT, you must reimplement all its vertex/edge/polygon interactions (drawing selected and unselected vertices, let the user select them, etc.)
  4. OBJECT_POLYGONOBJECT is sort of uncharted territory. While we have internally multiple plugins which make use of OBJECT_POINTOBJECT, there are none for the other flag, so you might run into problems here since this flag has never been really used.
Most Important Points
  1. The Python API is not right API when you want to implement an editable point object with all bells and whistles, you should use the C++ API.
  2. The task you are lining here out is enormous, and this is one of these "if you have to ask, its not the right thing for you"-cases. Our public C++ API is quite powerful and an expert could implement what you line out here, but that would be then a very substantial product with months of work behind it, as you effectively ask for reimplementing polygonal geometry.
  3. Pick your battles: If you just want to some information being displayed for objects, be it your own plugins, other plugins, or fundamental types as Opolygon, I would recommend implementing a tag which does that. If you want to, you could hide that tag from the users view, and also write a plugin which automatically distributes that tag in a scene (this last point would work best in C++ though). This would be a very achievable goal and much simpler than reimplementing polygonal geometry.
    a. On an even broader scope I could not even recommend doing that, as this might interfere with the useability of Cinema 4D. The problem is here that you want to change core functionalities of Cinema 4D (what objects do that are not your own) and this is a bad idea.

Cheers,
Ferdinand

PS: It is not that haven't read your accessing points and polygons questions, but without having sorted out these design issues first, they are irrelevant. In short: Without code they are not answerable, but I would assume they are caused by the Python bindings in some shape or form.

First of all, thanks for your support.

It is not possible, at least not without A LOT of work, to implement polygonal geometry that is driven by Attribute Manger parameters and can maintain vertex-by-vertex manipulations of users.
You must reimplement all its vertex/edge/polygon interactions
OBJECT_POLYGONOBJECT is sort of uncharted territory.

That answers my question. My approach was trying if I could use the already implemented geometry interactions and add from that point. Since I found no example for OBJECT_POLYGONOBJECT, thought that could be it, but seems not.

If you just want to some information being displayed for objects, I would recommend implementing a tag which does that. If you want to, you could hide that tag from the users view, and also write a plugin which automatically distributes that tag in a scene

My plan B was along these lines, with a dialog to show the info.

Thanks,
Oscar