How to obtain the object deformed by the deformer
-
Hi,
deformer object can deform an object in two ways:
method A as a child of the deformed object,
method B at the same level as the deformed object.There is a problem. In a custom deformer plugin, I obtain the deformed object in the Message() function. Using the first method A, I can obtain the deformed object ''Cube. x'' through node. GetUp(). but method B, how can I access the deformed object (Cube, Cube. 1, Cube. 2)?
Thanks for any help!
-
Hey @chuanzhen,
Thank you for reaching out to us. Please excuse the delay. What you are asking for is effectively a dependency graph; which Cinema 4D simply does not offer. While there are methods such as
BaseList2D.GetMain()
orBaseObject.GetCacheParent
with which you can traverse the scene graph, there are no methods which would tell you which objects are influenced by a deformer.Possible Solutions
That you are trying to do this, access the deformed objects irregularly, hints at the fact that you either are doing something in a different manner than it should be done or that you are trying to do something that is not intended. With that being said:
Cache the Dependencies
When you implement a deformer, you get passed in the to be modified objects in ObjectData.ModifyObject one by one as
op
. You could 'simply' cache that data. The caveat is here that these object references can become stale, i.e., not alive in Cinema 4D terms. What you would have to do, is cache theMAXON_CREATOR_ID
or since 2025 simply thehash(node)
and then later grab the matching objects over the ID/hash.Implement the Deformer Logic
Not a god idea
Cheers,
Ferdinand -
@ferdinand Thank you for your detailed reply.
If there is no direct method, it is a feasible solution to re implement the defoemer logic. However, since it requires storing data separately for each object that needs to be deformed, limiting the deformable device to only act on the parent object is a limited but more efficient method. -
Hey @chuanzhen,
limiting the deformable device to only act on the parent object is a limited but more efficient method
The only way you could do that is by checking each deformed object
op
being passed intoModifyObjects
, to be the parent of the also passed ingen
(i.e., the deformer also simply accessible viaNodeData.Get
). Only for anop
which is the parent ofgen
would you then carry out the modification. But there are no flags with which you can limit what Cinema 4D considers a valid deform target and what not (at least I am not aware of any).I had a look at our code base, and what I wrote about implementing the deformer logic yourself is not true (I removed the section). If I would have to restate it now, I would say a deformer can act upon anything that is either its direct parent or one of its siblings or one of their descendants, e.g., the tree below, where
D
means a deformer,T
is a deformable andF
is non-deformable. This tree is for a deformerD
in Unlimited mode.F └─ T ├── T ├── D | └── T ├── T | └── T | └── T └── T
But I might have missed details, as the deform cache handling is not just a function you read in our code base and instead a bit scattered. So, reimplementing this is probably not such a good idea, as you would also have to take deform modes into account and things can then get complicated.
In general, I would circle back to the idea that what you are trying to do, get the deformed objects in
NodeData.Message
, hints at the fact that you might be approaching something from the wrong angle (because it is a very unusual thing to do). Maybe you can explain what you are trying to achieve on a higher level, so that we can see if there might be a better solution.Cheers,
Ferdinand -
@ferdinand Thanks for detailed explanation.
Let me introduce the goals that the custom deformer plugin wants to achieve. (As can be seen from the cube, cube. 1, cube. 2... in the image, each object has a weight tag.) The custom deformer plugin needs to preprocess and store some data before the ModifyObjects () function works. (By clicking a button) Access the weight tag of each object to be deformed in Message (), preprocess and store some data, and then use the preprocessed data to execute the ModifyObjects () function to correctly process the deformation calculation.
In C4D, it seems that the Surface deformer has achieved a similar function
(there are certain benefits to restricting the custom deformer plugin only to the parent level, as there is no need to spend effort on correctly linking the corresponding preprocessed data when the ModifyObjects () function works.But it did break the general logic operation of the deformer)
The only way you could do that is by checking each deformed object being passed into , to be the parent of the also passed in (i.e., the deformer also simply accessible via ). Only for an which is the parent of would you then carry out the modification.