- Joined
- Aug 27, 2006
- Messages
- 223
- Reaction score
- 183
Warning: I have never played Dekaron and these posts are for sharing knowledge only. All python source code should be regarded as software prototyping unless otherwise stated.
Installation:
Usage:
License:
Source:
---------- Post added at 03:48 PM ---------- Previous post was at 03:46 PM ----------
Data Unpacker:
Usage:
License:
Source:
Installation:
- Download and install Blender 2.5 Alpha 0 from
You must be registered to see links
- Download and install Python 3.1.x from
You must be registered to see links(Windows Users)
- Copy and paste source code to Blender scripts directory (<Blender_Directory>/.blender/scripts/io) as import_scene_dekaron_mesh.py
Usage:
- Click File > Import > Dekaron (.mesh)
- Select *.mesh file
- Click Import Dekaron Mesh
License:
You must be registered to see links
Source:
Copy and save as: import_scene_dekaron_mesh.py
Code:
# Copyright (c) 2009-2012 AJ
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Version 0.0.1
# * Initial release
__author__ = 'AJ'
__email__ = ''
__url__ = ('blender', 'elysiun', 'Project homepage, http://www.ragezone.com/')
__version__ = '0.0.1'
__bpydoc__ = ''' \
Import Dekaron mesh files
'''
import bpy
import dynamic_menu
import io
import os
import struct
def create_dekaron_mesh(dekaron_mesh_name, dekaron_mesh_vertices_co, dekaron_mesh_vertices_uv, dekaron_mesh_indices):
dekaron_mesh = bpy.data.add_mesh(dekaron_mesh_name)
dekaron_mesh.add_geometry(int(len(dekaron_mesh_vertices_co) / 3), 0, int(len(dekaron_mesh_indices) / 4))
dekaron_mesh.verts.foreach_set("co", dekaron_mesh_vertices_co)
dekaron_mesh.faces.foreach_set("verts_raw", dekaron_mesh_indices)
if dekaron_mesh.faces is not None and \
dekaron_mesh_vertices_uv is not None and \
len(dekaron_mesh_vertices_uv) > 0:
dekaron_mesh.add_uv_texture()
for i, dekaron_mesh_face in enumerate(dekaron_mesh.faces):
dekaron_mesh_texture_face = dekaron_mesh.uv_textures[0].data[i]
dekaron_mesh_texture_face_uvs = [dekaron_mesh_vertices_uv[j] for j in dekaron_mesh_face.verts]
dekaron_mesh_texture_face.uv1 = dekaron_mesh_texture_face_uvs[0]
dekaron_mesh_texture_face.uv2 = dekaron_mesh_texture_face_uvs[1]
dekaron_mesh_texture_face.uv3 = dekaron_mesh_texture_face_uvs[2]
dekaron_mesh.update()
dekaron_mesh_object = bpy.data.add_object("MESH", dekaron_mesh_name)
dekaron_mesh_object.data = dekaron_mesh
return dekaron_mesh_object
def parse_dekaron_mesh_file_mesh0(dekaron_mesh_file):
dekaron_mesh_file_mesh_name_length = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
dekaron_mesh_file_mesh_name = dekaron_mesh_file.read(dekaron_mesh_file_mesh_name_length)
dekaron_mesh_file_mesh_aabb = struct.unpack('<6f', dekaron_mesh_file.read(24))[0]
dekaron_mesh_file_mesh_vertex_count = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
dekaron_mesh_file_mesh_vertices_co = []
for i in range(dekaron_mesh_file_mesh_vertex_count):
dekaron_mesh_file_mesh_vertices_co.extend(list(struct.unpack('3f', dekaron_mesh_file.read(12))))
dekaron_mesh_file.seek(28, os.SEEK_CUR)
dekaron_mesh_file_mesh_index_count = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
dekaron_mesh_file_mesh_indices = []
for i in range(int(dekaron_mesh_file_mesh_index_count / 3)):
dekaron_mesh_file_mesh_indices.extend(list(struct.unpack('<3H', dekaron_mesh_file.read(6))))
dekaron_mesh_file_mesh_indices.append(0)
if len(dekaron_mesh_file_mesh_name) <= 0:
dekaron_mesh_file_mesh_name = os.path.splitext(os.path.basename(dekaron_mesh_file.name))[0]
dekaron_mesh_file_mesh_bone_count = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
for i in range(dekaron_mesh_file_mesh_bone_count):
dekaron_mesh_file_mesh_bone_name_length = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
dekaron_mesh_file_mesh_bone_name = dekaron_mesh_file.read(dekaron_mesh_file_mesh_bone_name_length)
return create_dekaron_mesh(dekaron_mesh_file_mesh_name, \
dekaron_mesh_file_mesh_vertices_co, \
None, \
dekaron_mesh_file_mesh_indices)
def parse_dekaron_mesh_file_mesh3(dekaron_mesh_file):
def is_face_degenerate(face_indices):
if face_indices[0] == face_indices[1]:
return True
elif face_indices[0] == face_indices[2]:
return True
elif face_indices[1] == face_indices[2]:
return True
return False
dekaron_mesh_file_mesh_aabb = struct.unpack('<6f', dekaron_mesh_file.read(24))[0]
dekaron_mesh_file_mesh_unknown_count0 = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
dekaron_mesh_file_mesh_indices = []
for i in range(dekaron_mesh_file_mesh_unknown_count0):
dekaron_mesh_file_mesh_unknown0, \
dekaron_mesh_file_mesh_unknown1, \
dekaron_mesh_file_mesh_unknown2, \
dekaron_mesh_file_mesh_unknown3, \
dekaron_mesh_file_mesh_index_count = struct.unpack('<IIIII', dekaron_mesh_file.read(20))
if dekaron_mesh_file_mesh_index_count > 0:
face_indices = list(struct.unpack('<2H', dekaron_mesh_file.read(4)))
for j in range(2, dekaron_mesh_file_mesh_index_count):
face_indices.append(struct.unpack('<H', dekaron_mesh_file.read(2))[0])
face_indices_copy = face_indices[:]
if not j % 2:
face_indices_copy.reverse()
if is_face_degenerate(face_indices_copy) is False:
dekaron_mesh_file_mesh_indices.extend(face_indices_copy)
dekaron_mesh_file_mesh_indices.append(0)
face_indices.pop(0)
dekaron_mesh_file_mesh_vertex_count = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
dekaron_mesh_file_mesh_vertices_co = []
dekaron_mesh_file_mesh_vertices_no = []
dekaron_mesh_file_mesh_vertices_uv1 = []
for i in range(dekaron_mesh_file_mesh_vertex_count):
dekaron_mesh_file_mesh_vertices_co.extend(list(struct.unpack('3f', dekaron_mesh_file.read(12))))
dekaron_mesh_file_mesh_vertices_no.extend(list(struct.unpack('3f', dekaron_mesh_file.read(12))))
dekaron_mesh_file_mesh_vertex_uv1 = list(struct.unpack('2f', dekaron_mesh_file.read(8)))
dekaron_mesh_file_mesh_vertex_uv1[1] = (1.0 - dekaron_mesh_file_mesh_vertex_uv1[1]) - 1.0
dekaron_mesh_file_mesh_vertices_uv1.append(dekaron_mesh_file_mesh_vertex_uv1)
dekaron_mesh_file.seek(24, os.SEEK_CUR)
dekaron_mesh_file_mesh_bone_count = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
for i in range(dekaron_mesh_file_mesh_bone_count):
dekaron_mesh_file_mesh_bone_name_length = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
dekaron_mesh_file_mesh_bone_name = dekaron_mesh_file.read(dekaron_mesh_file_mesh_bone_name_length)
dekaron_mesh_file.seek(4, os.SEEK_CUR)
return create_dekaron_mesh(os.path.splitext(os.path.basename(dekaron_mesh_file.name))[0], \
dekaron_mesh_file_mesh_vertices_co, \
dekaron_mesh_file_mesh_vertices_uv1, \
dekaron_mesh_file_mesh_indices)
def parse_dekaron_mesh_file_meshes(dekaron_mesh_file, dekaron_mesh_type):
dekaron_mesh_file_mesh_count = struct.unpack('<I', dekaron_mesh_file.read(4))[0]
dekaron_mesh_objects = []
for i in range(dekaron_mesh_file_mesh_count):
if dekaron_mesh_type == 0:
dekaron_mesh_objects.append(parse_dekaron_mesh_file_mesh0(dekaron_mesh_file))
elif dekaron_mesh_type == 3:
dekaron_mesh_objects.append(parse_dekaron_mesh_file_mesh3(dekaron_mesh_file))
return dekaron_mesh_objects
def parse_dekaron_mesh_file(dekaron_mesh_file):
dekaron_mesh_file_header_magic, \
dekaron_mesh_file_header_unknown0, \
dekaron_mesh_file_header_unknown1, \
dekaron_mesh_file_header_unknown2, \
dekaron_mesh_file_header_mesh_data_address0, \
dekaron_mesh_file_header_mesh_data_size0, \
dekaron_mesh_file_header_mesh_data_address1, \
dekaron_mesh_file_header_mesh_data_size1, \
dekaron_mesh_file_header_mesh_data_address2, \
dekaron_mesh_file_header_mesh_data_size2, \
dekaron_mesh_file_header_mesh_data_address3, \
dekaron_mesh_file_header_mesh_data_size3 = struct.unpack('<IIIIIIIIIIII', dekaron_mesh_file.read(48))
dekaron_mesh_file_header_work_path = dekaron_mesh_file.read(64)
if dekaron_mesh_file_header_magic != 0x20031117:
return
dekaron_mesh_objects = []
# Parse collision meshes
if dekaron_mesh_file_header_mesh_data_size0 >= 4:
dekaron_mesh_file.seek(dekaron_mesh_file_header_mesh_data_address0)
dekaron_mesh_objects.extend(parse_dekaron_mesh_file_meshes(dekaron_mesh_file, 0))
# Parse meshes
if dekaron_mesh_file_header_mesh_data_size3 >= 4:
dekaron_mesh_file.seek(dekaron_mesh_file_header_mesh_data_address3)
dekaron_mesh_objects.extend(parse_dekaron_mesh_file_meshes(dekaron_mesh_file, 3))
return dekaron_mesh_objects
def import_dekaron_mesh_file_from_path(dekaron_mesh_file_path, context):
# dekaron_mesh_scene = bpy.data.scenes.new()
#
# dekaron_mesh_scene.make_current()
#
with io.open(dekaron_mesh_file_path, mode='r+b') as dekaron_mesh_file:
dekaron_mesh_objects = parse_dekaron_mesh_file(dekaron_mesh_file)
for dekaron_mesh_object in dekaron_mesh_objects:
context.scene.objects.link(dekaron_mesh_object)
class ImportDekaronMeshFile(bpy.types.Operator):
'''Import Dekaron mesh'''
bl_idname = "import_scene.dekaron_mesh"
bl_label = 'Import Dekaron Mesh'
path = bpy.props.StringProperty(name="File Path", description="Dekaron mesh file path", maxlen= 1024, default= "")
def execute(self, context):
import_dekaron_mesh_file_from_path(self.properties.path, context)
return ('FINISHED',)
def invoke(self, context, event):
window_manager = context.manager
window_manager.add_fileselect(self)
return ('RUNNING_MODAL',)
bpy.ops.add(ImportDekaronMeshFile)
menu_function = lambda self, context: self.layout.operator(ImportDekaronMeshFile.bl_idname, text="Dekaron (.mesh)...")
menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_import, menu_function)
---------- Post added at 03:48 PM ---------- Previous post was at 03:46 PM ----------
Data Unpacker:
Usage:
- Open Command Prompt/Console/Terminal
- Type: C:\Python31\python.exe dekaron_unpacker.py --directory="<Dekaron_Directory>\data"
License:
You must be registered to see links
Source:
Copy and save as: dekaron_unpacker.py
Code:
# Copyright (c) 2009-2012 AJ
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import getopt
import mmap
import os
import struct
import sys
def dekaron_unpack_parse_header_file(pack_header_file, pack_directory_name):
pack_header_file.seek(400, os.SEEK_CUR)
pack_chunk_file_count = struct.unpack('<I', pack_header_file.read(4))[0]
for i in range(pack_chunk_file_count):
pack_chunk_file_name_length = struct.unpack('<I', pack_header_file.read(4))[0]
pack_chunk_file_name = pack_header_file.read(pack_chunk_file_name_length)
pack_chunk_file_name = os.path.join(pack_directory_name, pack_chunk_file_name)
with open(pack_chunk_file_name, 'r+b') as pack_chunk_file:
pack_chunk_file_memory_map = mmap.mmap(pack_chunk_file.fileno(), 0)
pack_chunk_file_directory_count = struct.unpack('<I', pack_header_file.read(4))[0]
for b in xrange(pack_chunk_file_directory_count):
pack_chunk_file_directroy_name_length = struct.unpack('<I', pack_header_file.read(4))[0]
pack_chunk_file_directroy_name = pack_header_file.read(pack_chunk_file_directroy_name_length)
pack_chunk_file_directroy_name = os.path.join(pack_directory_name, pack_chunk_file_directroy_name)
pack_chunk_file_size, \
pack_chunk_file_unknown0, \
pack_chunk_file_file_count, \
pack_chunk_file_unknown1 = struct.unpack('<4I', pack_header_file.read(16))
print("pack file: {0} ({1:X} bytes)".format(pack_chunk_file_name, pack_chunk_file_size))
for j in range(pack_chunk_file_file_count):
pack_chunk_file_file_name_length = struct.unpack('<I', pack_header_file.read(4))[0]
pack_chunk_file_file_name = pack_header_file.read(pack_chunk_file_file_name_length)
pack_chunk_file_file_name = pack_chunk_file_file_name.replace('/', os.sep)
pack_chunk_file_file_name = os.path.join(pack_directory_name, pack_chunk_file_file_name[6:])
pack_chunk_file_file_pointer, \
pack_chunk_file_file_unknown0, \
pack_chunk_file_file_size, \
pack_chunk_file_file_unknown2, \
pack_chunk_file_file_unknown3 = struct.unpack('<5I', pack_header_file.read(20))
pack_chunk_file_memory_map.seek(pack_chunk_file_file_pointer)
pack_chunk_file_file_directory = os.path.dirname(pack_chunk_file_file_name)
if os.path.exists(pack_chunk_file_file_directory) is False:
os.makedirs(pack_chunk_file_file_directory)
print("created directory structure: {0}".format(pack_chunk_file_file_directory))
with open(pack_chunk_file_file_name, 'w+b') as pack_chunk_file_file:
pack_chunk_file_file.write(pack_chunk_file_memory_map.read(pack_chunk_file_file_size))
print("unpacked file: {0} ({1:X} bytes)".format(pack_chunk_file_file_name, pack_chunk_file_file_size))
pack_chunk_file_memory_map.close()
def dekaron_unpack(pack_directory_name):
pack_header_file_name = os.path.join(pack_directory_name, 'pack.hdr')
if os.path.exists(pack_directory_name) is False:
return
with open(pack_header_file_name, 'r+b') as pack_header_file:
dekaron_unpack_parse_header_file(pack_header_file, pack_directory_name)
def main(argv):
pack_directory_name = None
if len(argv) == 0:
pack_directory_name = os.getcwd()
elif len(argv) == 1:
try:
options, arguments = getopt.getopt(argv, 'd', ['directory='])
except getopt.GetoptError:
sys.exit(2)
for option, argument in options:
if option in ('d', '--directory'):
pack_directory_name = argument
if pack_directory_name is None or \
os.path.exists(pack_directory_name) is False or \
os.path.isdir(pack_directory_name) is False:
sys.exit(2)
else:
dekaron_unpack(pack_directory_name)
if __name__ == "__main__":
main(sys.argv[1:])
Last edited: