[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11455] branches/2-44-stable/blender/ release/scripts: ran batch imports for 3ds and lwo, minor changes to batch loading functions and some changes to lwo face importing .

Campbell Barton cbarton at metavr.com
Wed Aug 1 12:15:45 CEST 2007


Revision: 11455
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11455
Author:   campbellbarton
Date:     2007-08-01 12:15:45 +0200 (Wed, 01 Aug 2007)

Log Message:
-----------
ran batch imports for 3ds and lwo, minor changes to batch loading functions and some changes to lwo face importing.

Modified Paths:
--------------
    branches/2-44-stable/blender/release/scripts/3ds_import.py
    branches/2-44-stable/blender/release/scripts/lightwave_import.py

Modified: branches/2-44-stable/blender/release/scripts/3ds_import.py
===================================================================
--- branches/2-44-stable/blender/release/scripts/3ds_import.py	2007-08-01 09:49:17 UTC (rev 11454)
+++ branches/2-44-stable/blender/release/scripts/3ds_import.py	2007-08-01 10:15:45 UTC (rev 11455)
@@ -1,7 +1,7 @@
 #!BPY
 """ 
 Name: '3D Studio (.3ds)...'
-Blender: 241
+Blender: 244
 Group: 'Import'
 Tooltip: 'Import from 3DS file format (.3ds)'
 """
@@ -945,6 +945,7 @@
 #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)
 '''
+
 else:
 	# DEBUG ONLY
 	TIME= Blender.sys.time()
@@ -956,6 +957,11 @@
 	file= open('/tmp/temp3ds_list', 'r')
 	lines= file.readlines()
 	file.close()
+	# sort by filesize for faster testing
+	lines_size = [(os.path.getsize(f[:-1]), f[:-1]) for f in lines]
+	lines_size.sort()
+	lines = [f[1] for f in lines_size]
+	
 
 	def between(v,a,b):
 		if v <= max(a,b) and v >= min(a,b):
@@ -963,8 +969,8 @@
 		return False
 		
 	for i, _3ds in enumerate(lines):
-		if between(i, 1,200):
-			_3ds= _3ds[:-1]
+		if between(i, 650,800):
+			#_3ds= _3ds[:-1]
 			print 'Importing', _3ds, '\nNUMBER', i, 'of', len(lines)
 			_3ds_file= _3ds.split('/')[-1].split('\\')[-1]
 			newScn= Blender.Scene.New(_3ds_file)
@@ -972,4 +978,5 @@
 			load_3ds(_3ds, False)
 
 	print 'TOTAL TIME: %.6f' % (Blender.sys.time() - TIME)
+
 '''
\ No newline at end of file

Modified: branches/2-44-stable/blender/release/scripts/lightwave_import.py
===================================================================
--- branches/2-44-stable/blender/release/scripts/lightwave_import.py	2007-08-01 09:49:17 UTC (rev 11454)
+++ branches/2-44-stable/blender/release/scripts/lightwave_import.py	2007-08-01 10:15:45 UTC (rev 11455)
@@ -693,7 +693,7 @@
 		i = i + 6 + subchunklen
 	#end loop on surf chunks
 	###if DEBUG: print "read image:%s" % clip_dict
-	if clip_dict.has_key('XREF'):
+	if 'XREF' in clip_dict: # has_key
 		###if DEBUG: print "Cross-reference: no image pre-allocated."
 		return clip_dict
 	#look for images
@@ -985,7 +985,8 @@
 					
 			if uvname: # != "":
 				my_dict['UVNAME'] = uvname                            #theoretically there could be a number of them: only one used per surf
-			if not(my_dict.has_key('g_IMAG')) and (rr.has_key('CHAN')) and (rr.has_key('OPAC')) and (rr.has_key('IMAG')):
+			# all are dictionaries - so testing keys 
+			if not('g_IMAG' in my_dict) and ('CHAN' in rr) and ('OPAC' in rr) and ('IMAG' in rr):
 				if (rr['CHAN'] == 'COLR') and (rr['OPAC'] == 0):
 					my_dict['g_IMAG'] = rr['IMAG']                 #do not set anything, just save image object for later assignment
 			subchunklen = 0 #force ending
@@ -1005,40 +1006,6 @@
 	###if DEBUG: print "-> Material pre-allocated."
 	return my_dict
 
