Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,9 @@ from PIL import ImageColor
|
|
| 4 |
from pathlib import Path
|
| 5 |
import bpy
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
rbg1 = ImageColor.getcolor(color1, "RGB")
|
| 9 |
rgb2 = ImageColor.getcolor(color2, "RGB")
|
| 10 |
print(rbg1, rgb2 , light_position)
|
|
@@ -14,19 +16,17 @@ def generate(color1, color2, light_position):
|
|
| 14 |
bpy.ops.object.select_all(action='DESELECT')
|
| 15 |
bpy.ops.object.select_by_type(type='MESH')
|
| 16 |
bpy.ops.object.delete()
|
| 17 |
-
|
| 18 |
# Add a torus
|
| 19 |
-
bpy.ops.mesh.primitive_torus_add(
|
| 20 |
major_radius=1.5,
|
| 21 |
minor_radius=0.75,
|
| 22 |
major_segments=48*4,
|
| 23 |
minor_segments=12*4,
|
| 24 |
align="WORLD",
|
| 25 |
location=(0, 1, 1),
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
# Assigning the torus to a variable
|
| 29 |
-
torus = bpy.context.active_object
|
| 30 |
|
| 31 |
# Create a new material and assign it to the torus
|
| 32 |
material = bpy.data.materials.new(name="RainbowGradient")
|
|
@@ -79,17 +79,17 @@ def generate(color1, color2, light_position):
|
|
| 79 |
|
| 80 |
# Render
|
| 81 |
path = "test.png"
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
bpy.ops.render.render(write_still=True)
|
| 87 |
-
bpy.data.images["Render Result"].save_render(filepath=
|
| 88 |
|
| 89 |
# display(Image("test_sphere.png"))
|
| 90 |
|
| 91 |
# Read the saved image into memory and encode it to base64
|
| 92 |
-
temp_filepath = Path(
|
| 93 |
with temp_filepath.open("rb") as f:
|
| 94 |
my_img = base64.b64encode(f.read()).decode("utf-8")
|
| 95 |
|
|
|
|
| 4 |
from pathlib import Path
|
| 5 |
import bpy
|
| 6 |
|
| 7 |
+
blender_context = bpy.context
|
| 8 |
+
|
| 9 |
+
async def generate(color1, color2, light_position):
|
| 10 |
rbg1 = ImageColor.getcolor(color1, "RGB")
|
| 11 |
rgb2 = ImageColor.getcolor(color2, "RGB")
|
| 12 |
print(rbg1, rgb2 , light_position)
|
|
|
|
| 16 |
bpy.ops.object.select_all(action='DESELECT')
|
| 17 |
bpy.ops.object.select_by_type(type='MESH')
|
| 18 |
bpy.ops.object.delete()
|
| 19 |
+
|
| 20 |
# Add a torus
|
| 21 |
+
print(bpy.ops.mesh.primitive_torus_add(
|
| 22 |
major_radius=1.5,
|
| 23 |
minor_radius=0.75,
|
| 24 |
major_segments=48*4,
|
| 25 |
minor_segments=12*4,
|
| 26 |
align="WORLD",
|
| 27 |
location=(0, 1, 1),
|
| 28 |
+
))
|
| 29 |
+
torus = blender_context.active_object
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Create a new material and assign it to the torus
|
| 32 |
material = bpy.data.materials.new(name="RainbowGradient")
|
|
|
|
| 79 |
|
| 80 |
# Render
|
| 81 |
path = "test.png"
|
| 82 |
+
blender_context.scene.render.resolution_x = 1000
|
| 83 |
+
blender_context.scene.render.resolution_y = 400
|
| 84 |
+
blender_context.scene.render.image_settings.file_format = "PNG"
|
| 85 |
+
blender_context.scene.render.filepath = path
|
| 86 |
bpy.ops.render.render(write_still=True)
|
| 87 |
+
bpy.data.images["Render Result"].save_render(filepath=blender_context.scene.render.filepath)
|
| 88 |
|
| 89 |
# display(Image("test_sphere.png"))
|
| 90 |
|
| 91 |
# Read the saved image into memory and encode it to base64
|
| 92 |
+
temp_filepath = Path(blender_context.scene.render.filepath)
|
| 93 |
with temp_filepath.open("rb") as f:
|
| 94 |
my_img = base64.b64encode(f.read()).decode("utf-8")
|
| 95 |
|