Home | Trees | Indices | Help |
---|
|
1 # coding: utf-8 2 """ 3 vmd reader 4 """ 5 import io 6 import struct 7 from .. import common 8 from .. import vmd 9 1043 4413 """read cp932 text 14 """ 15 src=self.unpack("%ds" % size, size) 16 assert(type(src)==bytes) 17 pos = src.find(b"\x00") 18 if pos==-1: 19 return src 20 else: 21 return src[:pos]2224 """ 25 フレームひとつ分を読み込む 26 """ 27 frame=vmd.BoneFrame(self.read_text(15)) 28 (frame.frame, frame.pos.x, frame.pos.y, frame.pos.z, 29 frame.q.x, frame.q.y, frame.q.z, frame.q.w) = struct.unpack( 30 'I7f', self.ios.read(32)) 31 # complement data 32 frame.complement=''.join( 33 ['%x' % x for x in struct.unpack('64B', self.ios.read(64))]) 34 return frame3546 """ 47 read from file path 48 49 :Parameters: 50 path 51 file path 52 53 >>> import vmd.reader 54 >>> m=vmd.reader.read_from_file('resources/motion.vmd') 55 >>> print(m) 56 57 """ 58 return read(io.BytesIO(common.readall(path)))59 6062 assert(isinstance(ios, io.IOBase)) 63 reader=common.BinaryReader(ios) 64 65 signature=reader.unpack("30s", 30) 66 version=None 67 if signature[:25] == "Vocaloid Motion Data 0002": 68 version=2 69 elif signature[:25] == "Vocaloid Motion Data file": 70 version=1 71 else: 72 print("invalid signature", signature) 73 return 74 75 reader=Reader(reader.ios) 76 motion=vmd.Motion() 77 motion.model_name=reader.read_text(20) 78 motion.motions=[reader.read_bone_frame() 79 for _ in range(reader.unpack('I', 4))] 80 motion.shapes=[reader.read_morph_frame() 81 for _ in range(reader.unpack('I', 4))] 82 motion.cameras=[reader.read_cameta_frame() 83 for _ in range(reader.unpack('I', 4))] 84 motion.lights=[reader.read_light_frame() 85 for _ in range(reader.unpack('I', 4))] 86 return motion87
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Dec 2 06:05:54 2011 | http://epydoc.sourceforge.net |