#!BPY """ Name: 'TrueSpace (.cob)...' Blender: 232 Group: 'Import' Tooltip: 'Import TrueSpace Object File Format (.cob)' """ __author__ = "Anthony D'Agostino (Scorpius)" __url__ = ("blender", "elysiun", "Author's homepage, http://www.redrival.com/scorpius") __version__ = "Part of IOSuite 0.5" __bpydoc__ = """\ This script imports TrueSpace files to Blender TrueSpace is a commercial modeling and rendering application. The .cob file format is composed of 'chunks,' is well defined, and easy to read and write. It's very similar to LightWave's lwo format. Usage:
Execute this script from the "File->Import" menu and choose a TrueSpace file to open. Supported:
Meshes only. Supports UV Coordinates. COB files in ascii format can't be read. Missing:
Materials, and Vertex Color info will be ignored. Known issues:
Triangulation of convex polygons works fine, and uses a very simple fanning algorithm. Convex polygons (i.e., shaped like the letter "U") require a different algorithm, and will be triagulated incorrectly. Notes:
There are a few differences between how Blender & TrueSpace represent their objects' transformation matrices. Blender simply uses a 4x4 matrix, and trueSpace splits it into the following two fields. For the 'Local Axes' values: The x, y, and z-axis represent a simple rotation matrix. This is equivalent to Blender's object matrix before it was combined with the object's scaling matrix. Dividing each value by the appropriate scaling factor (and transposing at the same time) produces the original rotation matrix. For the 'Current Position' values: This is equivalent to Blender's object matrix except that the last row is omitted and the xyz location is used in the last column. Binary format uses a 4x3 matrix, ascii format uses a 4x4 matrix. For Cameras: The matrix here gets a little confusing, and I'm not sure of how to handle it. """ # $Id$ # # +---------------------------------------------------------+ # | Copyright (c) 2001 Anthony D'Agostino | # | http://www.redrival.com/scorpius | # | scorpius@netzero.com | # | June 12, 2001 | # | Read and write Caligari trueSpace File Format (*.cob) | # +---------------------------------------------------------+ # ***** BEGIN GPL LICENSE BLOCK ***** # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # ***** END GPL LICENCE BLOCK ***** import Blender, 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("