Skip to content

Commit

Permalink
Add Support for Non-Integer Frame Indices
Browse files Browse the repository at this point in the history
  • Loading branch information
SE2Dev committed Apr 3, 2017
1 parent a8d855f commit 4cfc0ca
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions xanim.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from time import strftime
import os

# Can be int or float
# Changes the internal type for frames indices
FRAME_TYPE = float

'''
-------------------
---< NT_EXPORT >---
Expand Down Expand Up @@ -44,7 +48,7 @@ def LoadFile(self, path):
if note_count == 0:
break
elif line_split[0] == "FRAME":
note = Note(int(line_split[1]), line_split[2][1:-1])
note = Note(FRAME_TYPE(line_split[1]), line_split[2][1:-1])
self.notes.append(note)
file.close()

Expand Down Expand Up @@ -89,6 +93,10 @@ def __clamp_multi__(value, range=(-1.0, 1.0)):
return tuple([max(min(v, range[1]), range[0]) for v in value])


def __clean_float2str__(value):
return ('%f' % value).rstrip('0').rstrip('.')


class PartInfo(object):
'''In the context of an XANIM_EXPORT file, a 'part' is essentially a
bone'''
Expand Down Expand Up @@ -244,14 +252,12 @@ def __load_frames__(self, file):
continue

if line_split[0] == "FRAMERATE":
# TODO: Check if the format even supports non-int framerates
self.framerate = float(line_split[1])
elif line_split[0] == "NUMFRAMES":
frame_count = int(line_split[1])
self.frames = [None] * frame_count
elif line_split[0] == "FRAME":
# TODO: Check if the format supports non-int frames
frame_number = int(line_split[1])
frame_number = FRAME_TYPE(line_split[1])

# Don't enable this until anims that don't start on frame 0 are
# sorted out
Expand Down Expand Up @@ -297,7 +303,7 @@ def __load_notes__(self, file, use_notetrack_file=True):
if note_count != 0:
state = 1
elif state == 1 and line_split[0] == "FRAME":
frame = int(line_split[1])
frame = FRAME_TYPE(line_split[1])
string = line_split[2][1:-1]
note = Note(frame, string)
self.notes.append(note)
Expand Down Expand Up @@ -372,13 +378,13 @@ def WriteFile(self, path, header_message="", embed_notes=True):
file.write("PART %d \"%s\"\n" % (part_index, part.name))
file.write("\n")

file.write("FRAMERATE %d\n" % self.framerate)
file.write("FRAMERATE %s\n" % __clean_float2str__(self.framerate))
file.write("NUMFRAMES %d\n" % len(self.frames))
for frame in self.frames:
file.write("FRAME %d\n" % frame.frame)
file.write("FRAME %s\n" % __clean_float2str__(frame.frame))
for part_index, part in enumerate(frame.parts):
file.write("PART %d\n" % part_index)
# TODO: Investigate precision options
# Investigate precision options?
offset = (part.offset[0], part.offset[1], part.offset[2])
file.write("OFFSET %f %f %f\n" % offset)
file.write("X %f %f %f\n" % __clamp_multi__(part.matrix[0]))
Expand All @@ -393,9 +399,6 @@ def WriteFile(self, path, header_message="", embed_notes=True):
# TODO: Verify how notetracks work across versions
# (Specifically for CoD2)

# TODO: Support for NT_EXPORT file generation
# and automatically formatting the XANIM_EXPORT to correspond to this

# WAW Style
file.write("NOTETRACKS\n\n")
if embed_notes is True:
Expand Down

0 comments on commit 4cfc0ca

Please sign in to comment.