Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update render8dirs.py for Blender 2.6 Python API #209

Closed
clintbellanger opened this issue Dec 3, 2011 · 3 comments
Closed

Update render8dirs.py for Blender 2.6 Python API #209

clintbellanger opened this issue Dec 3, 2011 · 3 comments
Labels

Comments

@clintbellanger
Copy link
Owner

For reference, here's the old script for 2.49. It looks for an object named "RenderPlatform", rotates it 45 degrees, then renders the animation (output files named appropriately). This continues until the animation is rendered in all 8 directions.


import Blender
from Blender import *
from Blender.Scene import Render
pi = 3.14159
deg45 = 45 * pi / 180
context = Scene.GetCurrent().getRenderingContext()
basePath = context.renderPath
for i in range(1,9):
    # objects without parents should be parented to RenderPlatform
    platform = Object.Get('RenderPlatform')
    platform.RotZ = platform.RotZ - deg45
    platform.setLocation(platform.getLocation()) # refreshes the child locations
    context.renderPath = basePath + str(i)
    context.renderAnim()
    Blender.Redraw()
context.renderPath = basePath

The goal of the script is to render sprites (e.g. character animations) in 8 directions isometric view. Objects are parented to the empty object RenderPlatform so that the scene can be rotated easily (rotate that parent object and the whole scene is facing the right direction). In future uses I probably want to only rotate cameras and lights while leaving the rest of the scene in place.

@clintbellanger
Copy link
Owner Author

Here are some hints I found. The script can probably start this way:

import bpy
pi = 3.14159
deg45 = 45 * pi / 180

To update the entire scene (apply transformations)

bpy.types.Scene.update

To render the current animation, I think:

bpy.ops.render.render(animation=True)

@AphonicChaos
Copy link

Other hints that might help:

from math import pi
# get current selected object
obj = bpy.context.object
help(obj)
...
help(obj.rotation_euler)
...
help(obj.rotation_euler.rotate)

# or maybe just...
help(bpy.ops.transform.rotate)

@clintbellanger
Copy link
Owner Author

Here we go.

import bpy
from math import radians

angle = 45
axis = 2 # z-axis
platform = bpy.data.objects["RenderPlatform"]
original_path = bpy.data.scenes[0].render.filepath

for i in range(0,8):

    # rotate the render platform and all children
    temp_rot = platform.rotation_euler
    temp_rot[axis] = temp_rot[axis] - radians(angle)
    platform.rotation_euler = temp_rot;

    # set the filename direction prefix
    bpy.data.scenes[0].render.filepath = original_path + str(i)

    # render animation for this direction
    bpy.ops.render.render(animation=True)

bpy.data.scenes[0].render.filepath = original_path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants