On 16/03/2017 at 09:03, xxxxxxxx wrote:
sorry for the simple question.I want to know how to get the cache of a cloner or sweep object.For example,there is a cube under the cloner object,how to get all points of the cubes?I looked for the SDK document,found a function called "GetCache()",I tried ,but not work.and I want to know how GetCache() to operate?although there is a example in the SDK,I am still confused about it.Would you help me?Any help would be very appreciated!
On 17/03/2017 at 10:28, xxxxxxxx wrote:
Hi Ching, thanks for writing us.
With reference to your question I warmly suggest you to spend some time looking into the BaseObject::GetCache() and BaseObject::GetDeformCache() in the Python API documentation where useful code snippets are presented showing how to traverse the scene and operate accordingly with the caches. Beside that I also warmly suggest to spend some time through the page of the BaseObject Manual and, last but not least, It could be also very helpful to give a look to the Active Object Dialog example part of the cinema4dsdk example set. Although a bit long, it could definitively shed lights on the internal structure of the cache in Cinema and how to handle it.
For your comfort please find a one-level digging-down cloner example showing how to retrieve the point data information for the objects pinned under a MoGraph Cloner object. To test the example simply create a scene with one cloner and one object pinned under it and run the script by selecting the cloner object. Please note that the code is not recursive so situations where cloners are nested are not handled, but extending to such a scenario won't be that hard.
def main() :
obj = doc.GetActiveObject()
# check object selection
if obj is None:
print("No object selected. Select the MoGraph Cloner.")
# get the object cache and
cache = obj.GetCache()
# check the cache to be valid
if cache is None:
# get the first child
cacheChild = cache.GetDown()
# loop over the children
while cacheChild is not None:
# get the cache global transformation matrix
cacheMg = cacheChild.GetMg()
# verify that the cache is an instance of PolygonObject
if cacheChild.GetCache().IsInstanceOf(c4d.Opolygon) :
# access the cache of the child
polyCache = cacheChild.GetCache()
# access the points stored in the child's cache
points = polyCache.GetAllPoints()
# loop over the points and transform them for the child global matrix
for point in points:
print cacheMg * point
# move to the next child of the cloner
cacheChild = cacheChild.GetNext()
On 17/03/2017 at 23:59, xxxxxxxx wrote:
Thank you for your code.It is very useful to me.