PYTHON - INPUT DELAI
-
Hello guys,
I started learning Python few days ago and I definitly need help from the pyhton dev community !I wish to insert a "delay time" that can be inputed by the user for each loop I created. How can I do that ?
Here is my code :
import c4d import math import time import threading from c4d.modules import mograph as mo #Welcome to the world of Python Fields def Sample(op, inputs, outputs, info): """Calculate the output values for the specified set of input points. Allocations should be avoided in Sample to maximize performance. Return false on error to cancel sampling. NOTE: Sample function is mandatory, PythonField cannot function without it. Keyword arguments: BaseObject -- the python field. FieldInput -- the points to sample. FieldOutput -- the sampling output arrays (pre-allocated). FieldInfo -- the sampling informations. """ NbObjFamily = 5 flight_time = 5 delay = 5*(doc.GetTime().Get()) # Wave "0" for i in range(0, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = value / flight_time outputs.SetValue(i, offsetValue) # Wave "1" for i in range(1, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = (value + 0.0) / flight_time outputs.SetValue(i, offsetValue) # Wave "2" for i in range(2, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = (value + 0.0) / flight_time outputs.SetValue(i, offsetValue) # Wave "3" for i in range(3, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = (value + 0.0) / flight_time outputs.SetValue(i, offsetValue) # Wave "4" for i in range(4, inputs._blockCount, NbObjFamily): value = (doc.GetTime().Get()) offsetValue = (value + 0.0) / flight_time outputs.SetValue(i, offsetValue) # Return false to cancel further sampling. return True
Any Idea ?
Thank you
-
... I forget one important information : This is a Python Force Field
-
welcome to the forum and Cinema 4D development community! Learning a programing language and an Application Programming Interface (API), e.g. Cinema's public API, can be a bit daunting, but you will see it is not so bad in the end. There are usually some misunderstanding, it is quite common
In your case it is not quite clear to us what you mean "delay time". The
Sample
function is meant to read or modify an array of Mograph particles. You have no control over the timet
at which Cinema polls this function, in fact it can be polled multiple times for the same timet
. From our understanding you are trying to do something like Cinema's own Delay Effector, which is not easy to do in a Python Effector/Field, as it would require you to build some kind of cache about the past. In your current code you are just overwriting the particle array multiple times (you set the particles [4, n] five times).But this is mostly speculation form our side, so we would like to ask you to explain in more detail what you are trying do. Please explain what you mean by delay time and what effect on a broader scale you are trying to achieve.
edit: Please also make sure to use the forum tagging feature in your next postings. I have done it partially for you here, you will need to add your version of Cinema and your operating system. If you want to make clear that your posting is a question, you can also use the ask-as-question feature.
Cheers and happy coding,
Ferdinand -
Hello Zipit,
Thank you a lot for posting advices and answering quit. Your explanations are very precise and clear. Coding might be difficult but offers incredible possibilities. [link text]PYTHON_FIELD_SCRIPT V 0.1.c4dPlease, can you tell me how can I add tags to my post ?
About my project, I think you have a good idea of what I want to do but I'll try to be as precise as possible this time. I attached the scene, it should be easier to understand what I want to do then.
I have 5 "Families" (groups) of clones, determined by the Sphere Fields called "FAMILY_X". Needed for my project evolution.
-
I want them to go from their starting position and morph to FIG_01 which is a grid during a determined time (set into User Data (ex "Transition_time (sec)") of the Python Force Field)
-
For ich family, I want to start the mouvement at a different time (that can be set in User Data (ex "Start_Time // Family_0") of the Python Force Field).
If it is possible with Python Force Field, what code should work to do that ?
If not, what is the best solution to do that ? Python Tag ? Python Script ?
Thank you !
-
-
ohh... forgot that !
I'm Working on
- MAC OS 10.14.6
- Cinema 4D R21
-
Good morning Hugo,
I think that is possible with a Python Effector, unless I do completely misunderstand you. If I understand you correctly, you want to do the following:
- Map the particles in your
Boules
cloner from to the particle positions in yourM_FIG_01
cloner. - You want to be able to animate the whole process, i.e. (linearly) interpolate from a starting position of a particle in
Boules
to a end position inM_FIG_01
- You also want to be able to offset the animation for each pentagon point group in
Boules
, so that your particles "depart in waves".
One and two are relatively easy to do, you only have to make sure that both particle systems/cloners have the same amount of particles (which you did ;)). Number three is a bit more tricky when you have more complex inputs for
Boules
, but in your case you can simply group the particles inBoules
into groups of five, to get the particles for each pentagon. You then have to get the particle system of theM_FIG_01
cloner and simply interpolate between the positions of the particles. But to do that in a meaningful way, you will have to cache the starting positions of yourBoule
system.I cannot write the script for you, but I can guide you through the process. I would recommend first removing all clutter from your scene (unnecessary objects), so that you only have the two cloner/matrices and one Python Effector. Then write just a piece of code for a Python Effector that loops through all particles the effector is applied to (Boules) and print out their positions. Also try to group them into their pentagon groups. Come back when you are done or encounter problems
edit: I did the tagging for you, but you can find the tags in the lower left corner of the posting editor.
Cheers,
Ferdinand - Map the particles in your
-
Hi,
without further feedback, we will consider this thread as solved by Monday and flag it accordingly.
Cheers,
Ferdinand