@@ -57,16 +57,16 @@ def snap_tup(tup):
5757 return tup
5858
5959
60- def strmtx (mtx , scale = 1.0 ):
60+ def strmtx (mtx , scale = 1.0 , limit = 16 ):
6161 # When scaling the exported data, we only want to affect distances,
6262 # so we only multiply location values in the transform matrix.
6363 mtx_util = Matrix ([[0 ,0 ,0 ,0 ], [0 ,0 ,0 ,0 ],[0 ,0 ,0 ,0 ],[0 ,0 ,0 ,scale - 1 ]])
6464 mtx = (mtx * scale ).normalized () - mtx_util
65-
65+
6666 s = ""
6767 for x in range (4 ):
6868 for y in range (4 ):
69- s += "{} " .format (mtx [x ][y ])
69+ s += "{} " .format (round (( mtx [x ][y ]), limit ) )
7070 s = " {} " .format (s )
7171 return s
7272
@@ -776,9 +776,12 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
776776 self .writel (S_GEOM , 3 , "<source id=\" {}-positions\" >" .format (meshid ))
777777 float_values = ""
778778 sf = self .config ["scale_factor" ]
779+ lim = self .config ["use_limit_precision" ]
779780 for v in vertices :
780781 float_values += " {} {} {}" .format (
781- v .vertex .x * sf , v .vertex .y * sf , v .vertex .z * sf )
782+ round (v .vertex .x * sf , lim ),
783+ round (v .vertex .y * sf , lim ),
784+ round (v .vertex .z * sf , lim ))
782785 self .writel (
783786 S_GEOM , 4 , "<float_array id=\" {}-positions-array\" "
784787 "count=\" {}\" >{}</float_array>" .format (
@@ -799,7 +802,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
799802 float_values = ""
800803 for v in vertices :
801804 float_values += " {} {} {}" .format (
802- v .normal .x , v .normal .y , v .normal .z )
805+ round (v .normal .x , lim ),
806+ round (v .normal .y , lim ),
807+ round (v .normal .z , lim ))
803808 self .writel (
804809 S_GEOM , 4 , "<float_array id=\" {}-normals-array\" "
805810 "count=\" {}\" >{}</float_array>" .format (
@@ -821,7 +826,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
821826 float_values = ""
822827 for v in vertices :
823828 float_values += " {} {} {}" .format (
824- v .tangent .x , v .tangent .y , v .tangent .z )
829+ round (v .tangent .x , lim ),
830+ round (v .tangent .y , lim ),
831+ round (v .tangent .z , lim ))
825832 self .writel (
826833 S_GEOM , 4 , "<float_array id=\" {}-tangents-array\" "
827834 "count=\" {}\" >{}</float_array>" .format (
@@ -842,7 +849,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
842849 float_values = ""
843850 for v in vertices :
844851 float_values += " {} {} {}" .format (
845- v .bitangent .x , v .bitangent .y , v .bitangent .z )
852+ round (v .bitangent .x , lim ),
853+ round (v .bitangent .y , lim ),
854+ round (v .bitangent .z , lim ))
846855 self .writel (
847856 S_GEOM , 4 , "<float_array id=\" {}-bitangents-array\" "
848857 "count=\" {}\" >{}</float_array>" .format (
@@ -865,7 +874,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
865874 float_values = ""
866875 for v in vertices :
867876 try :
868- float_values += " {} {}" .format (v .uv [uvi ].x , v .uv [uvi ].y )
877+ float_values += " {} {}" .format (
878+ round (v .uv [uvi ].x , lim ),
879+ round (v .uv [uvi ].y , lim ))
869880 except :
870881 # TODO: Review, understand better the multi-uv-layer API
871882 float_values += " 0 0 "
@@ -891,7 +902,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
891902 float_values = ""
892903 for v in vertices :
893904 float_values += " {} {} {}" .format (
894- v .color .x , v .color .y , v .color .z )
905+ round (v .color .x , lim ),
906+ round (v .color .y , lim ),
907+ round (v .color .z , lim ))
895908 self .writel (
896909 S_GEOM , 4 , "<float_array id=\" {}-colors-array\" "
897910 "count=\" {}\" >{}</float_array>" .format (
@@ -998,10 +1011,11 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
9981011 skel_source ))
9991012 else :
10001013 self .writel (S_SKIN , 2 , "<skin source=\" #{}\" >" .format (meshid ))
1001-
1014+
1015+ lim = self .config ["use_limit_precision" ]
10021016 self .writel (
10031017 S_SKIN , 3 , "<bind_shape_matrix>{}</bind_shape_matrix>" .format (
1004- strmtx (node .matrix_world )))
1018+ strmtx (node .matrix_world , 1 , lim )))
10051019 # Joint Names
10061020 self .writel (S_SKIN , 3 , "<source id=\" {}-joints\" >" .format (contid ))
10071021 name_values = ""
@@ -1026,8 +1040,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
10261040 contid ))
10271041 pose_values = ""
10281042 sf = self .config ["scale_factor" ]
1043+ lim = self .config ["use_limit_precision" ]
10291044 for v in si ["bone_bind_poses" ]:
1030- pose_values += " {}" .format (strmtx (v , sf ))
1045+ pose_values += " {}" .format (strmtx (v , sf , lim ))
10311046
10321047 self .writel (
10331048 S_SKIN , 4 , "<float_array id=\" {}-bind_poses-array\" "
@@ -1051,7 +1066,7 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
10511066 for v in vertices :
10521067 skin_weights_total += len (v .weights )
10531068 for w in v .weights :
1054- skin_weights += " {}" .format (w )
1069+ skin_weights += " {}" .format (round ( w , lim ) )
10551070
10561071 self .writel (
10571072 S_SKIN , 4 , "<float_array id=\" {}-skin_weights-array\" "
@@ -1239,10 +1254,11 @@ def export_armature_bone(self, bone, il, si):
12391254 si ["skeleton_nodes" ].append (boneid )
12401255
12411256 sf = self .config ["scale_factor" ]
1257+ lim = self .config ["use_limit_precision" ]
12421258 if (is_ctrl_bone is False ):
12431259 self .writel (
12441260 S_NODES , il , "<matrix sid=\" transform\" >{}</matrix>" .format (
1245- strmtx (xform , sf )))
1261+ strmtx (xform , sf , lim )))
12461262
12471263 for c in bone .children :
12481264 self .export_armature_bone (c , il , si )
@@ -1584,9 +1600,10 @@ def export_node(self, node, il):
15841600 il += 1
15851601
15861602 sf = self .config ["scale_factor" ]
1603+ lim = self .config ["use_limit_precision" ]
15871604 self .writel (
15881605 S_NODES , il , "<matrix sid=\" transform\" >{}</matrix>" .format (
1589- strmtx (node .matrix_local , sf )))
1606+ strmtx (node .matrix_local , sf , lim )))
15901607 if (node .type == "MESH" ):
15911608 self .export_mesh_node (node , il )
15921609 elif (node .type == "CURVE" ):
@@ -1682,10 +1699,11 @@ def export_animation_transform_channel(self, target, keys, matrices=True):
16821699 source_interps = ""
16831700
16841701 sf = self .config ["scale_factor" ]
1702+ lim = self .config ["use_limit_precision" ]
16851703 for k in keys :
16861704 source_frames += " {}" .format (k [0 ])
16871705 if (matrices ):
1688- source_transforms += " {}" .format (strmtx (k [1 ], sf ))
1706+ source_transforms += " {}" .format (strmtx (k [1 ], sf , lim ))
16891707 else :
16901708 source_transforms += " {}" .format (k [1 ])
16911709
@@ -2019,8 +2037,9 @@ def sort_by_frame(item):
20192037 markers .append (m )
20202038 markers .sort (key = sort_by_frame )
20212039
2040+ lim = self .config ["use_limit_precision" ]
20222041 for m in markers :
2023- tkf = round (m .frame * 1 / scene .render .fps , 6 )
2042+ tkf = round (m .frame * 1 / scene .render .fps , lim )
20242043 textkeys_output .write (m .name + " " + str (tkf ) + '\n ' )
20252044 textkeys_output .close ()
20262045
0 commit comments