Continue Blender Web parity task handoff
This commit is contained in:
65
tools/web/.tmp-driver-button-ui-experiment.py
Normal file
65
tools/web/.tmp-driver-button-ui-experiment.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import json
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
FIXTURE = pathlib.Path(sys.argv[sys.argv.index("--") + 1]).resolve()
|
||||
REPORT = pathlib.Path(sys.argv[sys.argv.index("--") + 2]).resolve()
|
||||
OUTPUT = pathlib.Path(sys.argv[sys.argv.index("--") + 3]).resolve()
|
||||
|
||||
|
||||
class DriverButtonPanel(bpy.types.Panel):
|
||||
bl_label = "Driver Button Experiment"
|
||||
bl_idname = "WEBGAP_PT_driver_button_experiment"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "object"
|
||||
bl_order = -1000
|
||||
|
||||
def draw(self, context):
|
||||
self.layout.prop(context.object, '["drive_target"]', text="drive_target")
|
||||
|
||||
|
||||
bpy.utils.register_class(DriverButtonPanel)
|
||||
|
||||
|
||||
def driver_report(obj):
|
||||
if obj is None or obj.animation_data is None:
|
||||
return []
|
||||
return [
|
||||
{
|
||||
"path": curve.data_path,
|
||||
"index": curve.array_index,
|
||||
"expression": curve.driver.expression if curve.driver else "",
|
||||
}
|
||||
for curve in obj.animation_data.drivers
|
||||
]
|
||||
|
||||
|
||||
def poll_driver():
|
||||
current = driver_report(obj)
|
||||
if current:
|
||||
REPORT.write_text(json.dumps({"drivers": current}, indent=2) + "\n", encoding="utf-8")
|
||||
bpy.ops.wm.save_as_mainfile(filepath=str(OUTPUT), check_existing=False, compress=True)
|
||||
return None
|
||||
return 0.25
|
||||
|
||||
|
||||
bpy.ops.wm.open_mainfile(filepath=str(FIXTURE), load_ui=False)
|
||||
obj = bpy.data.objects.get("WebGapAnimDriverButtonAddObject")
|
||||
|
||||
|
||||
def setup_ui():
|
||||
window = bpy.context.window
|
||||
if window is None:
|
||||
return 0.25
|
||||
screen = window.screen
|
||||
area = next(candidate for candidate in screen.areas if candidate.type == "PROPERTIES")
|
||||
area.spaces.active.context = "OBJECT"
|
||||
bpy.app.timers.register(poll_driver, first_interval=0.5)
|
||||
return None
|
||||
|
||||
|
||||
bpy.app.timers.register(setup_ui, first_interval=0.5)
|
||||
Reference in New Issue
Block a user