-
-
-def reduce_face(verts, face):
-	TriangleArea= Blender.Mathutils.TriangleArea
-	Vector= Blender.Mathutils.Vector
-	####if DEBUG: print len(face), face
-	# wants indicies local to the face
-	len_face= len(face)
-	if len_face==3:
-		return [face]
-	elif len_face==4:
-		vecs= [Vector(verts[i]) for i in face]
-		# Get the convave quad area
-		a1= TriangleArea(vecs[0], vecs[1], vecs[2])
-		a2= TriangleArea(vecs[0], vecs[2], vecs[3])
-		
-		a3= TriangleArea(vecs[0], vecs[1], vecs[3])
-		a4= TriangleArea(vecs[1], vecs[2], vecs[3])
-		
-		if abs((a1+a2) - (a3+a4)) < (a1+a2+a3+a4)/100: # Not convace
-			####if DEBUG: print 'planer'
-			return [[0,1,2,3]]
-		if a1+a2<a3+a4:
-			return [[0,1,2], [0,2,3]]
-		else:
-			return [[0,1,3], [1,2,3]]
-
-	else: # 5+
-		####if DEBUG: print 'SCANFILL...', len(face)
-		ngons= BPyMesh.ngon(verts, face, PREF_FIX_LOOPS= True)
-	return ngons
-	
-
-
 # =========================
 # === Recalculate Faces ===
 # =========================
@@ -1109,7 +1076,7 @@
 		pass
 	
 	msh.mode |= Blender.Mesh.Modes.AUTOSMOOTH #smooth it anyway
-	if surf.has_key('SMAN'):
+	if 'SMAN' in surf: # has_key
 		#not allowed mixed mode mesh (all the mesh is smoothed and all with the same angle)
 		#only one smoothing angle will be active! => take the max one
 		msh.degr = min(80, int(surf['SMAN']/3.1415926535897932384626433832795*180.0))     #lwo in radians - blender in degrees
@@ -1119,12 +1086,8 @@
 	except:
 		img= None
 	
-	
 	#uv_flag = ((surf.has_key('UVNAME')) and (uvcoords_dict.has_key(surf['UVNAME'])) and (img != None))
-	uv_flag = ((surf.has_key('UVNAME')) and (uvcoords_dict.has_key(surf['UVNAME'])))
-	
-	
-	
+	uv_flag = (('UVNAME' in surf) and (surf['UVNAME'] in uvcoords_dict))
 
 	###if DEBUG: print "\n#===================================================================#"
 	###if DEBUG: print "Processing Object: %s" % objname
@@ -1186,55 +1149,50 @@
 					uvs.append(default_uv)
 		
 		return uvs
-	
+	cur_face
 	for i in cur_ptag_faces_indexes:
 		cur_face = complete_facelist[i]
 		numfaceverts = len(cur_face)
 		
 		if numfaceverts == 2:		edges.append((vertex_map[cur_face[0]], vertex_map[cur_face[1]]))
-		elif numfaceverts == 3:	
-			rev_face = (cur_face[2], cur_face[1], cur_face[0])
+		elif numfaceverts == 3 or numfaceverts == 4:	
+			rev_face = [__i for __i in reversed(cur_face)]
 			face_data.append( [vertex_map[j] for j in rev_face] )
 			if uv_flag: face_uvs.append(tmp_get_face_uvs(rev_face, i))
-		
-		elif numfaceverts > 3:
-			meta_faces= reduce_face(complete_vertlist, cur_face)        # Indices of triangles
+		elif numfaceverts > 4:
+			meta_faces= BPyMesh.ngon(complete_vertlist, cur_face, PREF_FIX_LOOPS= True)
 			edge_face_count = {}
 			for mf in meta_faces:
-				# ###if DEBUG: print meta_faces
+				# These will always be tri's since they are scanfill faces
+				mf = cur_face[mf[2]], cur_face[mf[1]], cur_face[mf[0]]
+				face_data.append( [vertex_map[j] for j in mf] )
 				
-				if len(mf) == 3: #triangle
-					mf = cur_face[mf[2]], cur_face[mf[1]], cur_face[mf[0]]
-					face_data.append( [vertex_map[j] for j in mf] )
-					
-					if uv_flag: face_uvs.append(tmp_get_face_uvs(mf, i))
-					
-					#if USE_FGON:
-					if len(meta_faces) > 1:
-						mf = face_data[-1] # reuse mf
-						for i in xrange(3):
-							v1= mf[i]
-							v2= mf[i-1]
-							if v1!=v2:
-								if v1>v2:
-									v2,v1= v1,v2
-								try:
-									edge_face_count[v1,v2]+= 1
-								except:
-									edge_face_count[v1,v2]= 0
+				if uv_flag: face_uvs.append(tmp_get_face_uvs(mf, i))
 				
-				else: #quads
-					mf= cur_face[mf[3]], cur_face[mf[2]], cur_face[mf[1]], cur_face[mf[0]]
-					face_data.append( [vertex_map[j] for j in mf] )
-					if uv_flag: face_uvs.append(tmp_get_face_uvs(mf, i))
+				#if USE_FGON:
+				if len(meta_faces) > 1:
+					mf = face_data[-1] # reuse mf
+					for j in xrange(3):
+						v1= mf[j]
+						v2= mf[j-1]
+						if v1!=v2:
+							if v1>v2:
+								v2,v1= v1,v2
+							try:
+								edge_face_count[v1,v2]+= 1
+							except:
+								edge_face_count[v1,v2]= 0
+				
+
 			
 			if edge_face_count:
 				edges_fgon.extend( [vert_key for vert_key, count in edge_face_count.iteritems() if count] )
