Files
dmarx-ComfyUI-Keyframed/nodes.py
T
2023-12-04 13:57:55 -08:00

77 lines
1.9 KiB
Python

import keyframed as kf
from keyframed.dsl import curve_from_cn_string
CATEGORY = "keyframed"
class _BASE:
CATEGORY=CATEGORY
FUNCTION = 'main'
class KfCurveFromString(_BASE):
RETURN_TYPES = ("KEYFRAMED_CURVE",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {"chigozie_string": ("STRING", {
"multiline": True, #True if you want the field to look like the one on the ClipTextEncode node
"default": "0: 1"
}),
},
}
def main(self, chigozie_string):
return curve_from_cn_string(chigozie_string)
class KfCurveFromYAML(_BASE):
RETURN_TYPES = ("KEYFRAMED_CURVE",)
@classmethod
def INPUT_TYPES(s):
return {
"required": {"yaml": ("STRING", {
"multiline": True, #True if you want the field to look like the one on the ClipTextEncode node
"default": """curve:
- - 0
- 0
- linear
- - 1
- 1
loop: false
bounce: false
duration: 1
label: foo"""
}),
},
}
def main(self, yaml):
return kf.serialization.from_yaml(yaml)
class KfEvaluateCurveAtT(_BASE):
RETURN_TYPES = ("FLOAT","INT")
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"curve": ("KEYFRAMED_CURVE",),
"t": ("INT",)
},
}
def main(self, curve, t):
return curve[t]
NODE_CLASS_MAPPINGS = {
"KfCurveFromString": KfCurveFromString,
"KfCurveFromYAML": KfCurveFromYAML,
"KfEvaluateCurveAtT": KfEvaluateCurveAtT,
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
"KfCurveFromString": "Curve From String",
"KfCurveFromYAML": "Curve From YAML",
"KfEvaluateCurveAtT": "Evaluate Curve At T",
}