Tags Under Cloners
-
Hello,
I'm working on a tag plugin that is using positional data of an object to drive parameters. This is simple and straightforward so it is working properly using the code below inside of the Execute function to drive the Radius value of a sphere object.
EXECUTIONRESULT TagParamRun::Execute(BaseTag* tag, BaseDocument* doc, BaseObject* op, BaseThread* bt, Int32 priority, EXECUTIONFLAGS flags) { if (tag->GetObject()) { BaseObject* parentObj = tag->GetObject(); if (parentObj->GetType() == Osphere) { ApplicationOutput("Parent object " + parentObj->GetName()); Matrix sphereMat = parentObj->GetMg(); Vector spherePos = sphereMat.off; Vector centerPos = Vector(0); Float distance = sqrt(pow(spherePos.x - centerPos.x, 2) + pow(spherePos.y - centerPos.y, 2) + pow(spherePos.z - centerPos.z, 2)); GeData setData; distance = distance / 2; if (distance > 50) distance = 50; setData.SetFloat(100 - distance); parentObj->SetParameter(ConstDescID(DescLevel(PRIM_SPHERE_RAD)), setData, DESCFLAGS_SET::NONE); } } return EXECUTIONRESULT::OK; }
My issue comes in when I have the object with my tag under a Cloner. As I drag the tag's object around the scene all of the cloned spheres are changing their radius based on that single object instead of their cloned positions. Shown below.
If I make the cloner edititable then the setup is working as I would expect.
Is there a way to make it so that my tag is running after the Cloner has run? In this case 9 separate spheres with attached tags running on their own positions.
Any help would be greatly appreciated.
John Thomas
-
Hey @JohnThomas,
Thank you for reaching out to us. You tripped here over something many users before you have tripped over, but this is working as intended
Create a Cube generator object and give it a Look at Camera tag. The object will now orient its z-axis towards the scene camera. Now parent it to something that uses it an input for its own cache generation, e.g., a Cloner object. You will see that the clones do no orient itself towards the camera.
And this is intentional, expressions, i.e., tags, are not executed in caches as they would not be caches otherwise. The purpose of caches is to provide a ready-to-use part of scene geometry that does not have to be constantly reevaluated. Cinema 4D more or less just ignores caches when executing the expression pass on a document. But when you convert a cache back into a part of the visible scene graph with CSTO, things like expressions are being evaluated again.
You cannot circumvent this. When you want to implement a 'modifier' that can influence the cache of generators you must implement a MoGraph field or effector. But the generator which shall be influenced has of course to support the respective modifier. See Plugin Types for details.
Cheers,
Ferdinandedit: Technically you can write a tag that reaches into the cache of an object and modifies it. But that is not supported and can crash Cinema 4D. As long as you do not allocate or deallocate memory in the cache (e.g., add or remove nodes or points), you are somewhat safe. Use at your own risk, but Cinema 4D does that itself in some cases because developers love doing hacky things
-