#!BPY """ Name: '3D Studio (.3ds)...' Blender: 241 Group: 'Export' Tooltip: 'Export to 3DS file format (.3ds).' """ __author__ = ["Campbell Barton", "Bob Holcomb", "Richard Lärkäng", "Damien McGinnes", "Mark Stijnman"] __url__ = ("blender", "elysiun", "http://www.gametutorials.com", "http://lib3ds.sourceforge.net/") __version__ = "0.90a" __bpydoc__ = """\ 3ds Exporter This script Exports a 3ds file. Exporting is based on 3ds loader from www.gametutorials.com(Thanks DigiBen) and using information from the lib3ds project (http://lib3ds.sourceforge.net/) sourcecode. """ # ***** BEGIN GPL LICENSE BLOCK ***** # # Script copyright (C) Bob Holcomb # # 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 ***** # -------------------------------------------------------------------------- ###################################################### # Importing modules ###################################################### import Blender from Blender import Object, Material import BPyMesh import struct ###################################################### # Data Structures ###################################################### #Some of the chunks that we will export #----- Primary Chunk, at the beginning of each file PRIMARY= long("0x4D4D",16) #------ Main Chunks OBJECTINFO = long("0x3D3D",16); #This gives the version of the mesh and is found right before the material and object information VERSION = long("0x0002",16); #This gives the version of the .3ds file KFDATA = long("0xB000",16); #This is the header for all of the key frame info #------ sub defines of OBJECTINFO MATERIAL=45055 #0xAFFF // This stored the texture info OBJECT=16384 #0x4000 // This stores the faces, vertices, etc... #>------ sub defines of MATERIAL MATNAME = long("0xA000",16); # This holds the material name MATAMBIENT = long("0xA010",16); # Ambient color of the object/material MATDIFFUSE = long("0xA020",16); # This holds the color of the object/material MATSPECULAR = long("0xA030",16); # SPecular color of the object/material MATSHINESS = long("0xA040",16); # ?? MATMAP = long("0xA200",16); # This is a header for a new material MATMAPFILE = long("0xA300",16); # This holds the file name of the texture RGB1= long("0x0011",16) RGB2= long("0x0012",16) #>------ sub defines of OBJECT OBJECT_MESH = long("0x4100",16); # This lets us know that we are reading a new object OBJECT_LIGHT = long("0x4600",16); # This lets un know we are reading a light object OBJECT_CAMERA= long("0x4700",16); # This lets un know we are reading a camera object #>------ sub defines of CAMERA OBJECT_CAM_RANGES= long("0x4720",16); # The camera range values #>------ sub defines of OBJECT_MESH OBJECT_VERTICES = long("0x4110",16); # The objects vertices OBJECT_FACES = long("0x4120",16); # The objects faces OBJECT_MATERIAL = long("0x4130",16); # This is found if the object has a material, either texture map or color OBJECT_UV = long("0x4140",16); # The UV texture coordinates OBJECT_TRANS_MATRIX = long("0x4160",16); # The Object Matrix #>------ sub defines of KFDATA KFDATA_KFHDR = long("0xB00A",16); KFDATA_KFSEG = long("0xB008",16); KFDATA_KFCURTIME = long("0xB009",16); KFDATA_OBJECT_NODE_TAG = long("0xB002",16); #>------ sub defines of OBJECT_NODE_TAG OBJECT_NODE_ID = long("0xB030",16); OBJECT_NODE_HDR = long("0xB010",16); OBJECT_PIVOT = long("0xB013",16); OBJECT_INSTANCE_NAME = long("0xB011",16); POS_TRACK_TAG = long("0xB020",16); ROT_TRACK_TAG = long("0xB021",16); SCL_TRACK_TAG = long("0xB022",16); #==============================================# # Strips the slashes from the back of a string # #==============================================# def stripPath(path): '''Strips the slashes from the back of a string. ''' return path.split('/')[-1].split('\\')[-1] def uv_key(uv): return round(uv.x, 6), round(uv.y, 6) # size defines: SZ_SHORT = 2 SZ_INT = 4 SZ_FLOAT = 4 class _3ds_short: '''Class representing a short (2-byte integer) for a 3ds file. *** This looks like an unsigned short H is unsigned from the struct docs - Cam***''' value=0 def __init__(self, val=0): self.value=val def get_size(self): return SZ_SHORT def write(self,file): data=struct.pack("