#!BPY """ Name: 'TrueSpace (.cob)...' Blender: 232 Group: 'Import' Tooltip: 'Import TrueSpace Object File Format (.cob)' """ # $Id$ # # +---------------------------------------------------------+ # | Copyright (c) 2001 Anthony D'Agostino | # | http://www.redrival.com/scorpius | # | scorpius@netzero.com | # | June 12, 2001 | # | Released under the Blender Artistic Licence (BAL) | # | Import Export Suite v0.5 | # +---------------------------------------------------------+ # | Read and write Caligari trueSpace File Format (*.cob) | # +---------------------------------------------------------+ import Blender, mod_meshtools import struct, chunk, os, cStringIO, time # ======================= # === COB Chunk Class === # ======================= class CobChunk(chunk.Chunk): def __init__(self, file, align = 0, bigendian = 0, inclheader = 0): #$ COB self.closed = 0 self.align = align # whether to align to word (2-byte) boundaries if bigendian: strflag = '>' else: strflag = '<' self.file = file self.chunkname = file.read(4) if len(self.chunkname) < 4: raise EOFError self.major_ver, = struct.unpack(strflag+'h', file.read(2)) #$ COB self.minor_ver, = struct.unpack(strflag+'h', file.read(2)) #$ COB self.chunk_id, = struct.unpack(strflag+'l', file.read(4)) #$ COB self.parent_id, = struct.unpack(strflag+'l', file.read(4)) #$ COB try: self.chunksize = struct.unpack(strflag+'l', file.read(4))[0] except struct.error: raise EOFError if inclheader: self.chunksize = self.chunksize - 20 #$ COB self.size_read = 0 try: self.offset = self.file.tell() except: self.seekable = 0 else: self.seekable = 1 # ============================ # === Read COB File Header === # ============================ def read_header(file): magic, = struct.unpack("<9s", file.read(9)) version, = struct.unpack("<6s", file.read(6)) format, = struct.unpack("<1c", file.read(1)) endian, = struct.unpack("<2s", file.read(2)) misc, = struct.unpack("13s", file.read(13)) newline, = struct.unpack("<1B", file.read(1)) return format # ======================================== # === Read PolH (Polygonal Data) Chunk === # ======================================== def read_polh(chunk): data = cStringIO.StringIO(chunk.read()) oname = read_ObjectName(data) local = read_LocalAxes(data) crpos = read_CurrentPosition(data) verts = read_VertexList(data) uvcoords = read_UVCoords(data) faces, facesuv = read_FaceList(data, chunk) return verts, faces, oname, facesuv, uvcoords # === Read Object Name === def read_ObjectName(data): dupecount, namelen = struct.unpack(" 0: objname = objname + ', ' + `dupecount` return objname # === Read Local Axes === def read_LocalAxes(data): location = struct.unpack("