Blender (software): Difference between revisions

Line 93: Line 93:
exec(compile(open(filepath).read(), filename, 'exec'))
exec(compile(open(filepath).read(), filename, 'exec'))
</syntaxhighlight>
</syntaxhighlight>
===Rendering===
<syntaxhighlight lang="python">
def render_to_file(filepath, width, height):
    # Set device to GPU
    bpy.context.scene.cycles.device = "GPU"
    # Set resolution
    bpy.context.scene.render.resolution_x = width
    bpy.context.scene.render.resolution_y = height
    bpy.context.scene.render.resolution_percentage = 100
    # Set output file path
    bpy.context.scene.render.filepath = filepath
    # Do render
    bpy.ops.render.render(write_still=True)
</syntaxhighlight>
===MVP matrices===
[https://github.com/blender/blender/blob/v2.93.0/doc/python_api/examples/gpu.9.py Example python code]
<pre>
# Model matrix
my_object.matrix_world
# View matrix
bpy.context.scene.camera.matrix_world.inverted()
# Projection matrix
projection_matrix = bpy.context.scene.camera.calc_matrix_camera(
    bpy.context.evaluated_depsgraph_get(), x=WIDTH, y=HEIGHT)
</pre>


==Compiling Blender==
==Compiling Blender==