On 05/05/2018 at 06:46, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R19
Platform: Windows ;
Language(s) : C++ ;
---------
I am having trouble to determine when an input object of my generator changed compared to the
last time that I handled and generated new geometry for it.
When the generator is first invoked, there's no cached state and thus it generates new geometry
for every input object. It saves the dirty count of the input object (DIRTYFLAGS_CACHE | DIRTYFLAGS_DATA)
in a hashmap. After the geometry was generated from the PolygonObject's found in the input object's
cache, it calls Touch() on the object.
However, Touch() increases the DIRTYFLAGS_CACHE dirty count (eg. for Array and Cloner objects,
not for Cube primitives for some reason).
Now the dirty count that I stored for the object is incorrect as it has been modified by Touch().
I need to call Touch() after I computed the geometry however because Touch() will free the cache
of the input object, making it inaccessible for computing the new geometry.
**
Do I need to compute the dirty count a second time after calling Touch() and store that dirty count
instead?**
Now assume the above works properly and I determine that I don't need to recompute geometry
from the input object. I simply call Touch() again in order to hide the input object in the viewport
and reuse the previously generated cache.
Does that mean that the input object's GetVirtualObjects() was called but the result is completely
ignored and deleted again by my Touch() call? Wouldn't that be super unnecessary?
Also, that Touch() call would again increase the dirty count.
Are there some resources that explain how to manage this properly?
On a side-note, I can't use the BaseObject DependenceList stuff because I want to treat all of the
inputs separately. So if one input object changed, I may still re-use the previously generated cache
of another input object.
For the sake of completeness, in case it is of any relevance, this is how I retrieve all the input
objects to my generator:
inline void CollectGenerators(BaseObject* obj, maxon::BaseArray<BaseObject*>& objects) {
if (obj->GetDeformCache() || obj->GetCache() || obj->GetType() == Opolygon) {
objects.Append(obj);
}
else {
for (auto&& child : Utils::IterChildren(obj)) {
if (!child->GetBit(BIT_CONTROLOBJECT)) {
CollectGenerators(child, objects);
}
}
}
}
// Then in GetVirtualObjects() :
maxon::BaseArray<BaseObject*> generators;
for (auto&& child : Utils::IterChildren(op)) {
Utils::CollectGenerators(child, generators);
}
for (auto&& generator : generators) {
// TODO: Determine if the cache of the generator has changed -> Recompute the geometry only in that case
maxon::BaseArray<PolygonObject*> geos;
// Here I collect all PolygonObjects using the method described in the
// BaseObject::GetCache() documentation (checking for BIT_CONTROLOBJECT).
// Build new geometry from PolygonObjects
generator->Touch();
}
Thanks in advance,
Niklas