- elif classtype == 'k_classtype_skeleton':
- node.classtype = 11
- entdata_length += sizeof( classtype_skeleton )
- skeleton = classtype_skeleton()
-
- armature_def = graph_lookup[obj]
- armature = obj
- bones = armature_def['bones']
- skeleton.channels = len(bones)
- skeleton.ik_count = armature_def["ik_count"]
- skeleton.collider_count = armature_def["collider_count"]
-
- if armature.animation_data:
- previous_frame = bpy.context.scene.frame_current
- previous_action = armature.animation_data.action
-
- skeleton.anim_start = len(anim_buffer)
- skeleton.anim_count = 0
-
- for NLALayer in obj.animation_data.nla_tracks:
- for NLAStrip in NLALayer.strips:
- # Use action
- for a in bpy.data.actions:
- if a.name == NLAStrip.name:
- armature.animation_data.action = a
- break
-
- anim_start = int(NLAStrip.action_frame_start)
- anim_end = int(NLAStrip.action_frame_end)
-
- # export strips
- anim = mdl_animation()
- anim.pstr_name = emplace_string( NLAStrip.action.name )
- anim.rate = 30.0
- anim.offset = animdata_length
- anim.length = anim_end-anim_start
-
- # Export the fucking keyframes
- for frame in range(anim_start,anim_end):
- bpy.context.scene.frame_set(frame)
-
- for bone_name in bones:
- for pb in armature.pose.bones:
- if pb.name == bone_name:
- rb = armature.data.bones[ bone_name ]
-
- # relative bone matrix
- if rb.parent is not None:
- offset_mtx = rb.parent.matrix_local
- offset_mtx = offset_mtx.inverted_safe() @ \
- rb.matrix_local
-
- inv_parent = pb.parent.matrix @ offset_mtx
- inv_parent.invert_safe()
- fpm = inv_parent @ pb.matrix
- else:
- bone_mtx = rb.matrix.to_4x4()
- local_inv = rb.matrix_local.inverted_safe()
- fpm = bone_mtx @ local_inv @ pb.matrix
-
- loc, rot, sca = fpm.decompose()
-
- # local position
- final_pos = Vector(( loc[0], loc[2], -loc[1] ))
-
- # rotation
- lc_m = pb.matrix_channel.to_3x3()
- if pb.parent is not None:
- smtx = pb.parent.matrix_channel.to_3x3()
- lc_m = smtx.inverted() @ lc_m
- rq = lc_m.to_quaternion()
-
- kf = mdl_keyframe()
- kf.co[0] = final_pos[0]
- kf.co[1] = final_pos[1]
- kf.co[2] = final_pos[2]
-
- kf.q[0] = rq[1]
- kf.q[1] = rq[3]
- kf.q[2] = -rq[2]
- kf.q[3] = rq[0]
-
- # scale
- kf.s[0] = sca[0]
- kf.s[1] = sca[2]
- kf.s[2] = sca[1]
-
- animdata_buffer += [kf]
- animdata_length += sizeof(mdl_keyframe)
- break
-
- anim_buffer += [anim]
- skeleton.anim_count += 1
-
- s000 = F" [{uid: 3}/{header.node_count-1}]" + " |"*(depth-1)
- print( F"{s000} | *anim: {NLAStrip.action.name}" )
+ # Add submesh to encoder
+ #
+ g_encoder['data']['submesh'] += [sm]
+ node.submesh_count += 1
+
+ #}
+
+ # Save a reference to this node since we want to reuse the submesh indices
+ # later.
+ g_encoder['mesh_cache'][obj.data.name] = node
+#}
+
+
+def encoder_compile_ent_as( name, node, node_def ):
+#{
+ global g_encoder
+
+ if name == 'classtype_none':
+ #{
+ node.offset = 0
+ node.classtype = 0
+ return
+ #}
+ elif name not in globals():
+ #{
+ print( "Classtype '" +name + "' is unknown!" )
+ return
+ #}
+
+ buffer = g_encoder['data']['entdata']
+ node.offset = len(buffer)
+
+ cl = globals()[ name ]
+ inst = cl()
+ inst.encode_obj( node, node_def )
+
+ buffer.extend( bytearray(inst) )
+ bytearray_align_to( buffer, 4 )
+#}
+
+# Compiles animation data into model and gives us some extra node_def entries
+#
+def encoder_compile_armature( node, node_def ):
+#{
+ global g_encoder
+
+ entdata = g_encoder['data']['entdata']
+ animdata = g_encoder['data']['anim']
+ keyframedata = g_encoder['data']['keyframe']
+ mesh_cache = g_encoder['mesh_cache']
+ obj = node_def['obj']
+ bones = node_def['bones']
+
+ # extra info
+ node_def['anim_start'] = len(animdata)
+ node_def['anim_count'] = 0
+
+ # Compile anims
+ #
+ if obj.animation_data:
+ #{
+ # So we can restore later
+ #
+ previous_frame = bpy.context.scene.frame_current
+ previous_action = obj.animation_data.action
+ POSE_OR_REST_CACHE = obj.data.pose_position
+ obj.data.pose_position = 'POSE'
+
+ for NLALayer in obj.animation_data.nla_tracks:
+ #{
+ for NLAStrip in NLALayer.strips:
+ #{
+ # set active
+ #
+ for a in bpy.data.actions:
+ #{
+ if a.name == NLAStrip.name:
+ #{
+ obj.animation_data.action = a
+ break
+ #}
+ #}