Hey @Fabio-B,
⚠ Please note that we cannot provide support for AI generated code. See Support Procedures: Scope of Support for details.
When you want the clones to move, or in other words to be animated over time, you will need a noise and cannot use hashes or random values, as they are not interpolated, i.e., continous.
"""Realizes an effector that attracts MoGraph particles spherically around its origin.
Add the example to a Matrix object to understand its effect. In Full Control mode we can realize
a true attraction force as we have full control over the particle values. Compare this example to
Parameter Control mode to understand the difference.
"""
import c4d
import mxutils
op: c4d.BaseObject # The Python Effector object containing this code.
gen: c4d.BaseObject # The MoGraph Generator executing `op`.
doc: c4d.documents.BaseDocument # The document `op` and `gen`are contained in.
def main() -> bool:
"""Called by Cinema 4D to evaluate the effector.
"""
# Get the particle data for the effector #op. Get out when either the data cannot be retrieved.
data: c4d.modules.mograph.MoData = c4d.modules.mograph.GeGetMoData(op)
if data is None:
return 1.0
# Get the matrices of the particles. This is the array we will modify.
matrices: list[c4d.Matrix] = data.GetArray(c4d.MODATA_MATRIX)
# For each particle write a new persistent random height value, hashed over the index of the
# particle. This will cause the height each time to be the same, as long as the index of the
# particle does not change. One could also hash the position of the original particle to get a
# height value that is not dependent on the index of the particle (e.g., when the user changes
# the order of the particles in the Matrix object).
for i in range(data.GetCount()):
pos: c4d.Vector = matrices[i].off
y: float = c4d.utils.noise.Noise(matrices[i].off, doc.GetTime().Get()) * 25.0
matrices[i].off = c4d.Vector(pos.x, y, pos.z)
# Hash a height value over the position of the particle.
# y: float = mxutils.g_random.HashVectorToNumber(matrices[i].off) * 25.0
# Write the new data back.
data.SetArray(c4d.MODATA_MATRIX, matrices, op[c4d.FIELDS].HasContent())
return True
Cheers,
Ferdinand