Skip to content

Commit

Permalink
Added some spaces to the boxing of numbers in the save strings
Browse files Browse the repository at this point in the history
Fixed searching for MinExtent not comparing with found MinExtent
  • Loading branch information
tw1lac committed Jan 7, 2024
1 parent 8ff7609 commit fd10e5b
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions export_mdl/classes/War3AnimationAction.py
Expand Up @@ -15,15 +15,15 @@ def __init__(self, name, start, end, non_looping=False, movement_speed=270, rari

def save_sequences(self, fw: TextIO.write, global_extents_min: List[float], global_extents_max: List[float]):
fw("\tAnim \"%s\" {\n" % self.name)
fw("\t\tInterval {%d, %d},\n" % (self.start, self.end))
fw("\t\tInterval { %d, %d },\n" % (self.start, self.end))
if self.non_looping:
fw("\t\tNonLooping,\n")
if self.rarity > 0:
fw("\t\tRarity %d,\n" % self.rarity)
if 'walk' in self.name.lower():
fw("\t\tMoveSpeed %d,\n" % self.movement_speed)

fw("\t\tMinimumExtent {%s, %s, %s},\n" % tuple(map(float2str, global_extents_min)))
fw("\t\tMaximumExtent {%s, %s, %s},\n" % tuple(map(float2str, global_extents_max)))
fw("\t\tMinimumExtent { %s, %s, %s },\n" % tuple(map(float2str, global_extents_min)))
fw("\t\tMaximumExtent { %s, %s, %s },\n" % tuple(map(float2str, global_extents_max)))
fw("\t\tBoundsRadius %s,\n" % float2str(calc_bounds_radius(global_extents_min, global_extents_max)))
fw("\t}\n")
24 changes: 12 additions & 12 deletions export_mdl/classes/War3Geoset.py
Expand Up @@ -39,18 +39,18 @@ def write_geoset(self, fw: TextIO.write, material_names,
# Vertices
fw("\tVertices %d {\n" % len(self.vertices))
for vertex in self.vertices:
fw("\t\t{%s, %s, %s},\n" % tuple(map(float2str, vertex.pos)))
fw("\t\t{ %s, %s, %s },\n" % tuple(map(float2str, vertex.pos)))
fw("\t}\n")
# Normals
fw("\tNormals %d {\n" % len(self.vertices))
for vertex in self.vertices:
fw("\t\t{%s, %s, %s},\n" % tuple(map(float2str, vertex.normal)))
fw("\t\t{ %s, %s, %s },\n" % tuple(map(float2str, vertex.normal)))
fw("\t}\n")

# TVertices
fw("\tTVertices %d {\n" % len(self.vertices))
for vertex in self.vertices:
fw("\t\t{%s, %s},\n" % tuple(map(float2str, vertex.uv)))
fw("\t\t{ %s, %s },\n" % tuple(map(float2str, vertex.uv)))
fw("\t}\n")

# VertexGroups
Expand All @@ -77,7 +77,7 @@ def write_geoset(self, fw: TextIO.write, material_names,
fw("\tTangents %d {\n" % len(self.vertices))
for vertex in self.vertices:
tangents = tuple(vertex.tangent)
fw("\t\t{%s, %s, %s, %s},\n" % tuple(tangents))
fw("\t\t{ %s, %s, %s, %s },\n" % tuple(tangents))
fw("\t}\n")
# SkinWeights
fw("\tSkinWeights %d {\n" % len(self.vertices))
Expand All @@ -93,40 +93,40 @@ def write_geoset(self, fw: TextIO.write, material_names,
fw("\tFaces %d %d {\n" % (1, len(self.triangles) * 3))

fw("\t\tTriangles {\n")
fw("\t\t\t{")
fw("\t\t\t{ ")

all_triangles = []
for triangle in self.triangles:
for index in triangle:
all_triangles.append(str(index))
fw(", ".join(all_triangles))
fw("},\n")
fw(" },\n")
fw("\t\t}\n")
fw("\t}\n")

if use_skinweights:
fw("\tGroups %d %d {\n" % (len(self.skin_matrices), sum(len(mtrx) for mtrx in self.skin_matrices)))
i = 0
for matrix in self.skin_matrices:
fw("\t\tMatrices {%s},\n" % ','.join(str(i) for _ in matrix))
fw("\t\tMatrices { %s },\n" % ','.join(str(i) for _ in matrix))
i = i+1
fw("\t}\n")
else:
fw("\tGroups %d %d {\n" % (len(self.matrices), sum(len(mtrx) for mtrx in self.matrices)))
for matrix in self.matrices:
fw("\t\tMatrices {%s},\n" % ','.join(str(object_indices[g]) for g in matrix))
fw("\t\tMatrices { %s },\n" % ','.join(str(object_indices[g]) for g in matrix))
fw("\t}\n")

fw("\tMinimumExtent {%s, %s, %s},\n" % tuple(map(float2str, self.min_extent)))
fw("\tMaximumExtent {%s, %s, %s},\n" % tuple(map(float2str, self.max_extent)))
fw("\tMinimumExtent { %s, %s, %s },\n" % tuple(map(float2str, self.min_extent)))
fw("\tMaximumExtent { %s, %s, %s },\n" % tuple(map(float2str, self.max_extent)))
fw("\tBoundsRadius %s,\n" % float2str(calc_bounds_radius(self.min_extent, self.max_extent)))

for sequence in sequences:
fw("\tAnim {\n")

# As of right now, we just use the self bounds.
fw("\t\tMinimumExtent {%s, %s, %s},\n" % tuple(map(float2str, self.min_extent)))
fw("\t\tMaximumExtent {%s, %s, %s},\n" % tuple(map(float2str, self.max_extent)))
fw("\t\tMinimumExtent { %s, %s, %s },\n" % tuple(map(float2str, self.min_extent)))
fw("\t\tMaximumExtent { %s, %s, %s },\n" % tuple(map(float2str, self.max_extent)))
fw("\t\tBoundsRadius %s,\n" % float2str(calc_bounds_radius(self.min_extent, self.max_extent)))

fw("\t}\n")
Expand Down
2 changes: 1 addition & 1 deletion export_mdl/classes/War3GeosetAnim.py
Expand Up @@ -63,7 +63,7 @@ def write_geo_anim(self, fw: TextIO.write, geoset_id: int, global_seqs: Set[int]
# "Color", fw, global_seqs, "\t")

elif self.color is not None:
fw("\tstatic Color {%s, %s, %s},\n" % tuple(map(float2str, reversed(self.color[:3]))))
fw("\tstatic Color { %s, %s, %s },\n" % tuple(map(float2str, reversed(self.color[:3]))))

fw("\tGeosetId %d,\n" % geoset_id)

Expand Down
18 changes: 9 additions & 9 deletions export_mdl/classes/War3ParticleSystem.py
Expand Up @@ -177,23 +177,23 @@ def write_particle(self, fw: TextIO.write,
fw("\tTailLength %s,\n" % float2str(rnd(self.emitter.tail_length)))
fw("\tTime %s,\n" % float2str(rnd(self.emitter.time)))
fw("\tSegmentColor {\n")
fw("\t\tColor {%s, %s, %s},\n" % tuple(map(float2str, reversed(self.emitter.start_color))))
fw("\t\tColor {%s, %s, %s},\n" % tuple(map(float2str, reversed(self.emitter.mid_color))))
fw("\t\tColor {%s, %s, %s},\n" % tuple(map(float2str, reversed(self.emitter.end_color))))
fw("\t\tColor { %s, %s, %s },\n" % tuple(map(float2str, reversed(self.emitter.start_color))))
fw("\t\tColor { %s, %s, %s },\n" % tuple(map(float2str, reversed(self.emitter.mid_color))))
fw("\t\tColor { %s, %s, %s },\n" % tuple(map(float2str, reversed(self.emitter.end_color))))
fw("\t},\n")

alpha = (self.emitter.start_alpha, self.emitter.mid_alpha, self.emitter.end_alpha)
fw("\tAlpha {%s, %s, %s},\n" % tuple(map(float2str, alpha)))
fw("\tAlpha { %s, %s, %s },\n" % tuple(map(float2str, alpha)))

particle_scales = (self.emitter.start_scale, self.emitter.mid_scale, self.emitter.end_scale)

fw("\tParticleScaling {%s, %s, %s},\n" % tuple(map(float2str, particle_scales)))
fw("\tLifeSpanUVAnim {%d, %d, %d},\n" % (
fw("\tParticleScaling { %s, %s, %s },\n" % tuple(map(float2str, particle_scales)))
fw("\tLifeSpanUVAnim { %d, %d, %d },\n" % (
self.emitter.head_life_start, self.emitter.head_life_end, self.emitter.head_life_repeat))
fw("\tDecayUVAnim {%d, %d, %d},\n" % (
fw("\tDecayUVAnim { %d, %d, %d },\n" % (
self.emitter.head_decay_start, self.emitter.head_decay_end, self.emitter.head_decay_repeat))
fw("\tTailUVAnim {%d, %d, %d},\n" % (self.emitter.tail_life_start, self.emitter.tail_life_end, self.emitter.tail_life_repeat))
fw("\tTailDecayUVAnim {%d, %d, %d},\n" % (
fw("\tTailUVAnim { %d, %d, %d },\n" % (self.emitter.tail_life_start, self.emitter.tail_life_end, self.emitter.tail_life_repeat))
fw("\tTailDecayUVAnim { %d, %d, %d },\n" % (
self.emitter.tail_decay_start, self.emitter.tail_decay_end, self.emitter.tail_decay_repeat))
fw("\tTextureID %d,\n" % textures.index(self.emitter.texture_path))

Expand Down
2 changes: 1 addition & 1 deletion export_mdl/classes/War3RibbonEmitter.py
Expand Up @@ -105,7 +105,7 @@ def write_ribbon(self, fw: TextIO.write,
self.write_animated(fw, global_seqs, "Color", self.ribbon_color_anim)
# write_anim_vec(self.ribbon_color_anim, 'Color', 'ribbon_color', fw, global_seqs, Matrix(), Matrix(), "\t", (2, 1, 0))
else:
fw("\tstatic Color {%s, %s, %s},\n" % tuple(map(float2str, reversed(emitter.ribbon_color))))
fw("\tstatic Color { %s, %s, %s },\n" % tuple(map(float2str, reversed(emitter.ribbon_color))))

fw("\tstatic TextureSlot %d,\n" % textures.index(emitter.texture_path))

Expand Down
4 changes: 2 additions & 2 deletions export_mdl/export_mdl/save_cameras.py
Expand Up @@ -11,7 +11,7 @@ def save_cameras(fw: TextIO.write, model: War3Model, settings):
fw("Camera \"%s\" {\n" % camera.name)
position = settings.global_matrix @ Vector(camera.location)

fw("\tPosition {%s, %s, %s},\n" % tuple(map(float2str, position)))
fw("\tPosition { %s, %s, %s },\n" % tuple(map(float2str, position)))
fw("\tFieldOfView %f,\n" % camera.data.angle)
fw("\tFarClip %f,\n" % (camera.data.clip_end * 10))
fw("\tNearClip %f,\n" % (camera.data.clip_start * 10))
Expand All @@ -21,6 +21,6 @@ def save_cameras(fw: TextIO.write, model: War3Model, settings):
target = position + matrix.to_quaternion() @ Vector(
(0.0, 0.0, -target_loc)) # Target is just a point in front of the camera

fw("\tTarget {\n\t\tPosition {%s, %s, %s},\n" % tuple(map(float2str, target)))
fw("\tTarget {\n\t\tPosition { %s, %s, %s },\n" % tuple(map(float2str, target)))
fw("\t}\n")
fw("}\n")
2 changes: 1 addition & 1 deletion export_mdl/export_mdl/save_collision_shape.py
Expand Up @@ -17,7 +17,7 @@ def save_collision_shape(fw: TextIO.write, model: War3Model):

fw("\tVertices %d {\n" % len(collider.verts))
for vert in collider.verts:
fw("\t\t{%s, %s, %s},\n" % tuple(float2str(rnd(x)) for x in list(vert)))
fw("\t\t{ %s, %s, %s },\n" % tuple(float2str(rnd(x)) for x in list(vert)))
fw("\t}\n")
if collider.type == 'Sphere':
fw("\tBoundsRadius %s,\n" % float2str(rnd(collider.radius)))
Expand Down
4 changes: 2 additions & 2 deletions export_mdl/export_mdl/save_lights.py
Expand Up @@ -34,7 +34,7 @@ def save_lights(fw: TextIO.write, model: War3Model):
if light.color_anim is not None:
write_animated(fw, global_seqs, "Color", light.color_anim)
else:
fw("\tstatic Color {%s, %s, %s},\n" % tuple(map(float2str, reversed(light.color[:3]))))
fw("\tstatic Color { %s, %s, %s },\n" % tuple(map(float2str, reversed(light.color[:3]))))

if light.intensity_anim is not None:
write_animated(fw, global_seqs, "Intensity", light.intensity_anim)
Expand All @@ -49,7 +49,7 @@ def save_lights(fw: TextIO.write, model: War3Model):
if light.amb_color_anim is not None:
write_animated(fw, global_seqs, "AmbColor", light.amb_color_anim)
else:
fw("\tstatic AmbColor {%s, %s, %s},\n" % tuple(map(float2str, reversed(light.amb_color[:3]))))
fw("\tstatic AmbColor { %s, %s, %s },\n" % tuple(map(float2str, reversed(light.amb_color[:3]))))

visibility = light.visibility
if visibility is not None:
Expand Down
4 changes: 2 additions & 2 deletions export_mdl/export_mdl/save_model_header.py
Expand Up @@ -28,7 +28,7 @@ def save_model_header(fw: TextIO.write, model: War3Model):
fw("\tNumHelpers %d,\n" % len(model.helpers))

fw("\tBlendTime %d,\n" % 150)
fw("\tMinimumExtent {%s, %s, %s},\n" % tuple(map(float2str, model.global_extents_min)))
fw("\tMaximumExtent {%s, %s, %s},\n" % tuple(map(float2str, model.global_extents_max)))
fw("\tMinimumExtent { %s, %s, %s },\n" % tuple(map(float2str, model.global_extents_min)))
fw("\tMaximumExtent { %s, %s, %s },\n" % tuple(map(float2str, model.global_extents_max)))
fw("\tBoundsRadius %s,\n" % float2str(calc_bounds_radius(model.global_extents_min, model.global_extents_max)))
fw("}\n")
2 changes: 1 addition & 1 deletion export_mdl/export_mdl/save_pivot_points.py
Expand Up @@ -10,5 +10,5 @@ def save_pivot_points(fw: TextIO.write, objects_all: List[War3Node]):
if len(objects_all):
fw("PivotPoints %d {\n" % len(objects_all))
for obj in objects_all:
fw("\t{%s, %s, %s},\n" % tuple(map(float2str, obj.pivot)))
fw("\t{ %s, %s, %s },\n" % tuple(map(float2str, obj.pivot)))
fw("}\n")
18 changes: 9 additions & 9 deletions export_mdl/export_mdl/save_sequences.py
Expand Up @@ -9,16 +9,16 @@ def save_sequences(fw: TextIO.write, model: War3Model):
fw("Sequences %d {\n" % len(model.sequences))
for sequence in model.sequences:
fw("\tAnim \"%s\" {\n" % sequence.name)
fw("\t\tInterval {%d, %d},\n" % (sequence.start, sequence.end))
fw("\t\tInterval { %d, %d },\n" % (sequence.start, sequence.end))
if sequence.non_looping:
fw("\t\tNonLooping,\n")
if sequence.rarity > 0:
fw("\t\tRarity %d,\n" % sequence.rarity)
if 'walk' in sequence.name.lower():
fw("\t\tMoveSpeed %d,\n" % sequence.movement_speed)

fw("\t\tMinimumExtent {%s, %s, %s},\n" % tuple(map(float2str, model.global_extents_min)))
fw("\t\tMaximumExtent {%s, %s, %s},\n" % tuple(map(float2str, model.global_extents_max)))
fw("\t\tMinimumExtent { %s, %s, %s },\n" % tuple(map(float2str, model.global_extents_min)))
fw("\t\tMaximumExtent { %s, %s, %s },\n" % tuple(map(float2str, model.global_extents_max)))
fw("\t\tBoundsRadius %s,\n" % float2str(calc_bounds_radius(model.global_extents_min, model.global_extents_max)))
fw("\t}\n")
fw("}\n")
Expand All @@ -30,16 +30,16 @@ def save_sequences(fw: TextIO.write, sequences: List[War3AnimationAction],
fw("Sequences %d {\n" % len(sequences))
for sequence in sequences:
fw("\tAnim \"%s\" {\n" % sequence.name)
fw("\t\tInterval {%d, %d},\n" % (sequence.start, sequence.end))
fw("\t\tInterval { %d, %d },\n" % (sequence.start, sequence.end))
if sequence.non_looping:
fw("\t\tNonLooping,\n")
if sequence.rarity > 0:
fw("\t\tRarity %d,\n" % sequence.rarity)
if 'walk' in sequence.name.lower():
fw("\t\tMoveSpeed %d,\n" % sequence.movement_speed)

fw("\t\tMinimumExtent {%s, %s, %s},\n" % tuple(map(float2str, global_extents_min)))
fw("\t\tMaximumExtent {%s, %s, %s},\n" % tuple(map(float2str, global_extents_max)))
fw("\t\tMinimumExtent { %s, %s, %s },\n" % tuple(map(float2str, global_extents_min)))
fw("\t\tMaximumExtent { %s, %s, %s },\n" % tuple(map(float2str, global_extents_max)))
fw("\t\tBoundsRadius %s,\n" % float2str(calc_bounds_radius(global_extents_min, global_extents_max)))
fw("\t}\n")
fw("}\n")
Expand All @@ -51,16 +51,16 @@ def save_sequences(fw: TextIO.write, sequences: List[War3AnimationAction],
fw("Sequences %d {\n" % len(sequences))
for sequence in sequences:
fw("\tAnim \"%s\" {\n" % sequence.name)
fw("\t\tInterval {%d, %d},\n" % (int(sequence.start*f2ms), int(sequence.end*f2ms)))
fw("\t\tInterval { %d, %d },\n" % (int(sequence.start*f2ms), int(sequence.end*f2ms)))
if sequence.non_looping:
fw("\t\tNonLooping,\n")
if sequence.rarity > 0:
fw("\t\tRarity %d,\n" % sequence.rarity)
if 'walk' in sequence.name.lower():
fw("\t\tMoveSpeed %d,\n" % sequence.movement_speed)

fw("\t\tMinimumExtent {%s, %s, %s},\n" % tuple(map(float2str, global_extents_min)))
fw("\t\tMaximumExtent {%s, %s, %s},\n" % tuple(map(float2str, global_extents_max)))
fw("\t\tMinimumExtent { %s, %s, %s },\n" % tuple(map(float2str, global_extents_min)))
fw("\t\tMaximumExtent { %s, %s, %s },\n" % tuple(map(float2str, global_extents_max)))
fw("\t\tBoundsRadius %s,\n" % float2str(calc_bounds_radius(global_extents_min, global_extents_max)))
fw("\t}\n")
fw("}\n")
2 changes: 1 addition & 1 deletion export_mdl/import_stuff/mdl_parser/mdl_reader.py
Expand Up @@ -27,7 +27,7 @@ def chunkifier(chunk_to_split: str) -> List[str]:
while split_start < last_bracket:
end_bracket_index = chunk_to_split.index("}", split_start)
bracket_count = count_brackets(0, chunk_to_split[split_start:end_bracket_index+1])
while bracket_count > 0:
while 0 < bracket_count:
end_bracket_index = chunk_to_split.index("}", end_bracket_index+1)
bracket_count = count_brackets(0, chunk_to_split[split_start:end_bracket_index+1])
chunks.append(chunk_to_split[split_start:end_bracket_index+1].strip('\n\t\r ,'))
Expand Down
6 changes: 3 additions & 3 deletions export_mdl/utils.py
Expand Up @@ -32,13 +32,13 @@ def calc_extents(vertices: List[List[float]]) -> Tuple[List[float], List[float]]
# max_extents = [max(vertices, key=itemgetter(i))[i] for i in range(3)]
# min_extents = [min(vertices, key=itemgetter(i))[i] for i in range(3)]

max_extents = [0.0, 0.0, 0.0]
min_extents = [0.0, 0.0, 0.0]
min_extents: List[float] = [0.0, 0.0, 0.0]
max_extents: List[float] = [0.0, 0.0, 0.0]

for vertex in vertices:
for i, v in enumerate(vertex):
min_extents[i] = min(min_extents[i], v)
max_extents[i] = max(max_extents[i], v)
min_extents[i] = min(max_extents[i], v)

return min_extents, max_extents

Expand Down

0 comments on commit fd10e5b

Please sign in to comment.