Skip to content

Commit 5dcff98

Browse files
author
Roberto De Ioris
authored
Update SnippetsForStaticAndSkeletalMeshes.md
1 parent ae83b62 commit 5dcff98

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tutorials/SnippetsForStaticAndSkeletalMeshes.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,37 @@ Once you run the script, you will end with a SkeletalMesh with an animation and
939939

940940
The only relevant part in the code is the (a bit convoluted) way we move from OpenGL based conventions (y on top, x right, z forward right handed, counterwise backface culling) to the UE4 ones (z on top, x forward left handed, y right, clockwise backface culling)
941941

942+
This method is how we build the skeleton:
943+
944+
```python
945+
def build_skeleton(self, pkg_name, obj_name):
946+
pkg = ue.get_or_create_package('{0}_Skeleton'.format(pkg_name))
947+
skel = Skeleton('{0}_Skeleton'.format(obj_name), pkg)
948+
# add a root bone from which all of the others will descend
949+
# (this trick will avoid generating an invalid skeleton [and a crash], as in UE4 only one root can exist)
950+
skel.skeleton_add_bone('root', -1, FTransform())
951+
# iterate bones in the json file, note that we move from opengl axis to UE4
952+
# (y on top, x right, z forward right-handed) to (y right, x forward left-handed, z on top)
953+
for bone in self.model['bones']:
954+
# assume no rotation
955+
quat = FQuat()
956+
# give priority to quaternions
957+
# remember to negate x and y axis, as we invert z on position
958+
if 'rotq' in bone:
959+
quat = FQuat(bone['rotq'][2], bone['rotq'][0] * -1,
960+
bone['rotq'][1] * -1, bone['rotq'][3])
961+
elif 'rot' in bone:
962+
quat = FRotator(bone['rot'][2], bone['rot'][0] * -
963+
1, bome['rot'][1] * -1).quaternion()
964+
pos = FVector(bone['pos'][2] * -1, bone['pos'][0],
965+
bone['pos'][1]) * self.scale
966+
# always set parent+1 as we added the root bone before
967+
skel.skeleton_add_bone(
968+
bone['name'], bone['parent'] + 1, FTransform(pos, quat))
969+
skel.save_package()
970+
return skel
971+
```
972+
942973
## Animations: Getting curves from BVH files
943974

944975
BVH files are interesting for lot of reasons. First of all, BVH is basically the standard de-facto for motion capture devices. It is a textual human-readable format. And, maybe more important for this page, will heavily push your linear-algebra skills...

0 commit comments

Comments
 (0)