Skip to content

Commit

Permalink
Added support for exporting multiple UV layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbasnett committed Dec 27, 2021
1 parent 8edfac9 commit 7ebeb0d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
This is a Blender addon allowing you to export static meshes to the now-defunct ASE (ASCII Scene Export) format still in use in legacy programs like Unreal Tournament 2004.

Check out [this video](https://www.youtube.com/watch?v=gpmBxCGHQjU) on how to install and use the addon.

Resources:
* https://wiki.beyondunreal.com/Legacy:ASE_File_Format
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'name': 'ASCII Scene Export',
'description': 'Export ASE (ASCII Scene Export) files',
'author': 'Colin Basnett (Darklight Games)',
'version': (1, 0, 3),
'version': (1, 1, 0),
'blender': (2, 90, 0),
'location': 'File > Import-Export',
'warning': 'This add-on is under development.',
Expand Down
7 changes: 6 additions & 1 deletion src/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ def is_collision_name(name):
return name.startswith('MCDCX_')


class ASEUVLayer(object):
def __init__(self):
self.texture_vertices = []


class ASEGeometryObject(object):
def __init__(self):
self.name = ''
self.vertices = []
self.texture_vertices = []
self.uv_layers = []
self.faces = []
self.texture_vertex_faces = []
self.face_normals = []
Expand Down
16 changes: 9 additions & 7 deletions src/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ def build(self, context, options: ASEBuilderOptions):
face_normal.vertex_normals.append(vertex_normal)
geometry_object.face_normals.append(face_normal)

uv_layer = mesh_data.uv_layers.active.data

# Texture Coordinates
if not geometry_object.is_collision:
for loop_index, loop in enumerate(mesh_data.loops):
u, v = uv_layer[loop_index].uv
geometry_object.texture_vertices.append((u, v, 0.0))
# Texture Coordinates
for i, uv_layer_data in enumerate([x.data for x in mesh_data.uv_layers]):
if i >= len(geometry_object.uv_layers):
geometry_object.uv_layers.append(ASEUVLayer())
uv_layer = geometry_object.uv_layers[i]
for loop_index, loop in enumerate(mesh_data.loops):
u, v = uv_layer_data[loop_index].uv
uv_layer.texture_vertices.append((u, v, 0.0))

# Texture Faces
if not geometry_object.is_collision:
Expand All @@ -107,7 +109,7 @@ def build(self, context, options: ASEBuilderOptions):
))

# Update data offsets for next iteration
geometry_object.texture_vertex_offset = len(geometry_object.texture_vertices)
geometry_object.texture_vertex_offset = len(mesh_data.loops)
geometry_object.vertex_offset = len(geometry_object.vertices)

if len(ase.geometry_objects) == 0:
Expand Down
26 changes: 14 additions & 12 deletions src/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,23 @@ def build_ase_tree(ase) -> ASEFile:
face_node.push_sub_command('MESH_MTLID').push_datum(face.material_index)

# Texture Coordinates
if len(geometry_object.texture_vertices) > 0:
mesh_node.push_child('MESH_NUMTVERTEX').push_datum(len(geometry_object.texture_vertices))
tvertlist_node = mesh_node.push_child('MESH_TVERTLIST')
for tvert_index, tvert in enumerate(geometry_object.texture_vertices):
for i, uv_layer in enumerate(geometry_object.uv_layers):
parent_node = mesh_node if i == 0 else mesh_node.push_child('MESH_MAPPINGCHANNEL')
if i > 0:
parent_node.push_datum(i + 1)
parent_node.push_child('MESH_NUMTVERTEX').push_datum(len(uv_layer.texture_vertices))
tvertlist_node = parent_node.push_child('MESH_TVERTLIST')
for tvert_index, tvert in enumerate(uv_layer.texture_vertices):
tvert_node = tvertlist_node.push_child('MESH_TVERT')
tvert_node.push_datum(tvert_index)
tvert_node.push_data(list(tvert))

# Texture Faces
if len(geometry_object.texture_vertex_faces) > 0:
mesh_node.push_child('MESH_NUMTVFACES').push_datum(len(geometry_object.texture_vertex_faces))
texture_faces_node = mesh_node.push_child('MESH_TFACELIST')
for texture_face_index, texture_face in enumerate(geometry_object.texture_vertex_faces):
texture_face_node = texture_faces_node.push_child('MESH_TFACE')
texture_face_node.push_data([texture_face_index] + list(texture_face))
# Texture Faces
if len(geometry_object.texture_vertex_faces) > 0:
parent_node.push_child('MESH_NUMTVFACES').push_datum(len(geometry_object.texture_vertex_faces))
texture_faces_node = parent_node.push_child('MESH_TFACELIST')
for texture_face_index, texture_face in enumerate(geometry_object.texture_vertex_faces):
texture_face_node = texture_faces_node.push_child('MESH_TFACE')
texture_face_node.push_data([texture_face_index] + list(texture_face))

# Normals
if len(geometry_object.face_normals) > 0:
Expand Down

0 comments on commit 7ebeb0d

Please sign in to comment.