Skip to content

Instantly share code, notes, and snippets.

@kolibril13
Created November 21, 2024 14:58
Show Gist options
  • Save kolibril13/27c755f616442f336d14b76e20c0003c to your computer and use it in GitHub Desktop.
Save kolibril13/27c755f616442f336d14b76e20c0003c to your computer and use it in GitHub Desktop.
# /// script
# requires-python = ">=3.11,<3.12"
# dependencies = [
# "bpy==4.2.0",
# "marimo",
# ]
# ///
import marimo
__generated_with = "0.9.20"
app = marimo.App(width="medium")
@app.cell(hide_code=True)
def __(mo):
mo.md(r"""# Minimal Blender + Notebook example""")
return
@app.cell
def __():
import bpy
import marimo as mo
from math import radians
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.cycles.samples = 128
bpy.context.scene.render.resolution_x = 500
bpy.context.scene.render.resolution_y = 500
return bpy, mo, radians
@app.cell
def __(bpy, mo, radians):
bpy.ops.object.select_all(action='DESELECT')
for obj in bpy.context.scene.objects:
if obj.type != 'CAMERA':
obj.select_set(True)
bpy.ops.object.delete()
bpy.ops.object.light_add(type='SUN')
sun = bpy.context.object
sun.location = (0, 0, 0)
sun.rotation_euler = (radians(204), radians(-133), radians(-67))
sun.data.energy = 5
bpy.ops.mesh.primitive_torus_add(major_radius=3, minor_radius=1, location=(0, 0, 0))
torus = bpy.context.object
subsurf = torus.modifiers.new(name='Subdivision Surface', type='SUBSURF')
subsurf.levels = 4
subsurf.render_levels = 4
displace = torus.modifiers.new(name='Displacement', type='DISPLACE')
texture = bpy.data.textures.new(name='Displacement Texture', type='CLOUDS')
displace.texture = texture
displace.strength = 0.3
material = bpy.data.materials.new(name="OrangeMaterial")
material.use_nodes = False
material.diffuse_color = (1.0, 0.5, 0.0, 1.0) # RGBA for orange
torus.data.materials.append(material)
bpy.ops.render.render(write_still=True)
bpy.data.images['Render Result'].save_render(filepath="img.png")
mo.image("img.png")
return displace, material, obj, subsurf, sun, texture, torus
@app.cell
def __():
return
if __name__ == "__main__":
app.run()
@kolibril13
Copy link
Author

img

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment