skelform-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import copy
|
|
3
|
+
import pytweening
|
|
4
|
+
import zipfile
|
|
5
|
+
|
|
6
|
+
def get_frame_by_time(armature, anim_idx, elapsed, reverse):
|
|
7
|
+
anim = armature["animations"][anim_idx]
|
|
8
|
+
last_frame = anim["keyframes"][-1]["frame"]
|
|
9
|
+
|
|
10
|
+
frametime = 1 / anim["fps"]
|
|
11
|
+
frame = elapsed / frametime
|
|
12
|
+
|
|
13
|
+
if reverse:
|
|
14
|
+
frame = last_frame - frame
|
|
15
|
+
|
|
16
|
+
return frame
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def animate(armature, anim_idx, frame, after_animate=None):
|
|
20
|
+
props = []
|
|
21
|
+
keyframes = armature["animations"][anim_idx]["keyframes"]
|
|
22
|
+
|
|
23
|
+
frame %= keyframes[-1]["frame"]
|
|
24
|
+
|
|
25
|
+
for bone in armature["bones"]:
|
|
26
|
+
prop = copy.deepcopy(bone)
|
|
27
|
+
props.append(prop)
|
|
28
|
+
|
|
29
|
+
# interpolate
|
|
30
|
+
# yapf: disable
|
|
31
|
+
prop["rot"] += animate_float(keyframes, frame, prop["id"], "Rotation", 0)
|
|
32
|
+
prop["pos"]["x"] += animate_float(keyframes, frame, prop["id"], "PositionX", 0)
|
|
33
|
+
prop["pos"]["y"] += animate_float(keyframes, frame, prop["id"], "PositionY", 0)
|
|
34
|
+
prop["scale"]["x"] *= animate_float(keyframes, frame, prop["id"], "ScaleX", 1)
|
|
35
|
+
prop["scale"]["y"] *= animate_float(keyframes, frame, prop["id"], "ScaleY", 1)
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
after_animate(props, prop)
|
|
39
|
+
except:
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
if prop["parent_id"] == -1:
|
|
43
|
+
continue
|
|
44
|
+
|
|
45
|
+
# inherit parent
|
|
46
|
+
parent = [prop for prop in props if prop["id"] == props[-1]["parent_id"]][0]
|
|
47
|
+
|
|
48
|
+
prop["rot"] += parent["rot"]
|
|
49
|
+
prop["scale"]["x"] *= parent["scale"]["x"]
|
|
50
|
+
prop["scale"]["y"] *= parent["scale"]["y"]
|
|
51
|
+
prop["pos"]["x"] *= parent["scale"]["x"]
|
|
52
|
+
prop["pos"]["y"] *= parent["scale"]["y"]
|
|
53
|
+
|
|
54
|
+
x = copy.deepcopy(prop["pos"]["x"])
|
|
55
|
+
y = copy.deepcopy(prop["pos"]["y"])
|
|
56
|
+
prop["pos"]["x"] = x * math.cos(parent["rot"]) - y * math.sin(parent["rot"])
|
|
57
|
+
prop["pos"]["y"] = x * math.sin(parent["rot"]) + y * math.cos(parent["rot"])
|
|
58
|
+
|
|
59
|
+
prop["pos"]["x"] += parent["pos"]["x"]
|
|
60
|
+
prop["pos"]["y"] += parent["pos"]["y"]
|
|
61
|
+
|
|
62
|
+
return props
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def animate_float(keyframes, frame, bone_id, element, default):
|
|
66
|
+
prev_kf = {}
|
|
67
|
+
next_kf = {}
|
|
68
|
+
|
|
69
|
+
for kf in keyframes:
|
|
70
|
+
if kf["frame"] > frame:
|
|
71
|
+
break
|
|
72
|
+
elif kf["bone_id"] == bone_id and kf["element"] == element:
|
|
73
|
+
prev_kf = kf
|
|
74
|
+
|
|
75
|
+
for kf in keyframes:
|
|
76
|
+
if (
|
|
77
|
+
kf["frame"] >= frame
|
|
78
|
+
and kf["bone_id"] == bone_id
|
|
79
|
+
and kf["element"] == element
|
|
80
|
+
):
|
|
81
|
+
next_kf = kf
|
|
82
|
+
break
|
|
83
|
+
|
|
84
|
+
if prev_kf == {}:
|
|
85
|
+
prev_kf = next_kf
|
|
86
|
+
elif next_kf == {}:
|
|
87
|
+
next_kf = prev_kf
|
|
88
|
+
|
|
89
|
+
if prev_kf == {} and next_kf == {}:
|
|
90
|
+
return default
|
|
91
|
+
|
|
92
|
+
total_frames = next_kf["frame"] - prev_kf["frame"]
|
|
93
|
+
current_frame = frame - prev_kf["frame"]
|
|
94
|
+
|
|
95
|
+
if total_frames == 0:
|
|
96
|
+
return prev_kf["value"]
|
|
97
|
+
|
|
98
|
+
interp = current_frame / total_frames
|
|
99
|
+
start = prev_kf["value"]
|
|
100
|
+
end = next_kf["value"] - prev_kf["value"]
|
|
101
|
+
result = start + (end * interp)
|
|
102
|
+
return result
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: skelform_python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SkelForm runtime for Python
|
|
5
|
+
Author-email: Retropaint <darkglasses1122@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# SkelForm Python
|
|
13
|
+
|
|
14
|
+
SkelForm runtime for Python
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
skelform_python/__init__.py,sha256=_cPfBfi33lIifahstyHdJF-KXlnUo9DCh0KpfBbi4yY,2954
|
|
2
|
+
skelform_python-0.1.0.dist-info/METADATA,sha256=9Wti0bt64SSsLt1AwkKl_JHIjBf5IHu5XXnDRO29Mbs,379
|
|
3
|
+
skelform_python-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
4
|
+
skelform_python-0.1.0.dist-info/RECORD,,
|