73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
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 new knot configuration
|
|
item = scene.knot_list.add()
|
|
item.name = "Trefoil Knot"
|
|
item.shape_type = 'TORUS_KNOT'
|
|
|
|
# Topology (coprime p and q)
|
|
item.torus_p = 2 # Revolutions around the torus axis
|
|
item.torus_q = 3 # Spins around the torus tube
|
|
|
|
# Dimensions
|
|
item.mode = 'MAJOR_MINOR'
|
|
item.torus_R = 2.0 # Distance from center to tube center
|
|
item.torus_r = 0.8 # Radius of the tube
|
|
|
|
# Geometry
|
|
item.geo_bDepth = 0.08 # Bevel depth (thickness of the curve tube)
|
|
|
|
# Material settings
|
|
item.material_mode = 'PRESET'
|
|
item.shader_id = 'GLOSS_BLUE'
|
|
item.preset_color = (0.2, 0.6, 1.0)
|
|
item.preset_roughness = 0.1
|
|
item.preset_metallic = 0.2
|
|
|
|
# 6. Fit timeline so the knot plays
|
|
scene.knot_globals.frames_per_knot = 120
|
|
bpy.ops.knot.fit_timeline()
|
|
|
|
# 7. Force instant geometry generation for current frame
|
|
pr3tz.knot_frame_handler(scene)
|
|
|
|
print("\n=====================================================================")
|
|
print("Example 1: Simple Torus Knot Loaded!")
|
|
print("=====================================================================")
|
|
print("Generated a 3D Trefoil Knot (p=2, q=3) using the 'GLOSS_BLUE' preset.")
|
|
print("Interact with it in Blender:")
|
|
print(" - Open the 'Pr3tz' N-Panel in the 3D Viewport sidebar.")
|
|
print(" - Change 'Revolutions (p)' or 'Spins (q)' to see the knot shape morph.")
|
|
print(" - Modify the 'Bevel Depth' to change its thickness.")
|
|
print("=====================================================================\n")
|