Skip to content

Commit

Permalink
Merge pull request #75 from Robert-N7/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Robert-N7 authored Oct 20, 2021
2 parents 5dd9b98 + 629570f commit 74ee19a
Show file tree
Hide file tree
Showing 26 changed files with 311 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ tracks/

# Pycharm
__pycache*
.idea*
*.spec
*.pyc
*.gch
Expand Down
18 changes: 18 additions & 0 deletions .idea/abmatt.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/runConfigurations/cmdline.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/runConfigurations/pytest_in_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions abmatt/brres/mdl0/material/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ def __str__(self):
self.alphaLightControl)

def enable_vertex_color(self, enabled=True):
return self.colorLightControl.enable_vertex_color(enabled) or \
self.alphaLightControl.enable_vertex_color(enabled)
result = False
if self.colorLightControl.enable_vertex_color(enabled):
result = True
if self.alphaLightControl.enable_vertex_color(enabled):
result = True
return result

def is_vertex_color_enabled(self):
return self.colorLightControl.is_vertex_color_enabled() and \
Expand Down
2 changes: 1 addition & 1 deletion abmatt/build/config.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build_name = main # build output name
build_type = onedir # the type of build, (auto|onefile|onedir)
version = 1.2.0
version = 1.3.0
run_integration_tests = False
run_unit_tests = False
16 changes: 11 additions & 5 deletions abmatt/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def __init__(self, text=None, arg_list=None):
if not x:
raise ParsingException(self.txt, 'Not enough parameters')
self.set_key_val(x[0])
elif cmd == 'add' and len(x):
self.set_key_val(x[0])
elif cmd == 'add':
self.set_add(x)
elif len(x):
if cmd != 'info':
raise ParsingException(self.txt, "Unknown parameter(s) {}".format(x))
Expand Down Expand Up @@ -271,6 +271,12 @@ def set_convert(self, params):
raise ParsingException('Unsupported export format {}'.format(self.ext))
self.flags = flags

def set_add(self, params):
if len(params):
self.set_key_val(params[0])
if self.type == 'mdl0':
self.include = self.exclude = self.model = None

def set_key_val(self, keyval):
if ':' not in keyval:
raise ParsingException(self.txt, 'Requires key:value pair')
Expand Down Expand Up @@ -827,9 +833,9 @@ def run_convert(self):
brres = self.create_or_open(self.destination)
for file in files:
if not brres:
converter = klass(self.create_or_open(convert_file_ext(file, '.brres')), file, self.flags)
else:
converter = klass(brres, file, self.flags)
brres = self.create_or_open(convert_file_ext(file, '.brres'))
converter = klass(brres, file, self.flags,
include=self.include, exclude=self.exclude)
base_name = os.path.splitext(os.path.basename(converter.brres.name))[0]
model = self.model
if model and len(model) > len(base_name) and model.startswith(base_name + '-'):
Expand Down
29 changes: 20 additions & 9 deletions abmatt/converters/convert_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,21 @@ def _start_loading(self, model_name):
def _before_encoding(self):
if not self.geometries:
raise ConvertError('No geometries found to encode!')
self.removed_materials = {}
if self.patch_existing:
replace_names = [x.name for x in self.geometries]
for poly in [x for x in self.replacement_model.objects if x.name in replace_names]:
self.removed_materials[poly.material.name] = poly.material
self.replacement_model.remove_polygon(poly)
self.material_name_remap = material_name_remap = {}
self.encode_materials()
for x in self.geometries:
if x.material_name in material_name_remap:
x.material_name = material_name_remap[x.material_name]

if os.path.exists(self.json_file):
converter = MatsToJsonConverter(self.json_file)
converter.load_into(self.mdl0.materials)
converter.load_into(self.mdl0.materials, material_name_remap)
self.json_polygon_encoding = converter.polygons_by_name
else:
self.json_polygon_encoding = None
Expand Down Expand Up @@ -222,7 +229,9 @@ def __add_pat0_images(self):
def _encode_material(self, generic_mat):
m = None
if self.replacement_model:
m = self.replacement_model.get_material_by_name(generic_mat.name)
m = self.removed_materials.get(generic_mat.name)
if m is None:
m = self.replacement_model.get_material_by_name(generic_mat.name)
if m is None:
if self.material_library:
m = self.material_library.get(generic_mat)
Expand All @@ -234,6 +243,8 @@ def _encode_material(self, generic_mat):
mat.paste(m)
else:
mat = generic_mat.encode(self.mdl0)
if mat.name != generic_mat.name:
self.material_name_remap[generic_mat.name] = mat.name
for x in mat.layers:
self.image_library.add(x.name)
return mat
Expand Down Expand Up @@ -317,13 +328,13 @@ def _encode_geometry(self, geometry):
has_uv_mtx = json_data.get('has_uv_matrix')
priority = json_data.get('draw_priority')
elif self.replacement_model:
replace_geometry = [x for x in self.replacement_model.objects if x.name == geometry.name]
if replace_geometry:
replace_geometry = replace_geometry[0]
has_uv_mtx = [replace_geometry.has_uv_matrix(i) for i in range(8)]
priority = replace_geometry.priority
if self.patch_existing:
self.mdl0.remove_polygon(replace_geometry)
for x in self.replacement_model.objects:
if x.name == geometry.name:
has_uv_mtx = [x.has_uv_matrix(i) for i in range(8)]
priority = x.priority
if self.patch_existing:
self.mdl0.remove_polygon(x)
break
encoder = self.encoder.get_encoder(geometry) if self.encoder else None
return geometry.encode(self.mdl0, encoder=encoder,
priority=priority,
Expand Down
6 changes: 5 additions & 1 deletion abmatt/converters/convert_mats_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def load(self):
for x in self.materials_by_name]
return materials

def load_into(self, materials):
def load_into(self, materials, material_mapper=None):
""" Loads json data into materials, if the material name isn't found it is ignored
:param materials: the materials to load data into
:return: materials
Expand All @@ -49,6 +49,10 @@ def load_into(self, materials):
self.materials_by_name = json.loads(f.read())
for x in materials:
data = self.materials_by_name.get(x.name)
if not data and material_mapper:
new_name = material_mapper.get(x.name)
if new_name:
data = self.materials_by_name.get(new_name)
if data:
self.__load_material(x, data)

Expand Down
2 changes: 1 addition & 1 deletion abmatt/converters/dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def __initialize_libraries(self, initial_name):
def __initialize_assets(self, root):
asset = XMLNode('asset', parent=root)
contributor = XMLNode('contributor', parent=asset)
authoring_tool = XMLNode('authoring_tool', 'ABMATT COLLADA exporter v1.2.0', parent=contributor)
authoring_tool = XMLNode('authoring_tool', 'ABMATT COLLADA exporter v1.3.0', parent=contributor)
time_stamp = datetime.now()
created = XMLNode('created', str(time_stamp), parent=asset)
modified = XMLNode('modified', str(time_stamp), parent=asset)
Expand Down
Loading

0 comments on commit 74ee19a

Please sign in to comment.