There is a way to have an invisible material in the document... The "Active Object Dialog" example plugin from cinema4dsdk reveals that there's an invisible Sky Material in the document when a Physical Sky Object is created Can I do that with a standard material, too?
sorry i read too fast, you want to color your objects so you can use OBJECT_USECACHECOLOR when you register your generator. So you will be able to define a color for each object.
Unfortunately, that's not enough. I need arbitrary colors on the object's surface. Vertex colors would've been ideal, but they don't appear if the Vertex Color Tag is inside my generator's cache. Or would OBJECT_USECACHECOLOR allow me to have the vertex colors appear in the viewport?
Anyway, doesn't really make a difference. Vertex colors are only drawn without shading. Therefore, I would very much prefer the SkyObject-like solution with the hidden material.
I just realise, it should be possible to hide material and texture tag with GeListNode::ChangeNBit(OHIDE). Maybe that already solves my problem Will try tomorrow.
we will answer this more thoroughly tomorrow, but the trick when providing a vertex color map in a cache, is to select it, as this is the condition for Cinema to draw it. For your "moved goal posts" of having a shader/material, this can become tricky, because as providing materials is not an intended functionality for generator caches. But you probably know that.
The common workaround is then to assign the material to the generator and not the cache and hide the material as you already said yourself. But when you are going to rely on vertex colors, you are going to have a problem, I think. The problem is that you cannot assign the vertex color tag to the generator, as this won't work. Vertex color tags seem to be unable to reach into caches, I just tried. So, you will have to keep the vertex color tag on the cache. You can then still create just your material with a vertex map shader in it to do all your fancy shading and assign it to the generator (and hide it). The problem is: The vertex color shader would then have to reach/link into the cache to get the tag from there. Which I think should work in principal, have not tried myself though, but is obviously the definition of "dicey".
PS: This is a "private" answer of mine, just because I thought it is an interesting problem ^^
# Pretty straight forward per vertex definition of vertex colors.
count = node.GetPointCount()
tag = c4d.VertexColorTag(count)
data = tag.GetDataAddressW()
for pid in range(count):
color = c4d.Vector4d(random.uniform(0., 1.),
random.uniform(0., 1.), 1.)
c4d.VertexColorTag.SetPoint(data, None, None, pid, color)
# Add the tag and the magic bit, quite literately, select it.
# Get our cache source, cause I was to lazy to come up with some geom. :)
source = op[c4d.ID_USERDATA, 1]
if not isinstance(source, c4d.PolygonObject):
# Clone the cache source and create a vertex color map for it.
cache = source.GetClone(0)
Thank you, Ferdinand!
Since the Sky Object is using the trick with the hidden material, I think it is an adequate method of solving this. The material just needs to be created when the object is created, kept track of and updated with changed parameters, and then removed when the object is removed. I'll see to that and will be back if more questions arise.
okay And in retrospective I also see me misunderstanding something here in my answer on the weekend. I thought vertex colors were a requirement, but they were actually just one way you did consider for providing color information, right? If this is the case, then writing a custom shader and hiding the material it is attached to, should work fine.
thanks for your answer! What would the standard way of maintaining such a hidden material look like?
Something like this, I guess:
But when is the right moment for creating and freeing the material? Doing it in ObjectData::Init() does not work, because a) that function is called quite often, and b) when Init() is called on object creation, the node pointer is NULL.
I also tried MSG_DOCUMENTINFO with type MSG_DOCUMENTINFO_TYPE_OBJECT_INSERT, but it's not called when the object is added to the document.
How does the Sky Object solve this?
Well, the sky object Have a special command. The object itself and the material are hidden. The command does create the skyobject and insert it in the document. It also creates the Material. The Material Object does in its Init function set the Bit Ohide. and the SkyObject does Alloc a BaseLink in its InitFunction.
The command than retrieve the ObjectData using GetNodeData and set the baselink to the material.
The material is never deleted.
The hierarchy and the material tag should be created inside GetVirtualObject.
I would try to make the material visible if you make the object Editable. You can check the message MSG_EDITABLE_END.
You may also need MSG_MULTI_MARKMATERIALS MSG_DESCRIPTION_INITUNDO if you want to add an undo to the material stack if you change it after your object have been update.
Hope you have enough to solve your problem
Thank you, Manuel! I'll try that!
without further questions or postings, we will consider this topic as solved by Wednesday and flag it accordingly.
Thank you for your understanding,