- TOLERENCE = 4
- m = float(10**TOLERENCE)
-
- # Would be nice to know if this can be done faster than it currently runs,
- # its quite slow.
- #
- key = (int(co[0]*m+0.5),
- int(co[1]*m+0.5),
- int(co[2]*m+0.5),
- int(norm[0]*m+0.5),
- int(norm[1]*m+0.5),
- int(norm[2]*m+0.5),
- int(uv[0]*m+0.5),
- int(uv[1]*m+0.5),
- colour[0], # these guys are already quantized
- colour[1], # .
- colour[2], # .
- colour[3], # .
- weights[0], # v
- weights[1],
- weights[2],
- weights[3],
- groups[0],
- groups[1],
- groups[2],
- groups[3])
-
- if key in vertex_reference:
- return vertex_reference[key]
- else:
- #{
- index = c_uint32( len(vertex_reference) )
- vertex_reference[key] = index
-
- v = mdl_vert()
- v.co[0] = co[0]
- v.co[1] = co[2]
- v.co[2] = -co[1]
- v.norm[0] = norm[0]
- v.norm[1] = norm[2]
- v.norm[2] = -norm[1]
- v.uv[0] = uv[0]
- v.uv[1] = uv[1]
- v.colour[0] = colour[0]
- v.colour[1] = colour[1]
- v.colour[2] = colour[2]
- v.colour[3] = colour[3]
- v.weights[0] = weights[0]
- v.weights[1] = weights[1]
- v.weights[2] = weights[2]
- v.weights[3] = weights[3]
- v.groups[0] = groups[0]
- v.groups[1] = groups[1]
- v.groups[2] = groups[2]
- v.groups[3] = groups[3]
-
- buffer += [v]
- return index
- #}
-#}
-
-
-# Compile a mesh (or use one from the cache) onto node, based on node_def
-# No return value
-#
-def encoder_compile_mesh( node, node_def ):
-#{
- global g_encoder
-
- graph = g_encoder['scene_graph']
- graph_lookup = g_encoder['graph_lookup']
- mesh_cache = g_encoder['mesh_cache']
- obj = node_def['obj']
- armature_def = None
- can_use_cache = True
+ folder = bpy.path.abspath(bpy.context.scene.SR_data.export_dir)
+ path = F"{folder}{collection.name}.mdl"
+ print( path )
+
+ fp = open( path, "wb" )
+ header = mdl_header()
+ header.version = 40
+ sr_array_title( header.arrays, \
+ 'index', len(file_array_instructions), \
+ sizeof(mdl_array), header_size )
+
+ fp.write( bytearray_align_to( bytearray(header), 8 ) )
+
+ print( F'[SR] {"name":>16}| count | offset' )
+ index = bytearray()
+ for name,info in file_array_instructions.items():#{
+ arr = mdl_array()
+ offset = info['offset'] + header_size + index_size
+ sr_array_title( arr, name, info['count'], info['size'], offset )
+ index.extend( bytearray(arr) )
+
+ print( F'[SR] {name:>16}| {info["count"]: 8} '+\
+ F' 0x{info["offset"]:02x}' )
+ #}
+ fp.write( bytearray_align_to( index, 8 ) )
+ #bytearray_print_hex( index )
+
+ for name,info in file_array_instructions.items():#{
+ fp.write( bytearray_align_to( info['data'], 8 ) )
+ #}
+
+ fp.close()
+
+ print( '[SR] done' )
+#}
+
+class SR_SCENE_SETTINGS(bpy.types.PropertyGroup):
+#{
+ use_hidden: bpy.props.BoolProperty( name="use hidden", default=False )
+ export_dir: bpy.props.StringProperty( name="Export Dir", subtype='DIR_PATH' )
+ gizmos: bpy.props.BoolProperty( name="Draw Gizmos", default=True )
+
+ panel: bpy.props.EnumProperty(
+ name='Panel',
+ description='',
+ items=[
+ ('EXPORT', 'Export', '', 'MOD_BUILD',0),
+ ('ENTITY', 'Entity', '', 'MONKEY',1),
+ ('SETTINGS', 'Settings', 'Settings', 'PREFERENCES',2),
+ ],
+ )
+#}
+
+class SR_COLLECTION_SETTINGS(bpy.types.PropertyGroup):
+#{
+ pack_textures: bpy.props.BoolProperty( name="Pack Textures", default=False )
+ animations: bpy.props.BoolProperty( name="Export animation", default=True)
+#}
+
+def sr_get_mirror_bone( bones ):
+#{
+ side = bones.active.name[-1:]
+ other_name = bones.active.name[:-1]
+ if side == 'L': other_name += 'R'
+ elif side == 'R': other_name += 'L'
+ else: return None
+
+ for b in bones:#{
+ if b.name == other_name:
+ return b
+ #}