From b811d10dcc8b2358dfc43abe7431a2d132dde45f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Sun, 22 May 2011 19:32:24 +0900 Subject: [PATCH] fix for python3 --- blender25-meshio/pymeshio/mmd.py | 32 ++++++++++++++++++++++---------- blender25-meshio/pymeshio/pmd.py | 21 +++++++++------------ setup.py | 4 +++- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/blender25-meshio/pymeshio/mmd.py b/blender25-meshio/pymeshio/mmd.py index 02d852b..fbbc71f 100644 --- a/blender25-meshio/pymeshio/mmd.py +++ b/blender25-meshio/pymeshio/mmd.py @@ -35,16 +35,28 @@ 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: - return src +if sys.version_info[0]<3: + def truncate_zero(src): + """ + 0x00以降を捨てる + """ + pos = src.find(b"\x00") + assert(type(src)==bytes) + if pos >= 0: + return src[:pos] + else: + return src +else: + def truncate_zero(src): + """ + 0x00以降を捨てる + """ + pos = src.find(b"\x00") + assert(type(src)==bytes) + if pos >= 0: + return src[:pos].decode('cp932') + else: + return src.decode('cp932') def radian_to_degree(x): return x/math.pi * 180.0 diff --git a/blender25-meshio/pymeshio/pmd.py b/blender25-meshio/pymeshio/pmd.py index e42365b..8efc328 100644 --- a/blender25-meshio/pymeshio/pmd.py +++ b/blender25-meshio/pymeshio/pmd.py @@ -380,17 +380,12 @@ class IO(object): len(self.materials), len(self.bones), len(self.ik_list), len(self.morph_list)) def _check_position(self): - """ - if self.pos: - print(self.pos, self.io.tell()-self.pos) - """ self.pos=self.io.tell() - pass def read(self, path): size=os.path.getsize(path) - f=open(path, "rb") - return self.load(path, f, size) + with open(path, "rb") as f: + return self.load(path, f, size) def load(self, path, io, end): self.io=io @@ -548,9 +543,6 @@ class IO(object): for l in self.bone_display_list: io.write(struct.pack("=HB", *l)) - # ToDo - # Extend Data - return True @@ -587,7 +579,6 @@ class IO(object): def _loadHeader(self): signature=struct.unpack("3s", self.io.read(3))[0] - #print(signature) if signature!=b"Pmd": print("invalid signature", signature) return False @@ -700,13 +691,14 @@ class IO(object): struct.unpack("20s", self.io.read(20))[0]) self.english_comment=truncate_zero( struct.unpack("256s", self.io.read(256))[0]) + self._check_position() # english bone name for bone in self.bones: english_name=truncate_zero( struct.unpack("20s", self.io.read(20))[0]) bone.english_name=english_name + self._check_position() # english skin list - #for index in self.face_list: for skin in self.morph_list: if skin.name=='base': continue @@ -715,10 +707,12 @@ class IO(object): #skin=self.morph_list[index] if english_name!=skin.name: skin.english_name=english_name + self._check_position() # english bone list for i in xrange(0, len(self.bone_group_list)): self.bone_group_list[i].english_name=truncate_zero( struct.unpack("50s", self.io.read(50))[0]) + self._check_position() return True def loadPhysics(self): @@ -747,6 +741,7 @@ class IO(object): rigidbody.friction=struct.unpack("f", self.io.read(4))[0] rigidbody.processType=struct.unpack("B", self.io.read(1))[0] self.rigidbodies.append(rigidbody) + self._check_position() # ジョイントリスト count = struct.unpack("I", self.io.read(4))[0] @@ -780,5 +775,7 @@ class IO(object): constraint.springRot.y=struct.unpack("f", self.io.read(4))[0] constraint.springRot.z=struct.unpack("f", self.io.read(4))[0] self.constraints.append(constraint) + self._check_position() + return True diff --git a/setup.py b/setup.py index 905622d..ecb5c60 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ #from distutils.core import setup +import sys from setuptools import setup setup( @@ -14,6 +15,7 @@ setup( 'pymeshio': 'blender25-meshio/pymeshio' }, packages=['pymeshio'], - test_suite='nose.collector' + test_suite='nose.collector', + zip_safe = (sys.version>="2.5"), # <2.5 needs unzipped for -m to work ) -- 2.11.0