X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=blender25-meshio%2Fpymeshio%2Fmmd.py;h=7dc8f9b673a7fa33e4dab2fb821ed33bbecd80f5;hb=65211f29fc6e1e540cc3e1c515753f860653382b;hp=02d852b9da03915b8a8580f2275c719a594d2938;hpb=e59825fe14580205a23a2da39d5e2bd805277522;p=meshio%2Fpymeshio.git diff --git a/blender25-meshio/pymeshio/mmd.py b/blender25-meshio/pymeshio/mmd.py index 02d852b..7dc8f9b 100644 --- a/blender25-meshio/pymeshio/mmd.py +++ b/blender25-meshio/pymeshio/mmd.py @@ -35,17 +35,57 @@ if sys.version_info[0]>=3: ############################################################################### # utility ############################################################################### -def truncate_zero(src): - """ - 0x00以降を捨てる - """ - pos = src.find(b"\x00") - assert(type(src)==bytes) - if pos >= 0: - return src[:pos] - else: +if sys.version_info[0]<3: + def truncate_zero(src): + """ + 0x00以降を捨てる + """ + assert(type(src)==bytes) + pos = src.find(b"\x00") + if pos >= 0: + return src[:pos] + else: + return src +else: + def truncate_zero(src): + """ + 0x00以降を捨てる + """ + assert(type(src)==bytes) + pos = src.find(b"\x00") + if pos >= 0: + return src[:pos].decode('cp932') + else: + return src.decode('cp932') + + +if sys.version_info[0]<3: + def to_str(src): + t=type(src) + if t==unicode: + return src.encode('cp932') + elif t==str: + return src + else: + raise "INVALID str: %s" % t + + def from_str(src): return src +else: + def to_str(src): + t=type(src) + if t==str: + return src + elif t==bytes: + return src.decode('cp932') + else: + raise "INVALID str: %s" % t + + def from_str(src): + return src.encode('cp932') + + def radian_to_degree(x): return x/math.pi * 180.0 @@ -97,6 +137,9 @@ class Vector3(object): def to_tuple(self): return (self.x, self.y, self.z) + def __add__(l, r): + return Vector3(l.x+r.x, l.y+r.y, l.z+r.z) + class Quaternion(object): __slots__=['x', 'y', 'z', 'w']