diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-02-13 04:13:16 +0300 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2010-02-13 04:13:16 +0300 |
commit | 135a944c66c57f11fd77b4f7231686353112e7ac (patch) | |
tree | 3928c457f44f544113e84b3356ab101e3820072e /release/scripts/io/import_scene_3ds.py | |
parent | 1b3948f9aad25fec1923f5ccd36ea525d8e34fb6 (diff) | |
parent | 33b1cbf06d2c822c68676390b1775eb5d78de6e6 (diff) |
Merged changes in the trunk up to revision 26856.
Diffstat (limited to 'release/scripts/io/import_scene_3ds.py')
-rw-r--r-- | release/scripts/io/import_scene_3ds.py | 160 |
1 files changed, 13 insertions, 147 deletions
diff --git a/release/scripts/io/import_scene_3ds.py b/release/scripts/io/import_scene_3ds.py index 971d62d8e15..29289ae0970 100644 --- a/release/scripts/io/import_scene_3ds.py +++ b/release/scripts/io/import_scene_3ds.py @@ -12,7 +12,7 @@ # # 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. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ##### END GPL LICENSE BLOCK ##### @@ -130,7 +130,7 @@ Loader is based on 3ds loader from www.gametutorials.com (Thanks DigiBen). # # 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. +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ***** END GPL LICENCE BLOCK ***** # -------------------------------------------------------------------------- @@ -146,41 +146,9 @@ from import_scene_obj import unpack_face_list, load_image import bpy import Mathutils -# import Blender -# from Blender import Mesh, Object, Material, Image, Texture, Lamp, Mathutils -# from Blender.Mathutils import Vector -# import BPyImage - -# import BPyMessages - -# try: -# from struct import calcsize, unpack -# except: -# calcsize= unpack= None - - - -# # If python version is less than 2.4, try to get set stuff from module -# try: -# set -# except: -# from sets import Set as set - BOUNDS_3DS = [] -#this script imports uvcoords as sticky vertex coords -#this parameter enables copying these to face uv coords -#which shold be more useful. - -def createBlenderTexture(material, name, image): - texture = bpy.data.textures.new(name) - texture.setType('Image') - texture.image = image - material.setTexture(0, texture, Texture.TexCo.UV, Texture.MapTo.COL) - - - ###################################################### # Data Structures ###################################################### @@ -294,11 +262,8 @@ def read_chunk(file, chunk): def read_string(file): #read in the characters till we get a null character s = b'' -# s = '' while not s.endswith(b'\x00'): -# while not s.endswith('\x00'): s += struct.unpack('<c', file.read(1))[0] -# s += struct.unpack( '<c', file.read(1) )[0] #print 'string: ',s s = str(s[:-1], 'ASCII') @@ -327,29 +292,17 @@ def skip_to_end(file, skip_chunk): def add_texture_to_material(image, texture, material, mapto): -# if mapto=='DIFFUSE': -# map = Texture.MapTo.COL -# elif mapto=='SPECULAR': -# map = Texture.MapTo.SPEC -# elif mapto=='OPACITY': -# map = Texture.MapTo.ALPHA -# elif mapto=='BUMP': -# map = Texture.MapTo.NOR -# else: + #print('assigning %s to %s' % (texture, material)) + if mapto not in ("COLOR", "SPECULARITY", "ALPHA", "NORMAL"): print('/tError: Cannot map to "%s"\n\tassuming diffuse color. modify material "%s" later.' % (mapto, material.name)) mapto = "COLOR" -# map = Texture.MapTo.COL - if image: texture.image = image + if image: + texture.image = image # if image: texture.setImage(image) # double check its an image. material.add_texture(texture, "UV", mapto) -# free_tex_slots = [i for i, tex in enumerate( material.getTextures() ) if tex == None] -# if not free_tex_slots: -# print('/tError: Cannot add "%s" map. 10 Texture slots alredy used.' % mapto) -# else: -# material.setTexture(free_tex_slots[0],texture,Texture.TexCo.UV,map) def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): @@ -436,7 +389,6 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): if bmesh.faces and (contextMeshUV or img): bmesh.add_uv_texture() -# bmesh.faceUV = 1 for ii, i in enumerate(faces): # Mapped index- faces may have not been added- if so, then map to the correct index @@ -461,7 +413,9 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): # targetFace.uv = [contextMeshUV[vindex] for vindex in myContextMesh_facels[i]] if img: uf.image = img -# targetFace.image = img + + # to get this image to show up in 'Textured' shading mode + uf.tex = True # bmesh.transform(contextMatrix) ob = bpy.data.objects.new(tempName, 'MESH') @@ -507,7 +461,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): return [float(col)/255 for col in struct.unpack('<3B', temp_data)] # data [0,1,2] == rgb def read_texture(new_chunk, temp_chunk, name, mapto): - new_texture = bpy.data.textures.new('Diffuse') + new_texture = bpy.data.textures.new(name) new_texture.type = 'IMAGE' new_texture = new_texture.recast_type() @@ -657,96 +611,15 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): elif (new_chunk.ID == MAT_TEXTURE_MAP): read_texture(new_chunk, temp_chunk, "Diffuse", "COLOR") -# #print 'elif (new_chunk.ID==MAT_TEXTURE_MAP):' -# new_texture= bpy.data.textures.new('Diffuse') -# new_texture.setType('Image') -# img = None -# while (new_chunk.bytes_read<new_chunk.length): -# #print 'MAT_TEXTURE_MAP..while', new_chunk.bytes_read, new_chunk.length -# read_chunk(file, temp_chunk) - -# if (temp_chunk.ID==MAT_MAP_FILENAME): -# texture_name=read_string(file) -# #img= TEXTURE_DICT[contextMaterial.name]= BPyImage.comprehensiveImageLoad(texture_name, FILENAME) -# img= TEXTURE_DICT[contextMaterial.name]= BPyImage.comprehensiveImageLoad(texture_name, FILENAME, PLACE_HOLDER= False, RECURSIVE= IMAGE_SEARCH) -# new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed - -# else: -# skip_to_end(file, temp_chunk) - -# new_chunk.bytes_read+= temp_chunk.bytes_read - -# #add the map to the material in the right channel -# if img: -# add_texture_to_material(img, new_texture, contextMaterial, 'DIFFUSE') elif (new_chunk.ID == MAT_SPECULAR_MAP): read_texture(new_chunk, temp_chunk, "Specular", "SPECULARITY") -# #print 'elif (new_chunk.ID == MAT_SPECULAR_MAP):' -# new_texture = bpy.data.textures.new('Specular') -# new_texture.setType('Image') -# img = None -# while (new_chunk.bytes_read < new_chunk.length): -# read_chunk(file, temp_chunk) - -# if (temp_chunk.ID == MAT_MAP_FILENAME): -# texture_name = read_string(file) -# #img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME) -# img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME, PLACE_HOLDER=False, RECURSIVE=IMAGE_SEARCH) -# new_chunk.bytes_read+= (len(texture_name)+1) #plus one for the null character that gets removed -# else: -# skip_to_end(file, temp_chunk) - -# new_chunk.bytes_read += temp_chunk.bytes_read - -# #add the map to the material in the right channel -# if img: -# add_texture_to_material(img, new_texture, contextMaterial, 'SPECULAR') elif (new_chunk.ID == MAT_OPACITY_MAP): read_texture(new_chunk, temp_chunk, "Opacity", "ALPHA") -# #print 'new_texture = Blender.Texture.New('Opacity')' -# new_texture = bpy.data.textures.new('Opacity') -# new_texture.setType('Image') -# img = None -# while (new_chunk.bytes_read < new_chunk.length): -# read_chunk(file, temp_chunk) - -# if (temp_chunk.ID == MAT_MAP_FILENAME): -# texture_name = read_string(file) -# #img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME) -# img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME, PLACE_HOLDER=False, RECURSIVE=IMAGE_SEARCH) -# new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed -# else: -# skip_to_end(file, temp_chunk) - -# new_chunk.bytes_read += temp_chunk.bytes_read -# #add the map to the material in the right channel -# if img: -# add_texture_to_material(img, new_texture, contextMaterial, 'OPACITY') elif (new_chunk.ID == MAT_BUMP_MAP): read_texture(new_chunk, temp_chunk, "Bump", "NORMAL") -# #print 'elif (new_chunk.ID == MAT_BUMP_MAP):' -# new_texture = bpy.data.textures.new('Bump') -# new_texture.setType('Image') -# img = None -# while (new_chunk.bytes_read < new_chunk.length): -# read_chunk(file, temp_chunk) - -# if (temp_chunk.ID == MAT_MAP_FILENAME): -# texture_name = read_string(file) -# #img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME) -# img = BPyImage.comprehensiveImageLoad(texture_name, FILENAME, PLACE_HOLDER=False, RECURSIVE=IMAGE_SEARCH) -# new_chunk.bytes_read += (len(texture_name)+1) #plus one for the null character that gets removed -# else: -# skip_to_end(file, temp_chunk) - -# new_chunk.bytes_read += temp_chunk.bytes_read - -# #add the map to the material in the right channel -# if img: -# add_texture_to_material(img, new_texture, contextMaterial, 'BUMP') elif (new_chunk.ID == MAT_TRANSPARENCY): #print 'elif (new_chunk.ID == MAT_TRANSPARENCY):' @@ -852,7 +725,6 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): temp_data = file.read(STRUCT_SIZE_2FLOAT) new_chunk.bytes_read += STRUCT_SIZE_2FLOAT #2 float x 4 bytes each return Mathutils.Vector( struct.unpack('<2f', temp_data) ) -# return Vector( struct.unpack('<2f', temp_data) ) contextMeshUV = [ getuv() for i in range(num_uv) ] @@ -863,7 +735,6 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH): new_chunk.bytes_read += STRUCT_SIZE_4x3MAT contextMatrix_rot = Mathutils.Matrix(\ -# contextMatrix_rot = Blender.Mathutils.Matrix(\ data[:3] + [0],\ data[3:6] + [0],\ data[6:9] + [0],\ @@ -1089,16 +960,9 @@ def load_3ds(filename, context, IMPORT_CONSTRAIN_BOUNDS=10.0, IMAGE_SEARCH=True, print('finished importing: "%s" in %.4f sec.' % (filename, (time.clock()-time1))) # print('finished importing: "%s" in %.4f sec.' % (filename, (Blender.sys.time()-time1))) file.close() -# Blender.Window.WaitCursor(0) DEBUG = False -# if __name__=='__main__' and not DEBUG: -# if calcsize == None: -# Blender.Draw.PupMenu('Error%t|a full python installation not found') -# else: -# Blender.Window.FileSelector(load_3ds, 'Import 3DS', '*.3ds') - # For testing compatibility #load_3ds('/metavr/convert/vehicle/truck_002/TruckTanker1.3DS', False) #load_3ds('/metavr/archive/convert/old/arranged_3ds_to_hpx-2/only-need-engine-trains/Engine2.3DS', False) @@ -1151,7 +1015,9 @@ class IMPORT_OT_autodesk_3ds(bpy.types.Operator): # to the class instance from the operator settings before calling. path = StringProperty(name="File Path", description="File path used for importing the 3DS file", maxlen= 1024, default= "") - + filename = StringProperty(name="File Name", description="Name of the file.") + directory = StringProperty(name="Directory", description="Directory of the file.") + # size_constraint = FloatProperty(name="Size Constraint", description="Scale the model by 10 until it reacehs the size constraint. Zero Disables.", min=0.0, max=1000.0, soft_min=0.0, soft_max=1000.0, default=10.0), # search_images = BoolProperty(name="Image Search", description="Search subdirectories for any assosiated images (Warning, may be slow)", default=True), # apply_matrix = BoolProperty(name="Transform Fix", description="Workaround for object transformations importing incorrectly", default=False), |