Skip to content

Commit

Permalink
0.4.5 Update:
Browse files Browse the repository at this point in the history
- GEOM Reader fix for old versions
- HEAD Reader fix for old versions
- COLLADA Reader small change
  • Loading branch information
danila-schelkov committed Jul 28, 2020
1 parent 4188356 commit e163573
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
## `Python 3D Models Converter`

**Version**: 0.4.5

### **Tools:**
- scw2dae
- scw2obj
- obj2scw
- obj2dae
- dae2scw
- dae2obj


### **THIS IS NOT RELEASE VERSION!**
2 changes: 1 addition & 1 deletion models_converter/chunks/GEOM.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
3 changes: 2 additions & 1 deletion models_converter/chunks/HEAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions models_converter/formats/dae_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,20 @@ 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
# <Libraries>
self.library_materials = root.find('./collada:library_materials', self.namespaces)
self.library_effects = root.find('./collada:library_effects', self.namespaces)

self.library_geometries = root.find('./collada:library_geometries', self.namespaces)
self.library_controllers = root.find('./collada:library_controllers', self.namespaces)

library_scenes = root.find('./collada:library_visual_scenes', self.namespaces)
# Libraries
# </Libraries>

for material in self.library_materials:
material_name = material.attrib['id']
Expand Down Expand Up @@ -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
Expand All @@ -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'],
Expand Down
23 changes: 13 additions & 10 deletions models_converter/formats/dae_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ def __init__(self, data: dict):
# <Materials>
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)
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
# </Polygons>
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name='3d-converter',
version='0.4.2',
version='0.4.5',
author='Vorono4ka',
author_email='[email protected]',
description='Python 3D Models Converter',
Expand All @@ -22,4 +22,3 @@
],
python_requires='>=3.6',
)
#

0 comments on commit e163573

Please sign in to comment.