[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14475] branches/apricot: changes from trunk

Campbell Barton ideasman42 at gmail.com
Sat Apr 19 13:26:51 CEST 2008


Revision: 14475
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14475
Author:   campbellbarton
Date:     2008-04-19 13:26:51 +0200 (Sat, 19 Apr 2008)

Log Message:
-----------
changes from trunk

Modified Paths:
--------------
    branches/apricot/release/scripts/md2_export.py
    branches/apricot/release/scripts/md2_import.py
    branches/apricot/source/blender/blenkernel/intern/depsgraph.c
    branches/apricot/source/blender/blenkernel/intern/object.c
    branches/apricot/source/blender/include/blendef.h
    branches/apricot/source/blender/render/intern/source/initrender.c
    branches/apricot/source/blender/src/buttons_editing.c
    branches/apricot/source/blender/src/buttons_shading.c
    branches/apricot/source/blender/src/editobject.c
    branches/apricot/source/gameengine/Ketsji/BL_Shader.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp

Modified: branches/apricot/release/scripts/md2_export.py
===================================================================
--- branches/apricot/release/scripts/md2_export.py	2008-04-19 11:23:50 UTC (rev 14474)
+++ branches/apricot/release/scripts/md2_export.py	2008-04-19 11:26:51 UTC (rev 14475)
@@ -8,7 +8,7 @@
 """
 
 __author__ = 'Bob Holcomb'
-__version__ = '0.18.1'
+__version__ = '0.18.1 patch 1'
 __url__ = ["Bob's site, http://bane.servebeer.com",
      "Support forum, http://bane.servebeer.com", "blender", "elysiun"]
 __email__ = ["Bob Holcomb, bob_holcomb:hotmail*com", "scripts"]
@@ -19,6 +19,12 @@
  Thanks Guys!
 """
 
+# This is a PATCHED VERSION, fixing the bug due to which animations would
+# (almost) never work.  It is now also possible to output a MD2 model without
+# texture.
+# On: 23 january 2008
+# By: Boris van Schooten (schooten at cs.utwente.nl)
+
 # ***** BEGIN GPL LICENSE BLOCK *****
 #
 # Script copyright (C): Bob Holcomb
@@ -105,13 +111,13 @@
 	g_filename = String("MD2 file to save: ", EVENT_NOEVENT, 10, 75, 210, 18,
                             g_filename.val, 255, "MD2 file to save")
 	########## MD2 File Search Button
-	Button("Search",EVENT_CHOOSE_FILENAME,220,75,80,18)
+	Button("Browse",EVENT_CHOOSE_FILENAME,220,75,80,18)
 
 	##########  MD2 Frame List Text entry
 	g_frame_filename = String("Frame List file to load: ", EVENT_NOEVENT, 10, 55, 210, 18,
                                 g_frame_filename.val, 255, "Frame List to load-overrides MD2 defaults")
 	########## Frame List Search Button
