diff --git a/README.md b/README.md index 7cb1561..7ce5e04 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,13 @@ ## `Python 3D Models Converter` +**Version**: 0.4.5 + +### **Tools:** - scw2dae - scw2obj +- obj2scw - obj2dae +- dae2scw - dae2obj - ### **THIS IS NOT RELEASE VERSION!** diff --git a/models_converter/chunks/GEOM.py b/models_converter/chunks/GEOM.py index 62e1e04..b891dd7 100644 --- a/models_converter/chunks/GEOM.py +++ b/models_converter/chunks/GEOM.py @@ -19,7 +19,7 @@ def __init__(self, initial_bytes: bytes, header: dict): name = self.readString() group = self.readString() - if header['version'] == 1: + if header['version'] < 2: matrix = [] for x in range(4): temp_list = [] diff --git a/models_converter/chunks/HEAD.py b/models_converter/chunks/HEAD.py index c5a93a7..ac3b6db 100644 --- a/models_converter/chunks/HEAD.py +++ b/models_converter/chunks/HEAD.py @@ -15,7 +15,8 @@ def __init__(self, initial_bytes: bytes): self.readUShort() self.readUShort() materials_file = self.readString() - self.readUByte() + if version == 2: + self.readUByte() self.readed['version'] = version self.readed['frame_rate'] = frame_rate diff --git a/models_converter/formats/dae_read.py b/models_converter/formats/dae_read.py index 0778a4c..6346731 100644 --- a/models_converter/formats/dae_read.py +++ b/models_converter/formats/dae_read.py @@ -126,14 +126,12 @@ def __init__(self, file_data): self.geometry_info = {} root = fromstring(file_data) - # tree = parse(file_path) - # root = tree.getroot() self.namespaces = { 'collada': 'http://www.collada.org/2005/11/COLLADASchema' } - # Libraries + # self.library_materials = root.find('./collada:library_materials', self.namespaces) self.library_effects = root.find('./collada:library_effects', self.namespaces) @@ -141,7 +139,7 @@ def __init__(self, file_data): self.library_controllers = root.find('./collada:library_controllers', self.namespaces) library_scenes = root.find('./collada:library_visual_scenes', self.namespaces) - # Libraries + # for material in self.library_materials: material_name = material.attrib['id'] @@ -215,8 +213,8 @@ def __init__(self, file_data): def parse_nodes(self): nodes = self.parsed['nodes'] - for node in nodes: - node: dict = node # this line for fix "Expected type" + for node_index in range(len(nodes)): + node = nodes[node_index] if node['has_target']: controller = None geometry = None @@ -232,6 +230,13 @@ def parse_nodes(self): geometry = self.library_geometries \ .find(f'collada:geometry[@id="{node["target"]}"]', self.namespaces) + if node['target'].endswith('-cont'): + node['target'] = node['target'][:-5] + if node['target'].endswith('-geom'): + node['target'] = node['target'][:-5] + + self.parsed['nodes'][node_index] = node + if geometry is not None: self.geometry_info = {'name': '', 'group': node['parent'], diff --git a/models_converter/formats/dae_write.py b/models_converter/formats/dae_write.py index de7e69a..7c84a4f 100644 --- a/models_converter/formats/dae_write.py +++ b/models_converter/formats/dae_write.py @@ -87,9 +87,11 @@ def __init__(self, data: dict): # for material_data in data['materials']: material_name = material_data['name'] - effect_name = f'{material_name}-effect' - material = SubElement(library_materials, 'material', id=material_name) + SubElement(library_materials, 'material', id=material_name) + # effect_name = f'{material_name}-effect' + # + # material = SubElement(library_materials, 'material', id=material_name) # SubElement(material, 'instance_effect', url=f'#{effect_name}') # # effect = SubElement(library_effects, 'effect', id=effect_name) @@ -151,9 +153,12 @@ def __init__(self, data: dict): vertex = vertex_data['vertex'] stride = len(vertex[0]) + if vertex_type == 'VERTEX': + vertex_type = 'POSITION' + source_name = f'{geometry_name}-{vertex_type.lower()}' - if vertex_type in ['VERTEX', 'POSITION', 'NORMAL']: + if vertex_type in ['POSITION', 'NORMAL']: params.append({ 'name': 'X', 'type': 'float' @@ -201,20 +206,18 @@ def __init__(self, data: dict): vertex_index = geometry_data['vertices'].index(vertex) vertex_type = vertex['type'] - if vertex_type == 'POSITION': - vertex_type = 'VERTEX' source_id = f'{geometry_name}-{vertex_type.lower()}' - if vertex_type == 'VERTEX': + if vertex_type == 'POSITION': source_id = f'{geometry_name}-vertices' dae.write_input(triangles, vertex_type, source_id, vertex_index) polygons = SubElement(triangles, 'p') formatted_polygons_data = [] - for item in polygons_data: - for sub_item in item: - for value in sub_item: - formatted_polygons_data.append(str(value)) + for polygon in polygons_data: + for point in polygon: + for vertex in point: + formatted_polygons_data.append(str(vertex)) polygons.text = ' '.join(formatted_polygons_data) # diff --git a/setup.py b/setup.py index d29a177..475d285 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name='3d-converter', - version='0.4.2', + version='0.4.5', author='Vorono4ka', author_email='crowo4ka@gmail.com', description='Python 3D Models Converter', @@ -22,4 +22,3 @@ ], python_requires='>=3.6', ) -# \ No newline at end of file