I'm using a function to render thumbnails of some grease pencils, and in order to frame it well, i use the object.matrix_world to get the world coordinates of my points.
def render_scene_frame(frame_number, gplib_data) : #gplib_data is a property group (stored in another scene)
print('render frame ', frame_number)
mode = gplib_data.mode
scene = bpy.context.scene
scene.frame_current = frame_number
print('scene/fr, mode : ', scene.name, scene.frame_current, mode)
for ob in scene.collection.all_objects :
if ob.type == 'GPENCIL' :
ob_matrix_world = Matrix(ob.matrix_world)
gp_ob = ob.data
print('****', ob.name, ob.data.name)
print(ob_matrix_world)
#... some more code
i'm calling this function from an operator, here's the part of code :
if self.gplib_data.export_anim == True : #assume it's true
self.gplib_data.export_mode = 'ANIM'
render_scene_frame(1, self.gplib_data)
if self.gplib_data.export_poses == True : #assume it's true too
self.gplib_data.export_mode = 'POSE'
for frame in range(1, ((self.gplib_data.export_range_stop - self.gplib_data.export_range_start) + 2)) : #assume it's something like range(1, 5)
render_scene_frame(frame, self.gplib_data)
According to me, it will "render" (or at least print objects matrix_world) frame 1 twice, then frame 2, 3 ,4. And it tries to. But the matrix_world print shows different values for both frame 1, which doesn't makes sense to me. Looking deeper i feel that the ob_matrix_world, is late by one iteration.
render frame 1
scene/fr/mode: Template Scene 1 ANIM
**** _head _head
<Matrix 4x4 ( 0.9998, 0.0000, -0.0198, -0.7120)
(-0.0000, 1.0000, 0.0000, -0.0000)
( 0.0198, 0.0000, 0.9998, 0.2139)
( 0.0000, 0.0000, 0.0000, 1.0000)>
**** _hat _hat
<Matrix 4x4 ( 0.9998, 0.0000, -0.0198, -0.7422)
(-0.0000, 1.0000, 0.0000, -0.1300)
( 0.0198, 0.0000, 0.9998, 0.9114)
( 0.0000, 0.0000, 0.0000, 1.0000)>
render frame 1
scene/fr/mode: Template Scene 1 POSE
**** _head _head
<Matrix 4x4 ( 0.9959, 0.0000, -0.0904, -0.6969)
(-0.0000, 1.0000, -0.0000, -0.0420)
( 0.0904, 0.0000, 0.9959, 0.3414)
( 0.0000, 0.0000, 0.0000, 1.0000)>
**** _hat _hat
<Matrix 4x4 ( 0.9959, 0.0000, -0.0904, -0.7762)
(-0.0000, 1.0000, -0.0000, -0.1720)
( 0.0904, 0.0000, 0.9959, 1.0350)
( 0.0000, 0.0000, 0.0000, 1.0000)>
I'm definetly missing something. Thanks for helping me !
Scene.frame_set(frame_number)instead of assigning it toScene.frame_current. – brockmann Dec 22 '20 at 18:22