27/09/2018
Connect two X-Particles xpEmitters with splines with this Python Generator. You can also tweak amount of connections and spline interpolations.
You can also connect two xpEmitters using xpElektrix by setting Mode to ‘Particle to Particle’.
import c4d, xparticles from c4d import utils as u def main(): connect = c4d.BaseObject(1011010) # Initializ connect object connect[c4d.CONNECTOBJECT_WELD] = False # Untick weld checkbox emittera = xparticles.ToEmitter(op[c4d.ID_USERDATA,1]) # Emitter A link emitterb = xparticles.ToEmitter(op[c4d.ID_USERDATA,4]) # Emitter B link connections = op[c4d.ID_USERDATA,2] # Amount of connections interp = op[c4d.ID_USERDATA,3] # Iterpolation for spline offset = op[c4d.ID_USERDATA,8] # Offset connections splines = [] # Initialize list for splines pca = emittera.GetParticleCount() # Get Emitter A's particle count pcb = emitterb.GetParticleCount() # Get Emitter B's particle count if pca > pcb: # If Emitter A's particle count is larger than Emitter B's op[c4d.ID_USERDATA,6] = str(pcb) # Maximum amount of connections tpc = pcb # Particle count to use else: # Otherwise op[c4d.ID_USERDATA,6] = str(pca) # Maximum amount of connections tpc = pca # Particle count to use try: # Try to execute following script for i in range(connections): # Loop through connections count points = [] # Initialize list for points if op[c4d.ID_USERDATA,10] == True: # If modulo checkbox is ticked offset = offset%tpc # Offset with modulo pa = emittera.GetParticle(i+offset) # Get Emitter A's particle index pap = pa.GetPosition() # Get Emitter A's particle's position pb = emitterb.GetParticle(i+offset) # Get Emitter B's particle index pbp = pb.GetPosition() # Get Emitter B's particle's position for k in range(interp): # Loop through interpolation count r = u.RangeMap(k, 0, interp, 0, 1, True) # Range map pp = u.MixVec(pap, pbp, r) # Get point's final position points.append(pp) # Add point to points list points.append(pbp) # Add last point spline = c4d.SplineObject(interp+1, c4d.SPLINETYPE_LINEAR) # Initialize spline object splines.append(spline) # Add spline to splines list splines[i].SetName("Spline"+str(i)) # Set name for spline object splines[i].SetAllPoints(points) # Set points to spline splines[i].InsertUnder(connect) # Insert spline under connect object except: # If something went wrong pass # Do nothing return connect # Return connect object that contains splines
Updated 16/10/2018
> Added offset option
ar_generator_connect_xpemitters.c4d v1.0.0 (2023.1.0)