[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23558] trunk/blender/release/scripts/io: adding back changes from soc-2009-kaz branch.

Campbell Barton ideasman42 at gmail.com
Tue Sep 29 17:27:00 CEST 2009


Revision: 23558
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23558
Author:   campbellbarton
Date:     2009-09-29 17:27:00 +0200 (Tue, 29 Sep 2009)

Log Message:
-----------
adding back changes from soc-2009-kaz branch.

Modified Paths:
--------------
    trunk/blender/release/scripts/io/export_3ds.py
    trunk/blender/release/scripts/io/export_fbx.py
    trunk/blender/release/scripts/io/export_obj.py
    trunk/blender/release/scripts/io/export_ply.py
    trunk/blender/release/scripts/io/export_x3d.py
    trunk/blender/release/scripts/io/import_3ds.py
    trunk/blender/release/scripts/io/import_obj.py

Modified: trunk/blender/release/scripts/io/export_3ds.py
===================================================================
--- trunk/blender/release/scripts/io/export_3ds.py	2009-09-29 15:16:22 UTC (rev 23557)
+++ trunk/blender/release/scripts/io/export_3ds.py	2009-09-29 15:27:00 UTC (rev 23558)
@@ -46,15 +46,36 @@
 # Importing modules
 ######################################################
 
-import Blender
+import struct
+import os
+import time
+
 import bpy
-from BPyMesh import getMeshFromObject
-from BPyObject import getDerivedObjects
-try: 
-    import struct
-except: 
-    struct = None
 
+# import Blender
+# from BPyMesh import getMeshFromObject
+# from BPyObject import getDerivedObjects
+# try: 
+#     import struct
+# except: 
+#     struct = None
+
+# also used by X3D exporter
+# return a tuple (free, object list), free is True if memory should be freed later with free_derived_objects()
+def create_derived_objects(ob):
+	if ob.parent and ob.parent.dupli_type != 'NONE':
+		return False, None
+
+	if ob.dupli_type != 'NONE':
+		ob.create_dupli_list()
+		return True, [(dob.object, dob.matrix) for dob in ob.dupli_list]
+	else:
+		return False, [(ob, ob.matrix)]
+
+# also used by X3D exporter
+def free_derived_objects(ob):
+	ob.free_dupli_list()
+
 # So 3ds max can open files, limit names to 12 in length
 # this is verry annoying for filenames!
 name_unique = []
@@ -85,61 +106,62 @@
 
 #Some of the chunks that we will export
 #----- Primary Chunk, at the beginning of each file
