Hi, I am making a DEMO for my research work of crowd simulation. The people may walk and stop during the animation. The position and drection(Velocity) of the crowd have been recorded in a text file. I have written a Python script successfully read the data file at each keyframe. Now, I use TP partilce to animate the crowd. And, I subsitute the particle with a Man model through XPresso Pshape tags. Shown as followed.
When the position is not changed the model's motion should stop(stay at present keyframe) untill he moved again. The motion of the model is pre-rendered like a re-cycle movie.
The keyframe of the Model as follow:
What should I do to hold on the present keyframe? Sorry ablout my poor question description!
My Python scripts as followed:
# Boids for Py4D by smart-page.net
# particles' params
boids_number = 1000
currentframe = None
# used for read user data frame by frame
frame_step = boids_number+1
frame_total = 0
currentframe = doc.GetTime().GetFrame(doc.GetFps())
# particles born at 0 frame
if currentframe == 0:
# life time for particles
lt = c4d.BaseTime(1000)
# user data for paritlces
filename = op[c4d.ID_USERDATA, 1]
# open the user file. First, read a frame of data from the user file. Then, read lines one bye one to feed the particles.
with open(filename, 'r') as fn:
# read all lines of the user data
lines = fn.readlines()
# compute how many frames of data in the file
frame_total = int(len(lines) / frame_step)
frame = 1
#read a frame of data according to the scene keyframe
for frame in range(frame_total):
if frame == currentframe:
t_lines = lines[frame * frame_step:frame * frame_step + frame_step - 1]
#pase lines of the readed data
for line in t_lines:
if line == t_lines: # filter the first line of each frame in the text file, because is just flag words
#split position(x,y,z) and direction (dx,dy,dz)
x, y, z, dx, dy, dz = line.split()
pos = c4d.Vector(float(x), float(y), float(z) )
vol = c4d.Vector(float(dx), float(dy), float(dz))
# some codes wanted here
# the motion of the man should stop.
# should I edit the keyframe of the walking Man model?
# when temp==0, then the walking Man stay at present keyframe but not go ahead along with the scene keyframe.
# align to velocity direction
vel = vol.GetNormalized()
side = c4d.Vector(c4d.Vector(0, 1, 0).Cross(vel)).GetNormalized()
up = vel.Cross(side)
m = c4d.Matrix(c4d.Vector(0), side, up, vel)
# set position
# set life time for particle i
My user data format as followed.