Add example scripts for major functions
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
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 and populate with a couple of animated shapes
|
||||
scene = bpy.context.scene
|
||||
scene.knot_list.clear()
|
||||
|
||||
item_1 = scene.knot_list.add()
|
||||
item_1.name = "Bake Target A"
|
||||
item_1.shape_type = 'TORUS_KNOT'
|
||||
item_1.torus_p = 2
|
||||
item_1.torus_q = 3
|
||||
item_1.spin_phase_rate = 0.05
|
||||
item_1.material_mode = 'PRESET'
|
||||
item_1.shader_id = 'LAVA'
|
||||
|
||||
item_2 = scene.knot_list.add()
|
||||
item_2.name = "Bake Target B"
|
||||
item_2.shape_type = 'LISSAJOUS'
|
||||
item_2.liss_kx = 3
|
||||
item_2.liss_ky = 2
|
||||
item_2.liss_amp = 2.0
|
||||
item_2.material_mode = 'PRESET'
|
||||
item_2.shader_id = 'GLASS'
|
||||
item_2.transition_frames = 20
|
||||
|
||||
pr3tz.materials.prewarm_materials_and_blends(scene)
|
||||
|
||||
# 5. Set a short frame range for rapid baking
|
||||
scene.frame_start = 1
|
||||
scene.frame_end = 40
|
||||
scene.render.fps = 24
|
||||
|
||||
# Setup target filepath for the baked blend file
|
||||
baked_dir = os.path.join(dir_path, "baked")
|
||||
if not os.path.exists(baked_dir):
|
||||
os.makedirs(baked_dir)
|
||||
output_blend = os.path.join(baked_dir, "baked_knot_animation.blend")
|
||||
|
||||
# 6. Execute programmatic bake and export
|
||||
print(f"\nStarting programmatic bake & export to: {output_blend}...")
|
||||
# Run the operator directly, passing parameters.
|
||||
# Since it inherits from ExportHelper, it expects filepath to be passed.
|
||||
bpy.ops.knot.bake_export(
|
||||
filepath=output_blend,
|
||||
use_render_resolution=False, # Set to False to bake quickly at preview res
|
||||
pack_textures=True,
|
||||
split_export=False
|
||||
)
|
||||
|
||||
print(f"\nBake completed! stand-alone .blend file saved at: {output_blend}")
|
||||
|
||||
print("\n=====================================================================")
|
||||
print("Example 8: Programmatic Bake & Export Script Completed!")
|
||||
print("=====================================================================")
|
||||
print("The procedural knot was successfully baked to standalone meshes.")
|
||||
print("The output .blend file requires no addons and can be rendered")
|
||||
print("on any computer or render farm (e.g. SheepIt).")
|
||||
print("=====================================================================\n")
|
||||
Reference in New Issue
Block a user