Add example scripts for major functions

This commit is contained in:
Stefan Cepko
2026-06-05 05:36:50 -04:00
parent 31e464f5cd
commit 8292682ac2
10 changed files with 763 additions and 2 deletions
+93
View File
@@ -0,0 +1,93 @@
import sys
import os
import bpy
# 1. Resolve path to include workspace root so pr3tz can be imported
dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if dir_path not in sys.path:
sys.path.append(dir_path)
import pr3tz
# 2. Register pr3tz addon
try:
if "pr3tz" in sys.modules:
import importlib
importlib.reload(pr3tz)
else:
import pr3tz
pr3tz.register()
print("[Pr3tz] Registered successfully!")
except Exception as e:
print(f"[Pr3tz] Failed to register: {e}")
sys.exit(1)
# 3. Configure the scene (camera, lights, timeline, etc.)
pr3tz.setup_scene()
# 4. Clear existing playlist
scene = bpy.context.scene
scene.knot_list.clear()
# 5. Add a simple spinning knot configuration
item = scene.knot_list.add()
item.name = "Render Example Knot"
item.shape_type = 'TORUS_KNOT'
item.torus_p = 2
item.torus_q = 5
item.torus_R = 2.0
item.torus_r = 0.8
item.geo_bDepth = 0.06
item.spin_phase_rate = 0.02
item.material_mode = 'PRESET'
item.shader_id = 'NEON_GLOW'
item.preset_color = (0.0, 0.5, 1.0) # Neon blue
item.preset_emission_strength = 2.0
pr3tz.materials.prewarm_materials_and_blends(scene)
# 6. Configure rendering for a super-fast headless export
scene.render.engine = 'CYCLES'
scene.cycles.samples = 4 # Very low samples for quick testing
scene.cycles.use_denoising = False
# Render size (small for fast test rendering)
scene.render.resolution_x = 480
scene.render.resolution_y = 270
scene.render.resolution_percentage = 100
# Setup Output directory
output_dir = os.path.join(dir_path, "renders")
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Set base filename
scene.render.filepath = os.path.join(output_dir, "frame_")
scene.render.image_settings.file_format = 'PNG'
scene.render.image_settings.color_mode = 'RGBA'
# 7. Render a short range (10 frames)
start_frame = 1
end_frame = 10
print(f"\nHeadless Render Started. Rendering frames {start_frame} to {end_frame}...")
for f in range(start_frame, end_frame + 1):
print(f"Rendering frame {f}/{end_frame}...")
scene.frame_set(f) # Triggers knot_frame_handler automatically
# We construct the filepath for this frame manually to save it
scene.render.filepath = os.path.join(output_dir, f"frame_{f:04d}.png")
# Execute render
bpy.ops.render.render(write_still=True)
print(f"\nRendering complete! Output frames saved to: {output_dir}")
print("\n=====================================================================")
print("Example 7: Headless Render Script Completed!")
print("=====================================================================")
print("You can run this script from your terminal headlessly using:")
print(" blender -b -P examples/07_headless_render.py")
print("=====================================================================\n")