Skip to content

Commit

Permalink
Now applying the export space transform
Browse files Browse the repository at this point in the history
* Now adding a dummy material when none is provided.
  • Loading branch information
cmbasnett committed Dec 28, 2024
1 parent 0c0c5fc commit 24adafe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion io_scene_ase/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ def is_collision(self):

class ASE(object):
def __init__(self):
self.materials: List[Optional[Material]] = []
self.materials: List[str] = []
self.geometry_objects = []
15 changes: 11 additions & 4 deletions io_scene_ase/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ def get_coordinate_system_transform(forward_axis: str = 'X', up_axis: str = 'Z')

def build_ase(context: Context, options: ASEBuildOptions, dfs_objects: Iterable[DfsObject]) -> ASE:
ase = ASE()
ase.materials = options.materials
ase.materials = [x.name for x in options.materials]

# If no materials are assigned to the object, add an empty material.
# This is necessary for the ASE format to be compatible with the UT2K4 importer.
if len(ase.materials) == 0:
ase.materials.append('')

dfs_objects = list(dfs_objects)
dfs_objects_processed = 0
Expand Down Expand Up @@ -112,7 +117,6 @@ def __init__(self, name: str):
max_uv_layers = max(max_uv_layers, len(mesh_data.uv_layers))

geometry_object.uv_layers = [ASEUVLayer() for _ in range(max_uv_layers)]
print('max_uv_layers', max_uv_layers)

for dfs_object in geometry_object_info.dfs_objects:
obj = dfs_object.obj
Expand All @@ -136,7 +140,10 @@ def __init__(self, name: str):
mesh_object = bpy.data.objects.new('', mesh_data)
mesh_object.matrix_world = matrix_world

vertex_transform = Matrix.Rotation(math.pi, 4, 'Z') @ Matrix.Scale(options.scale, 4) @ matrix_world
vertex_transform = (Matrix.Rotation(math.pi, 4, 'Z') @
Matrix.Scale(options.scale, 4) @
options.transform @
matrix_world)

for vertex_index, vertex in enumerate(mesh_data.vertices):
vertex = vertex_transform @ vertex.co
Expand All @@ -148,7 +155,7 @@ def __init__(self, name: str):
for mesh_material_index, material in enumerate(obj.data.materials):
if material is None:
raise ASEBuildError(f'Material slot {mesh_material_index + 1} for mesh \'{obj.name}\' cannot be empty')
material_indices.append(ase.materials.index(material))
material_indices.append(ase.materials.index(material.name))

if len(material_indices) == 0:
# If no materials are assigned to the mesh, just have a single empty material.
Expand Down
2 changes: 1 addition & 1 deletion io_scene_ase/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def build_ase_tree(ase: ASE) -> ASEFile:
for material_index, material in enumerate(ase.materials):
submaterial_node = material_node.push_child('SUBMATERIAL')
submaterial_node.push_datum(material_index)
submaterial_node.push_child('MATERIAL_NAME').push_datum(material.name)
submaterial_node.push_child('MATERIAL_NAME').push_datum(material)
diffuse_node = submaterial_node.push_child('MAP_DIFFUSE')
diffuse_node.push_child('MAP_NAME').push_datum('default')
diffuse_node.push_child('UVW_U_OFFSET').push_datum(0.0)
Expand Down

0 comments on commit 24adafe

Please sign in to comment.