-PRIMARY= long("0x4D4D",16)
+PRIMARY= int("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
+OBJECTINFO   =      int("0x3D3D",16);      #This gives the version of the mesh and is found right before the material and object information
+VERSION      =      int("0x0002",16);      #This gives the version of the .3ds file
+KFDATA       =      int("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
+MATNAME    =      int("0xA000",16);      # This holds the material name
+MATAMBIENT   =      int("0xA010",16);      # Ambient color of the object/material
+MATDIFFUSE   =      int("0xA020",16);      # This holds the color of the object/material
+MATSPECULAR   =      int("0xA030",16);      # SPecular color of the object/material
+MATSHINESS   =      int("0xA040",16);      # ??
+MATMAP       =      int("0xA200",16);      # This is a header for a new material
+MATMAPFILE    =      int("0xA300",16);      # This holds the file name of the texture
 
-RGB1=	long("0x0011",16)
-RGB2=	long("0x0012",16)
+RGB1=	int("0x0011",16)
+RGB2=	int("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
+OBJECT_MESH  =      int("0x4100",16);      # This lets us know that we are reading a new object
+OBJECT_LIGHT =      int("0x4600",16);      # This lets un know we are reading a light object
+OBJECT_CAMERA=      int("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
+OBJECT_CAM_RANGES=   int("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
+OBJECT_VERTICES =   int("0x4110",16);      # The objects vertices
+OBJECT_FACES    =   int("0x4120",16);      # The objects faces
+OBJECT_MATERIAL =   int("0x4130",16);      # This is found if the object has a material, either texture map or color
+OBJECT_UV       =   int("0x4140",16);      # The UV texture coordinates
+OBJECT_TRANS_MATRIX  =   int("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);
+KFDATA_KFHDR            = int("0xB00A",16);
+KFDATA_KFSEG            = int("0xB008",16);
+KFDATA_KFCURTIME        = int("0xB009",16);
+KFDATA_OBJECT_NODE_TAG  = int("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);
+OBJECT_NODE_ID          = int("0xB030",16);
+OBJECT_NODE_HDR         = int("0xB010",16);
+OBJECT_PIVOT            = int("0xB013",16);
+OBJECT_INSTANCE_NAME    = int("0xB011",16);
+POS_TRACK_TAG			= int("0xB020",16);
+ROT_TRACK_TAG			= int("0xB021",16);
+SCL_TRACK_TAG			= int("0xB022",16);
 
 def uv_key(uv):
-	return round(uv.x, 6), round(uv.y, 6)
+	return round(uv[0], 6), round(uv[1], 6)
+# 	return round(uv.x, 6), round(uv.y, 6)
 
 # size defines:	
 SZ_SHORT = 2
@@ -272,7 +294,8 @@
 		return 3
 	
 	def write(self,file):
-		file.write( struct.pack('<3c', chr(int(255*self.r)), chr(int(255*self.g)), chr(int(255*self.b)) ) )
+		file.write( struct.pack('<3B', int(255*self.r), int(255*self.g), int(255*self.b) ) )
+# 		file.write( struct.pack('<3c', chr(int(255*self.r)), chr(int(255*self.g)), chr(int(255*self.b)) ) )
 	
 	def __str__(self):
 		return '{%f, %f, %f}' % (self.r, self.g, self.b)
@@ -343,12 +366,12 @@
 	def dump(self,indent):
 		if (self.value!=None):
 			spaces=""
-			for i in xrange(indent):
+			for i in range(indent):
 				spaces+="  ";
 			if (self.name!=""):
-				print spaces, self.name, " = ", self.value
+				print(spaces, self.name, " = ", self.value)
 			else:
-				print spaces, "[unnamed]", " = ", self.value
+				print(spaces, "[unnamed]", " = ", self.value)
 
 
 #the chunk class
@@ -408,9 +431,9 @@
 		Dump is used for debugging purposes, to dump the contents of a chunk to the standard output. 
 		Uses the dump function of the named variables and the subchunks to do the actual work.'''
 		spaces=""
-		for i in xrange(indent):
+		for i in range(indent):
 			spaces+="  ";
-		print spaces, "ID=", hex(self.ID.value), "size=", self.get_size()
+		print(spaces, "ID=", hex(self.ID.value), "size=", self.get_size())
 		for variable in self.variables:
 			variable.dump(indent+1)
 		for subchunk in self.subchunks:
@@ -424,15 +447,20 @@
 
 def get_material_images(material):
 	# blender utility func.
-	images = []
 	if material:
-		for mtex in material.getTextures():
-			if mtex and mtex.tex.type == Blender.Texture.Types.IMAGE:
-				image = mtex.tex.image
-				if image:
-					images.append(image) # maye want to include info like diffuse, spec here.
-	return images
+		return [s.texture.image for s in material.textures if s and s.texture.type == 'IMAGE' and s.texture.image]
 
+	return []
+# 	images = []
+# 	if material:
+# 		for mtex in material.getTextures():
+# 			if mtex and mtex.tex.type == Blender.Texture.Types.IMAGE:
+# 				image = mtex.tex.image
+# 				if image:
+# 					images.append(image) # maye want to include info like diffuse, spec here.
+# 	return images
+
+
 def make_material_subchunk(id, color):
 	'''Make a material subchunk.
 	
@@ -454,7 +482,8 @@
 	mat_sub = _3ds_chunk(id)
 	
 	def add_image(img):
-		filename = image.filename.split('\\')[-1].split('/')[-1]
+		filename = os.path.basename(image.filename)
+# 		filename = image.filename.split('\\')[-1].split('/')[-1]
 		mat_sub_file = _3ds_chunk(MATMAPFILE)
 		mat_sub_file.add_variable("mapfile", _3ds_string(sane_name(filename)))
 		mat_sub.add_subchunk(mat_sub_file)
@@ -482,9 +511,12 @@
 		material_chunk.add_subchunk(make_material_subchunk(MATSPECULAR, (1,1,1) ))
 	
 	else:
-		material_chunk.add_subchunk(make_material_subchunk(MATAMBIENT, [a*material.amb for a in material.rgbCol] ))
-		material_chunk.add_subchunk(make_material_subchunk(MATDIFFUSE, material.rgbCol))
-		material_chunk.add_subchunk(make_material_subchunk(MATSPECULAR, material.specCol))
+		material_chunk.add_subchunk(make_material_subchunk(MATAMBIENT, [a*material.ambient for a in material.diffuse_color] ))
+# 		material_chunk.add_subchunk(make_material_subchunk(MATAMBIENT, [a*material.amb for a in material.rgbCol] ))
+		material_chunk.add_subchunk(make_material_subchunk(MATDIFFUSE, material.diffuse_color))
+# 		material_chunk.add_subchunk(make_material_subchunk(MATDIFFUSE, material.rgbCol))
+		material_chunk.add_subchunk(make_material_subchunk(MATSPECULAR, material.specular_color))
+# 		material_chunk.add_subchunk(make_material_subchunk(MATSPECULAR, material.specCol))
 		
 		images = get_material_images(material) # can be None
 		if image: images.append(image)
@@ -513,28 +545,39 @@
 	
 	If the mesh contains quads, they will be split into triangles.'''
 	tri_list = []
-	do_uv = mesh.faceUV
+	do_uv = len(mesh.uv_textures)
+# 	do_uv = mesh.faceUV
 	
-	if not do_uv:
-		face_uv = None
+# 	if not do_uv:
+# 		face_uv = None
 	
 	img = None
-	for face in mesh.faces:
-		f_v = face.v

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list