@@ -991,6 +991,9 @@ def loadFromBlender(self, glm_filepath_rel: str, gla_filepath_rel: str, basepath
991
991
"" or gla_filepath_rel == "*default" )
992
992
skeleton_object : Optional [bpy .types .Object ] = None
993
993
boneIndexMap : Optional [BoneIndexMap ] = None
994
+ skeleton_armature : Optional [bpy .types .Armature ] = None
995
+ # Assume people usually use the "rest pose" before exporting
996
+ old_pose = "REST"
994
997
if defaultSkeleton :
995
998
# no skeleton available, generate default/unit skeleton instead
996
999
self .header .numBones = 1
@@ -1004,17 +1007,22 @@ def loadFromBlender(self, glm_filepath_rel: str, gla_filepath_rel: str, basepath
1004
1007
if obj .type != 'ARMATURE' :
1005
1008
return False , ErrorMessage ("skeleton_root is no Armature!" )
1006
1009
skeleton_armature = downcast (bpy .types .Armature , obj .data )
1010
+ # Exporting in pose position will lead to incorrect results, make sure to reset to users last position!
1011
+ old_pose = skeleton_armature .pose_position
1012
+ skeleton_armature .pose_position = "REST"
1007
1013
1008
1014
boneIndexMap , message = buildBoneIndexLookupMap (JAFilesystem .RemoveExtension (
1009
1015
JAFilesystem .AbsPath (gla_filepath_rel , basepath )) + ".gla" )
1010
1016
if boneIndexMap is None :
1017
+ skeleton_armature .pose_position = old_pose
1011
1018
return False , message
1012
1019
1013
1020
self .header .numBones = len (boneIndexMap )
1014
1021
1015
1022
# check if skeleton matches the specified one
1016
1023
for bone in skeleton_armature .bones :
1017
1024
if bone .name not in boneIndexMap :
1025
+ skeleton_armature .pose_position = old_pose
1018
1026
return False , ErrorMessage (f"skeleton_root does not match specified gla, could not find bone { bone .name } " )
1019
1027
1020
1028
# load from Blender
@@ -1030,13 +1038,17 @@ def loadFromBlender(self, glm_filepath_rel: str, gla_filepath_rel: str, basepath
1030
1038
f"Found { self .header .numLODs } model_root objects, i.e. LOD levels" )
1031
1039
1032
1040
if self .header .numLODs == 0 :
1041
+ if skeleton_armature :
1042
+ skeleton_armature .pose_position = old_pose
1033
1043
return False , ErrorMessage ("Could not find model_root_0 object" )
1034
1044
1035
1045
# build hierarchy from first LOD
1036
1046
surfaceIndexMap : Dict [str , int ] = {} # surface name -> index
1037
1047
success , message = self .surfaceDataCollection .loadFromBlender (
1038
1048
rootObjects [0 ], surfaceIndexMap )
1039
1049
if not success :
1050
+ if skeleton_armature :
1051
+ skeleton_armature .pose_position = old_pose
1040
1052
return False , message
1041
1053
self .surfaceDataOffsets .calculateOffsets (self .surfaceDataCollection )
1042
1054
@@ -1047,12 +1059,16 @@ def loadFromBlender(self, glm_filepath_rel: str, gla_filepath_rel: str, basepath
1047
1059
success , message = self .LODCollection .loadFromBlender (
1048
1060
rootObjects , surfaceIndexMap , self .surfaceDataCollection , boneIndexMap , skeleton_object )
1049
1061
if not success :
1062
+ if skeleton_armature :
1063
+ skeleton_armature .pose_position = old_pose
1050
1064
return False , message
1051
1065
1052
1066
self .LODCollection .calculateOffsets (self .header .ofsLODs )
1053
1067
1054
1068
# calculate offsets etc.4
1055
1069
self ._calculateHeaderOffsets ()
1070
+ if skeleton_armature :
1071
+ skeleton_armature .pose_position = old_pose
1056
1072
return True , NoError
1057
1073
1058
1074
def saveToFile (self , filepath_abs : str ) -> Tuple [bool , ErrorMessage ]:
0 commit comments