if df['time'].max() > self.longest_time:
self.longest_time = df['time'].max()
for name,edf in df.groupby('objectnum'):
print(name)
n = f"Object {name}"
edf = edf.sort_values('time')
initialx = edf['x'].iat[0]
initialy = edf['y'].iat[1]
initialz = edf['z'].iat[2]
bpy.ops.mesh.primitive_cube_add(location=(initialx,initialy,initialz))
orig_cube =bpy.context.view_layer.objects.active;
orig_cube.name = n
orig_cube.scale = (0,0,0)
for i,time in enumerate(edf['time']):
orig_cube.location[0] = edf['x'].iat[i]
orig_cube.location[1] = edf['y'].iat[i]
orig_cube.location[2] = edf['z'].iat[i]
if i == edf.shape[0]-1 or i == 0:
orig_cube.scale[0] = 0
orig_cube.scale[1] = 0
orig_cube.scale[2] = 0
else:
orig_cube.scale[0] = 100000
orig_cube.scale[1] = 100000
orig_cube.scale[2] = 100000
orig_cube.keyframe_insert(data_path="location", frame=time)
orig_cube.keyframe_insert(data_path='scale',frame=time)
How can I just do this with something like this? I'm trying to eliminate the for loop that loops over all the data.
if ['time'].max() > self.longest_time:
self.longest_time = df['time'].max()
for name,edf in df.groupby('onjectnum'):
n = f"object {name}"
edf = edf.sort_values('time')
initialx = edf['x'].iat[0]
initialy = edf['y'].iat[1]
initialz = edf['z'].iat[2]
bpy.ops.mesh.primitive_cube_add(location=(initialx,initialy,initialz))
orig_cube =bpy.context.view_layer.objects.active;
orig_cube.name = n
orig_cube.scale = (0,0,0)
#HERE IS WHERE I NEED THE MAGIC
#Creating a Nx3 array of locations [x,y,z]
locations = np.array([edf['x'],edf['y'],edf['z']]).T
orig_cube.ADD_KEYFRAMES(data_path='location',loc=locations,fame=edf['time'])
#Creating a Nx3 array of scales with first and last instances = 0,0,0
#With the rest being 1,1,1
scales = np.ones((edf.shape[0],3))*10000
scales[0,:] = 0
scales[-1,:] = 0
orig_cube.ADD_KEYFRAMES(data_path='scale',scale=scales,frame=edf['time'])