particle emitter with python generator[solved]
-
On 05/03/2017 at 22:22, xxxxxxxx wrote:
Hi,guys.
I'm a newer in python.I want to create a particle emitter with python generator,but it can't be emitted correctly and looks very strange.I don't know what I'm doing wrong? Would you mind help me? Thank you!Here is my code below:
import c4d import random def rnd(mutil) : return random.random()*mutil def main() : tp = doc.GetParticleSystem() All = tp.GetRootGroup() random.seed(12345) num = doc.GetTime().GetFrame(doc.GetFps()) for i in xrange(0,num) : p = tp.AllocParticle() tp.SetGroup(p,All) tp.SetLife(p,c4d.BaseTime(rnd(20),doc.GetFps())) tp.SetPosition(p,c4d.Vector(rnd(100),0,rnd(100))+op.GetMg().off) tp.SetVelocity(p,c4d.Vector(rnd(200),rnd(1000),rnd(100))) return c4d.BaseObject(c4d.Onull)
-
On 06/03/2017 at 09:54, xxxxxxxx wrote:
Hi WeiChing,
welcome to the Plugin Café forums.
I have moved this thread to the Python sub-forum, which is probably a bit better suited.
I'm not hundred percent sure, the Python Generator is a good place for such particle interaction. A Python Tag feels a bit more natural to me.
In general it's a bit hard to help you, without any description of what you want to achieve. But we definitely do not mind to help you. Actually that's what we are here for.
We have two examples demonstrating TP in a Python Tag: SA4Python and boid_simulation
You can find the scenes and scripts in our Git Hub repository under scenes. So maybe it's worth taking a look. -
On 07/03/2017 at 04:42, xxxxxxxx wrote:
Hi,Andreas.
Thank you very much for your reply!I just want to create a particle emitter in the python generator,Only I click the "Force Update"button of the python generator,the particles can be emitted.I don't know why? after I saw that you give me two examples, I understand that a particle emitter can be created with a python tag correctly.I guess that python generator can not be used to create a particle emitter,is it right?(sorry for my poor English!)Best wishes!
-
On 08/03/2017 at 05:39, xxxxxxxx wrote:
Hi,
I won't say, a Python Generator can not be used to create a particle emitter. At least it's not forbidden, but it's probably not the easiest task. The thing is, the main() function of the Python Generator is called in GetVirtualObjects() of a ObjectData Generator plugin. This function is designed to create/return polygonal data and it is usually called, when the scene gets evaluated/executed. But, and here is the point, it is not called under all circumstances (for example if the scene gets evaluated with cache building disabled) and therefore might not be the best place for a particle generator.
The Python code in a Python Tag on the other hand is called in the Execute() function of a TagData plugin. -
On 08/03/2017 at 17:41, xxxxxxxx wrote:
Hi Andreas,
Thanks!you have cleared a lot of confusion for me.
Best Wishes!