skelform-python 0.4.0__tar.gz → 0.4.2__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.0
3
+ Version: 0.4.2
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.0"
7
+ version = "0.4.2"
8
8
  authors = [
9
9
  { name="Retropaint", email="darkglasses1122@gmail.com" },
10
10
  ]
@@ -115,6 +115,7 @@ class Atlas:
115
115
  @dataclass
116
116
  class Armature:
117
117
  bones: list[Bone]
118
+ cached_bones: Optional[list[Bone]]
118
119
  ik_root_ids: list[int]
119
120
  animations: Optional[list[Animation]]
120
121
  atlases: list[Atlas]
@@ -131,7 +132,6 @@ def animate(
131
132
  ikf = interpolate_keyframes
132
133
 
133
134
  for bone in armature.bones:
134
- bone = copy.deepcopy(bone)
135
135
  bones.append(bone)
136
136
  id = bone.id
137
137
  # yapf: disable
@@ -178,6 +178,17 @@ def rotate(point: Vec2, rot: float):
178
178
  )
179
179
 
180
180
 
181
+ # Call this before running inheritance.
182
+ def reset_inheritance(bones, og_bones):
183
+ for b in range(len(bones)):
184
+ bones[b].pos.x = og_bones[b].pos.x
185
+ bones[b].pos.y = og_bones[b].pos.y
186
+ bones[b].rot = og_bones[b].rot
187
+ bones[b].scale.x = og_bones[b].scale.x
188
+ bones[b].scale.y = og_bones[b].scale.y
189
+
190
+ return bones
191
+
181
192
  def inheritance(bones, ik_rots):
182
193
  for bone in bones:
183
194
  if bone.parent_id != -1:
@@ -210,27 +221,28 @@ def normalize(vec):
210
221
 
211
222
 
212
223
  def construct(armature: Armature):
213
- inh_props = copy.deepcopy(armature.bones)
224
+ if armature.cached_bones is None:
225
+ armature.cached_bones = copy.deepcopy(armature.bones)
214
226
 
215
- inh_props = inheritance(inh_props, {})
216
- ik_rots = inverse_kinematics(inh_props, armature.ik_root_ids)
227
+ armature.cached_bones = reset_inheritance(armature.cached_bones, armature.bones)
228
+ armature.cached_bones = inheritance(armature.cached_bones, {})
229
+ ik_rots = inverse_kinematics(armature.cached_bones, armature.ik_root_ids)
217
230
 
218
- final_bones = copy.deepcopy(armature.bones)
219
- final_bones = inheritance(final_bones, ik_rots)
231
+ armature.cached_bones = reset_inheritance(armature.cached_bones, armature.bones)
232
+ armature.cached_bones = inheritance(armature.cached_bones, ik_rots)
220
233
 
221
- final_bones = construct_verts(final_bones)
234
+ armature.cached_bones = construct_verts(armature.cached_bones)
222
235
 
223
- return final_bones
236
+ return armature.cached_bones
224
237
 
225
238
 
226
239
  def construct_verts(bones: list[Bone]):
227
240
  for b in range(len(bones)):
228
241
  if not bones[b].vertices:
229
242
  continue
230
- bone = copy.deepcopy(bones[b])
231
243
 
232
- for v in range(len(bone.vertices)):
233
- bone.vertices[v] = inherit_vert(bone.vertices[v].pos, bone)
244
+ for v in range(len(bones[b].vertices)):
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
@@ -413,6 +425,14 @@ def check_bone_flip(bone_rot: float, scale: Vec2):
413
425
  return bone_rot
414
426
 
415
427
 
428
+ def get_bone_texture(bone_tex: str, styles: [Style]):
429
+ for style in styles:
430
+ for tex in style.textures:
431
+ if tex.name == bone_tex:
432
+ return tex
433
+ return False
434
+
435
+
416
436
  # Returns a (bone.id, Texture) map of textures to draw bones with.
417
437
  def setup_bone_textures(bones: [Bone], styles: [Style]):
418
438
  final_textures = {}
@@ -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 = "." }