On 24/04/2016 at 05:50, xxxxxxxx wrote:
Today I just made my first Python plugin!:slightly_smiling_face: The plugin is a simple cloner based on the 'Objectdata' class. Its just cloning its children to the points of an object passed through PY_CLONER_LINK, a link box in the gui. Its main method, GetVirtualObjects, is displayed below.
Now it works as expected, but when the link-object changes every frame (by a formula-deformer, for example), the frame rate of c4d steadily drops and in the activity monitor I can see memory use increasing. In fact, I made a little calculation and it seems that:
memory increase per second = len(pts) x (frame_rate) x (memory_per_cloned_object)
i.e. that new objects are being created every frame but none of the old objects are destructed. This can rapidly grow in the GB range.
What is the cause of this memory increase, and can it be stopped? Or should I make another plugin like a particle modifier or something?
To summarize: I want a plugin that updates the position of particles at every frame. The positions are calculated by another plugin, or an extension on this one. The number of particles is constant at runtime, but may change from session to session (for example at frame 0).
I hope someone can help me out,
CINEMA 4D 17 Prime
Mac OS X 10.10.5
def GetVirtualObjects(self, op, hierarchyhelp) :
bco = op.GetDataInstance()
obj = bco.GetLink(c4d.PY_CLONER_LINK, doc=None, isinstanceof=c4d.Obase)
instances = bco.GetBool(c4d.PY_INSTANCE_BOOL)
clones = op.GetChildren()
null = c4d.BaseObject(c4d.Onull)
Nc = len(clones)
if (not obj) or (not clones) : return null
if obj.GetCache() :
obj = obj.GetCache()
elif obj.GetDeformCache() :
obj = obj.GetDeformCache()
elif obj.CheckType(c4d.Obase) :
obj = self.MakeEditable(obj)
pts = obj.GetAllPoints()
for i,p in enumerate(pts) :
cln = c4d.BaseObject(c4d.Oinstance)
bc = cln.GetDataInstance()
k = i%Nc
bc.SetBool(c4d.INSTANCEOBJECT_RENDERINSTANCE, instances )