Now applying the export space transform
* Now adding a dummy material when none is provided.
This commit is contained in:
@@ -55,5 +55,5 @@ class ASEGeometryObject(object):
|
|||||||
|
|
||||||
class ASE(object):
|
class ASE(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.materials: List[Optional[Material]] = []
|
self.materials: List[str] = []
|
||||||
self.geometry_objects = []
|
self.geometry_objects = []
|
||||||
|
|||||||
@@ -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:
|
def build_ase(context: Context, options: ASEBuildOptions, dfs_objects: Iterable[DfsObject]) -> ASE:
|
||||||
ase = 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 = list(dfs_objects)
|
||||||
dfs_objects_processed = 0
|
dfs_objects_processed = 0
|
||||||
@@ -112,7 +117,6 @@ def build_ase(context: Context, options: ASEBuildOptions, dfs_objects: Iterable[
|
|||||||
max_uv_layers = max(max_uv_layers, len(mesh_data.uv_layers))
|
max_uv_layers = max(max_uv_layers, len(mesh_data.uv_layers))
|
||||||
|
|
||||||
geometry_object.uv_layers = [ASEUVLayer() for _ in range(max_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:
|
for dfs_object in geometry_object_info.dfs_objects:
|
||||||
obj = dfs_object.obj
|
obj = dfs_object.obj
|
||||||
@@ -136,7 +140,10 @@ def build_ase(context: Context, options: ASEBuildOptions, dfs_objects: Iterable[
|
|||||||
mesh_object = bpy.data.objects.new('', mesh_data)
|
mesh_object = bpy.data.objects.new('', mesh_data)
|
||||||
mesh_object.matrix_world = matrix_world
|
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):
|
for vertex_index, vertex in enumerate(mesh_data.vertices):
|
||||||
vertex = vertex_transform @ vertex.co
|
vertex = vertex_transform @ vertex.co
|
||||||
@@ -148,7 +155,7 @@ def build_ase(context: Context, options: ASEBuildOptions, dfs_objects: Iterable[
|
|||||||
for mesh_material_index, material in enumerate(obj.data.materials):
|
for mesh_material_index, material in enumerate(obj.data.materials):
|
||||||
if material is None:
|
if material is None:
|
||||||
raise ASEBuildError(f'Material slot {mesh_material_index + 1} for mesh \'{obj.name}\' cannot be empty')
|
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 len(material_indices) == 0:
|
||||||
# If no materials are assigned to the mesh, just have a single empty material.
|
# If no materials are assigned to the mesh, just have a single empty material.
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class ASEWriter(object):
|
|||||||
for material_index, material in enumerate(ase.materials):
|
for material_index, material in enumerate(ase.materials):
|
||||||
submaterial_node = material_node.push_child('SUBMATERIAL')
|
submaterial_node = material_node.push_child('SUBMATERIAL')
|
||||||
submaterial_node.push_datum(material_index)
|
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 = submaterial_node.push_child('MAP_DIFFUSE')
|
||||||
diffuse_node.push_child('MAP_NAME').push_datum('default')
|
diffuse_node.push_child('MAP_NAME').push_datum('default')
|
||||||
diffuse_node.push_child('UVW_U_OFFSET').push_datum(0.0)
|
diffuse_node.push_child('UVW_U_OFFSET').push_datum(0.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user