OSDN Git Service

fix string encode
[meshio/pymeshio.git] / blender25-meshio / pymeshio / mmd.py
index fbbc71f..7dc8f9b 100644 (file)
@@ -40,8 +40,8 @@ if sys.version_info[0]<3:
         """
         0x00以降を捨てる
         """
-        pos = src.find(b"\x00")
         assert(type(src)==bytes)
+        pos = src.find(b"\x00")
         if pos >= 0:
             return src[:pos]
         else:
@@ -51,13 +51,41 @@ else:
         """
         0x00以降を捨てる
         """
-        pos = src.find(b"\x00")
         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
 
@@ -109,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']