-				
 	
-	msh.edges.extend(edges)
+	if edges:
+		msh.edges.extend(edges)
+	
 	face_mapping_removed = msh.faces.extend(face_data, indexList=True)
-	if surf.has_key('TRAN') or (mat and mat.alpha<1.0): # incase mat is null
+	if 'TRAN' in surf or (mat and mat.alpha<1.0): # incase mat is null
 		transp_flag = True
 	else:
 		transp_flag = False
@@ -1347,7 +1305,7 @@
 def lookup_imag(clip_list, ima_id):
 	for ii in clip_list:
 		if ii and ii['ID'] == ima_id:
-			if ii.has_key('XREF'):
+			if 'XREF' in ii: # has_key
 				#cross reference - recursively look for images
 				return lookup_imag(clip_list, ii['XREF'])
 			else:
@@ -1415,7 +1373,7 @@
 		#if not blok['ENAB']:
 		#    ###if DEBUG: print "***Image is not ENABled! Quitting this block"
 		#    break
-		if not(blok.has_key('IMAG')):
+		if not('IMAG' in blok): # has_key
 			###if DEBUG: print "***No IMAGE for this block? Quitting"
 			break                 #extract out the image index within the clip_list
 		if blok['IMAG'] == 0: blok['IMAG'] = lastimag #experimental ....
@@ -1434,13 +1392,13 @@
 			tname += "+"
 		else:
 			tname += "x" #let's signal when should not be enabled
-		if blok.has_key('CHAN'):
+		if 'CHAN' in blok: # has_key
 			tname += blok['CHAN']
 		newtex = bpy.data.textures.new(tname)
 		newtex.setType('Image')                 # make it anu image texture
 		newtex.image = img
 		#how does it extends beyond borders
-		if blok.has_key('WRAP'):
+		if 'WRAP' in blok: # has_key
 			if (blok['WRAP'] == 3) or (blok['WRAP'] == 2):
 				newtex.setExtend('Extend')
 			elif (blok['WRAP'] == 1):
@@ -1457,35 +1415,35 @@
 		nega = False
 		mapflag = Blender.Texture.MapTo.COL  #default to color
 		maptype = Blender.Texture.Mappings.FLAT
-		if blok.has_key('CHAN'):
-			if blok['CHAN'] == 'COLR' and blok.has_key('OPACVAL'):
+		if 'CHAN' in blok: # has_key
+			if blok['CHAN'] == 'COLR' and 'OPACVAL' in blok: # has_key
 				colfac = blok['OPACVAL']
 				# Blender needs this to be clamped
 				colfac = max(0.0, min(1.0, colfac))
 				###if DEBUG: print "!!!Set Texture -> MapTo -> Col = %.3f" % colfac
 			if blok['CHAN'] == 'BUMP':
 				mapflag = Blender.Texture.MapTo.NOR
-				if blok.has_key('OPACVAL'): norfac = blok['OPACVAL']
+				if 'OPACVAL' in blok: norfac = blok['OPACVAL'] # has_key
 				###if DEBUG: print "!!!Set Texture -> MapTo -> Nor = %.3f" % norfac
 			if blok['CHAN'] == 'LUMI':
 				mapflag = Blender.Texture.MapTo.EMIT
-				if blok.has_key('OPACVAL'): dvar = blok['OPACVAL']
+				if 'OPACVAL' in blok: dvar = blok['OPACVAL'] # has_key
 				###if DEBUG: print "!!!Set Texture -> MapTo -> DVar = %.3f" % dvar
 			if blok['CHAN'] == 'DIFF':
 				mapflag = Blender.Texture.MapTo.REF
-				if blok.has_key('OPACVAL'): dvar = blok['OPACVAL']
+				if 'OPACVAL' in blok: dvar = blok['OPACVAL'] # has_key
 				###if DEBUG: print "!!!Set Texture -> MapTo -> DVar = %.3f" % dvar
 			if blok['CHAN'] == 'SPEC':
 				mapflag = Blender.Texture.MapTo.SPEC
-				if blok.has_key('OPACVAL'): dvar = blok['OPACVAL']
+				if 'OPACVAL' in blok: dvar = blok['OPACVAL'] # has_key
 				###if DEBUG: print "!!!Set Texture -> MapTo -> DVar = %.3f" % dvar
 			if blok['CHAN'] == 'TRAN':
 				mapflag = Blender.Texture.MapTo.ALPHA
-				if blok.has_key('OPACVAL'): dvar = blok['OPACVAL']
+				if 'OPACVAL' in blok: dvar = blok['OPACVAL'] # has_key
 				###if DEBUG: print "!!!Set Texture -> MapTo -> DVar = %.3f" % dvar
 				alphaflag = 1

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list