skelform-python 0.4.1__tar.gz → 0.4.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: skelform_python
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: SkelForm runtime for Python
5
5
  Author-email: Retropaint <darkglasses1122@gmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "skelform_python"
7
- version = "0.4.1"
7
+ version = "0.4.3"
8
8
  authors = [
9
9
  { name="Retropaint", email="darkglasses1122@gmail.com" },
10
10
  ]
@@ -15,7 +15,6 @@ class Vec2:
15
15
 
16
16
  def __add__(self, other):
17
17
  return Vec2(self.x + other.x, self.y + other.y)
18
-
19
18
  def __mul__(self, other):
20
19
  if isinstance(other, float):
21
20
  return Vec2(self.x * other, self.y * other)
@@ -115,6 +114,7 @@ class Atlas:
115
114
  @dataclass
116
115
  class Armature:
117
116
  bones: list[Bone]
117
+ cached_bones: Optional[list[Bone]]
118
118
  ik_root_ids: list[int]
119
119
  animations: Optional[list[Animation]]
120
120
  atlases: list[Atlas]
@@ -131,7 +131,6 @@ def animate(
131
131
  ikf = interpolate_keyframes
132
132
 
133
133
  for bone in armature.bones:
134
- bone = copy.deepcopy(bone)
135
134
  bones.append(bone)
136
135
  id = bone.id
137
136
  # yapf: disable
@@ -178,6 +177,17 @@ def rotate(point: Vec2, rot: float):
178
177
  )
179
178
 
180
179
 
180
+ # Call this before running inheritance.
181
+ def reset_inheritance(bones, og_bones):
182
+ for b in range(len(bones)):
183
+ bones[b].pos.x = og_bones[b].pos.x
184
+ bones[b].pos.y = og_bones[b].pos.y
185
+ bones[b].rot = og_bones[b].rot
186
+ bones[b].scale.x = og_bones[b].scale.x
187
+ bones[b].scale.y = og_bones[b].scale.y
188
+
189
+ return bones
190
+
181
191
  def inheritance(bones, ik_rots):
182
192
  for bone in bones:
183
193
  if bone.parent_id != -1:
@@ -210,27 +220,29 @@ def normalize(vec):
210
220
 
211
221
 
212
222
  def construct(armature: Armature):
213
- inh_props = copy.deepcopy(armature.bones)
223
+ if armature.cached_bones is None:
224
+ armature.cached_bones = copy.deepcopy(armature.bones)
214
225
 
215
- inh_props = inheritance(inh_props, {})
216
- ik_rots = inverse_kinematics(inh_props, armature.ik_root_ids)
226
+ armature.cached_bones = reset_inheritance(armature.cached_bones, armature.bones)
227
+ armature.cached_bones = inheritance(armature.cached_bones, {})
228
+ ik_rots = inverse_kinematics(armature.cached_bones, armature.ik_root_ids)
217
229
 
218
- final_bones = copy.deepcopy(armature.bones)
219
- final_bones = inheritance(final_bones, ik_rots)
230
+ armature.cached_bones = reset_inheritance(armature.cached_bones, armature.bones)
231
+ armature.cached_bones = inheritance(armature.cached_bones, ik_rots)
220
232
 
221
- final_bones = construct_verts(final_bones)
233
+ armature.cached_bones = construct_verts(armature.cached_bones)
222
234
 
223
- return final_bones
235
+ return armature.cached_bones
224
236
 
225
237
 
226
238
  def construct_verts(bones: list[Bone]):
227
239
  for b in range(len(bones)):
228
240
  if not bones[b].vertices:
229
241
  continue
230
- bone = copy.deepcopy(bones[b])
231
242
 
232
- for v in range(len(bone.vertices)):
233
- bone.vertices[v] = inherit_vert(bone.vertices[v].pos, bone)
243
+ for v in range(len(bones[b].vertices)):
244
+ bones[b].vertices[v].pos = bones[b].vertices[v].init_pos
245
+ bones[b].vertices[v].pos = inherit_vert(bones[b].vertices[v].pos, bones[b])
234
246
 
235
247
  if not bones[b].binds:
236
248
  continue
@@ -251,8 +263,8 @@ def construct_verts(bones: list[Bone]):
251
263
  if not bind.is_path:
252
264
  vert: Vertex = bones[b].vertices[id]
253
265
  weight: float = bind.verts[v].weight
254
- endpos: Vec2 = inherit_vert(vert.initPos, bindBone) - vert.pos
255
- vert.pos += endPos * weight
266
+ endpos: Vec2 = inherit_vert(vert.init_pos, bindBone) - vert.pos
267
+ vert.pos += endpos * weight
256
268
  continue
257
269
 
258
270
  binds = bones[b].binds
@@ -1,8 +0,0 @@
1
- version = 1
2
- revision = 2
3
- requires-python = ">=3.9"
4
-
5
- [[package]]
6
- name = "skelform-python"
7
- version = "0.1.0.1"
8
- source = { editable = "." }