-	Button("Search",EVENT_CHOOSE_FRAME,220,55,80,18)
+	Button("Browse",EVENT_CHOOSE_FRAME,220,55,80,18)
 	
 	##########  Texture path to append
 	g_texture_path=String("Texture Path: ", EVENT_NOEVENT, 10,35,210,18,
@@ -143,14 +149,9 @@
 	elif (evt==EVENT_CHOOSE_FRAME):
 		FileSelector(frame_callback, "Frame Selection")
 	elif (evt==EVENT_SAVE_MD2):
-		if (g_filename.val == "model"):
-			save_md2("blender.md2")
-			Blender.Draw.Exit()
-			return
-		else:
-			save_md2(g_filename.val)
-			Blender.Draw.Exit()
-			return
+		save_md2(g_filename.val)
+		Blender.Draw.Exit()
+		return
 
 Register(draw_gui, event, bevent)
 
@@ -616,21 +617,24 @@
 
 	#move the object to the origin if it's not already there
 	if object.getLocation('worldspace')!=(0.0, 0.0, 0.0):
-		object.setLocation(0.0,0.0,0.0)
-		print "Model not centered at origin-Centering"
-		result=Blender.Draw.PupMenu("Model not centered at origin-Centering for you")
+		print "Model not centered at origin"
+		result=Blender.Draw.PupMenu("Model not centered at origin%t|Center (will not work with animations!)|Do not center")
+		if result==1:
+			object.setLocation(0.0,0.0,0.0)
 
 	#resize the object in case it is not the right size
 	if object.getSize('worldspace')!=(1.0,1.0,1.0):
-		object.setSize(1.0,1.0,1.0)
 		print "Object is scaled-You should scale the mesh verts, not the object"
-		result=Blender.Draw.PupMenu("Object is scaled-You should scale the mesh verts, not the object-fixing for you")
+		result=Blender.Draw.PupMenu("Object is scaled-You should scale the mesh verts, not the object%t|Fix scale (will not work with animations!)|Do not scale")
+		if result==1:
+			object.setSize(1.0,1.0,1.0)
 		
 	if object.getEuler('worldspace')!=Blender.Mathutils.Euler(0.0,0.0,0.0):
 		print "object.rot: ", object.getEuler('worldspace')
-		object.setEuler([0.0,0.0,0.0])
 		print "Object is rotated-You should rotate the mesh verts, not the object"
-		result=Blender.Draw.PupMenu("Object is rotated-You should rotate the mesh verts, not the object-fixing for you")
+		result=Blender.Draw.PupMenu("Object is rotated-You should rotate the mesh verts, not the object%t|Fix rotation (will not work with animations!)|Do not rotate")
+		if result==1:
+			object.setEuler([0.0,0.0,0.0])
 	
 	#get access to the mesh data
 	mesh=object.getData(False, True) #get the object (not just name) and the Mesh, not NMesh
@@ -643,7 +647,7 @@
 			face.sel=1
 			if result==0:  #first time we have this problem, don't pop-up a window every time it finds a quad
 			  print "Model not made entirely of triangles"
-			  result=Blender.Draw.PupMenu("Model not made entirely out of Triangles-Convert?%t|YES|NO")
+			  result=Blender.Draw.PupMenu("Model not made entirely out of Triangles-Convert?%t|YES|Quit")
 	
 	#triangulate or quit
 	if result==1:
@@ -672,36 +676,34 @@
 	
 	else:
 		print "Model does not have UV (face or vertex)"
-		result=Blender.Draw.PupMenu("Model does not have UV (face or vertex)%t|Quit")
-		return False
+		result=Blender.Draw.PupMenu("Model does not have UV (face or vertex)%t|Output (0,0) as UV coordinates and do not generate GL commands|Quit")
+		if result==2:
+			return False
 
 	#check it has an associated texture map
 	last_face=""
-	last_face=mesh.faces[0].image
-	if last_face=="":
-		print "Model does not have a texture Map"
-		result=Blender.Draw.PupMenu("Model does not have a texture Map%t|Quit")
-		return False
+	if mesh.faceUV:
+		last_face=mesh.faces[0].image
+		#check if each face uses the same texture map (only one allowed)
+		for face in mesh.faces:
+			mesh_image=face.image
+			if not mesh_image:
+				print "Model has a face without a texture Map"
+				result=Blender.Draw.PupMenu("Model has a face without a texture Map%t|This should never happen!")
+				#return False
+			if mesh_image!=last_face:
+				print "Model has more than 1 texture map assigned"
+				result=Blender.Draw.PupMenu("Model has more than 1 texture map assigned%t|Quit")
+				#return False
+		if mesh_image:
+			size=mesh_image.getSize()
+			#is this really what the user wants
+			if (size[0]!=256 or size[1]!=256):
+				print "Texture map size is non-standard (not 256x256), it is: ",size[0],"x",size[1]
+				result=Blender.Draw.PupMenu("Texture map size is non-standard (not 256x256), it is: "+str(size[0])+"x"+str(size[1])+": Continue?%t|YES|NO")
+				if(result==2):
+					return False
 
-	#check if each face uses the same texture map (only one allowed)
-	for face in mesh.faces:
-		mesh_image=face.image
-		if not mesh_image:
-			print "Model has a face without a texture Map"
-			result=Blender.Draw.PupMenu("Model has a face without a texture Map%t|Quit")
-			return False
-		if mesh_image!=last_face:
-			print "Model has more than 1 texture map assigned"
-			result=Blender.Draw.PupMenu("Model has more than 1 texture map assigned%t|Quit")
-			return False
-		
-	size=mesh_image.getSize()
-	#is this really what the user wants
-	if (size[0]!=256 or size[1]!=256):
-		print "Texture map size is non-standard (not 256x256), it is: ",size[0],"x",size[1]
-		result=Blender.Draw.PupMenu("Texture map size is non-standard (not 256x256), it is: "+str(size[0])+"x"+str(size[1])+": Continue?%t|YES|NO")
-		if(result==2):
-			return False
 
 	#verify frame list data
 	user_frame_list=get_frame_list()	
@@ -743,7 +745,8 @@
 	
 	#get a Mesh, not NMesh
 	mesh=object.getData(False, True)	
-	
+	#don't forget to copy the data! -- Boris van Schooten
+	mesh=mesh.__copy__();
 	#load up some intermediate data structures
 	tex_list={}
 	tex_count=0
@@ -758,31 +761,35 @@
 
 	#get the skin information
 	#use the first faces' image for the texture information
-	mesh_image=mesh.faces[0].image
-	size=mesh_image.getSize()
-	md2.skin_width=size[0]
-	md2.skin_height=size[1]
-	md2.num_skins=1
-	#add a skin node to the md2 data structure
-	md2.skins.append(md2_skin())
-	md2.skins[0].name=g_texture_path.val+Blender.sys.basename(mesh_image.getFilename())
-	if len(md2.skins[0].name)>64:
-		print "Texture Path and name is more than 64 characters"
-		result=Blender.Draw.PupMenu("Texture path and name is more than 64 characters-Quitting")
-		return False
+	if mesh.faceUV:
+		mesh_image=mesh.faces[0].image
+		size=mesh_image.getSize()
+		md2.skin_width=size[0]
+		md2.skin_height=size[1]
+		md2.num_skins=1
+		#add a skin node to the md2 data structure
+		md2.skins.append(md2_skin())
+		md2.skins[0].name=g_texture_path.val+Blender.sys.basename(mesh_image.getFilename())
+		if len(md2.skins[0].name)>64:
+			print "Texture Path and name is more than 64 characters"
+			result=Blender.Draw.PupMenu("Texture path and name is more than 64 characters-Quitting")
+			return False
 
 	#put texture information in the md2 structure
 	#build UV coord dictionary (prevents double entries-saves space)
 	for face in mesh.faces:
-		for i in range(0,3):
-			t=(face.uv[i])
+		for i in xrange(0,3):
+			if mesh.faceUV:
+				t=(face.uv[i])
+			else:
+				t=(0,0)
 			tex_key=(t[0],t[1])
 			if not tex_list.has_key(tex_key):
 				tex_list[tex_key]=tex_count
 				tex_count+=1
 	md2.num_tex_coords=tex_count #each vert has its own UV coord
 
-	for this_tex in range (0, md2.num_tex_coords):
+	for this_tex in xrange (0, md2.num_tex_coords):
 		md2.tex_coords.append(md2_tex_coord())
 	for coord, index in tex_list.iteritems():
 		#md2.tex_coords.append(md2_tex_coord())
@@ -791,13 +798,16 @@
 
 	#put faces in the md2 structure
 	#for each face in the model
-	for this_face in range(0, md2.num_faces):
+	for this_face in xrange(0, md2.num_faces):
 		md2.faces.append(md2_face())
-		for i in range(0,3):
+		for i in xrange(0,3):
 			#blender uses indexed vertexes so this works very well
 			md2.faces[this_face].vertex_index[i]=mesh.faces[this_face].verts[i].index
 			#lookup texture index in dictionary
-			uv_coord=(mesh.faces[this_face].uv[i])
+			if mesh.faceUV:
+				uv_coord=(mesh.faces[this_face].uv[i])
+			else:
+				uv_coord=(0,0)
 			tex_key=(uv_coord[0],uv_coord[1])
 			tex_index=tex_list[tex_key]
 			md2.faces[this_face].texture_index[i]=tex_index
@@ -824,7 +834,7 @@
 	progressIncrement=0.25/md2.num_frames
 
 	#fill in each frame with frame info and all the vertex data for that frame
-	for frame_counter in range(0,md2.num_frames):
+	for frame_counter in xrange(0,md2.num_frames):
 		
 		progress+=progressIncrement
 		Blender.Window.DrawProgressBar(progress, "Calculating Frame: "+str(frame_counter))
@@ -865,6 +875,10 @@
 		frame_scale_y=(frame_max_y-frame_min_y)/255
 		frame_scale_z=(frame_max_z-frame_min_z)/255
 		
+		if frame_scale_x == 0: frame_scale_x = 1.0
+		if frame_scale_y == 0: frame_scale_y = 1.0
+		if frame_scale_z == 0: frame_scale_z = 1.0
+		
 		#translate value of the mesh to center it on the origin
 		frame_trans_x=frame_min_x
 		frame_trans_y=frame_min_y
@@ -875,7 +889,7 @@
 		md2.frames[frame_counter].translate=(-frame_trans_x, frame_trans_y, frame_trans_z)
 		
 		#now for the vertices
-		for vert_counter in range(0, md2.num_vertices):

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list