0
$\begingroup$

I wanna apply the rotation of an object, each time a certian case is true. The problem is, this has to work while an animation renders. So bevore it render the frame x, it checks if the case is true and if it is, then it applys the rotation of the object. I use this in my Rubik's cube rig. The apply_transfrom doesn't work in this case.

Here is the testing .blend: https://www.dropbox.com/s/hz8nxx87b3wucx4/untitled.blend?dl=0

Open the .blend, run the two script, and press F12. The goal is that the rotation is applied on all cubes.

Update: I found the solution myself. I use this script here: Apply mesh transformations to primitive_uv_sphere_add()

$\endgroup$

1 Answer 1

1
$\begingroup$

First see this and compare it with your code:

import bpy
from mathutils import Vector

# call this only once
# it adds vector attribute to all Object entities
bpy.types.Object.vector = bpy.props.FloatVectorProperty()

# design your callback function like this
def test(scenes):
    # select the group
    bpy.ops.object.select_all(action='DESELECT')
    for obj in bpy.data.groups['Würfel'].objects:
        obj.select = True

    # apply rotation
    bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)

    # store the locations
    for obj in bpy.data.groups['Würfel'].objects:
        loc = obj.location
        obj.vector = Vector((round(loc[0], 0), round(loc[1], 0), round(loc[2], 0)))

If you do a test call with test(bpy.context.scene) it should execute without errors.

If you do bpy.app.handlers.frame_change_pre.append(test) it will work fine on every frame change.

When the objects go into render pipeline the transformations are already 'set/converted' so there is really no data to transform in the pre_render handler.

$\endgroup$
6
  • $\begingroup$ I did the setup like you said and it kind of works. When I first run the script the objects get selected and the rotation gets applied. The problem is when I try to run the script via 'frame_change' it gives me the problem shown in the picture. I think I have done something wrong. Also I think I didn't explain my problem well enough. I want this script to run while an animation renders. So when a specific case is true, it applies the rotation to all objects in the group before the frame of the animation gets rendered. pasteall.org/pic/82041 $\endgroup$
    – 3Descape
    Jan 6, 2015 at 11:39
  • $\begingroup$ You need to add the frame_change handler function without parameters - like bpy.app.handlers.frame_change_pre.append(test) not like bpy.app.handlers.frame_change_pre.append(test(bpy.context.scene)). Fix this and it should work without problems $\endgroup$ Jan 6, 2015 at 13:19
  • $\begingroup$ Yes it works with frame_change_pre in the viewport, but as son as I try to run it with render_pre while rendering it doesn't work.(I think I didn't explan to well what I want, Sorry) But that's what I wanna have: The think is that I try to make a rubik's cube rig with python. If one segment is rotated 90° the rotation get's applied. In the viewport this work fine, but now I need a way to do this while rendering an animation. There I can't use the transfrom_apply. So before each frame is rendered, it checks if the rotation == 90° and if it does it applies the rotation. $\endgroup$
    – 3Descape
    Jan 6, 2015 at 13:59
  • $\begingroup$ @3Descape Please edit your question instead of explaining your idea in the comment section so the question is useful for the community. $\endgroup$
    – p2or
    Jan 6, 2015 at 14:24
  • 1
    $\begingroup$ @3Descape Just use the frame_change_pre, it will work on render animation too because before such render the frame needs to change. Problem is only the first frame so start at frame 0 (or -1 if the animation starts on 0) so there is the frame_change. $\endgroup$ Jan 6, 2015 at 14:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .