[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14275] trunk/blender/release/scripts: -> FLT I/O: UI now undo safe

Geoffrey Bantle hairbat at yahoo.com
Sat Mar 29 00:06:13 CET 2008


Revision: 14275
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14275
Author:   briggs
Date:     2008-03-29 00:06:00 +0100 (Sat, 29 Mar 2008)

Log Message:
-----------
-> FLT I/O: UI now undo safe

Both the FLT importer and exporter now store and retrieve
their settings from the blender python registry making
them safe for use with global undo.

Modified Paths:
--------------
    trunk/blender/release/scripts/flt_export.py
    trunk/blender/release/scripts/flt_import.py

Modified: trunk/blender/release/scripts/flt_export.py
===================================================================
--- trunk/blender/release/scripts/flt_export.py	2008-03-28 21:04:27 UTC (rev 14274)
+++ trunk/blender/release/scripts/flt_export.py	2008-03-28 23:06:00 UTC (rev 14275)
@@ -47,45 +47,51 @@
 
 FF = FileFinder()
 records = process_recordDefs()
-
+		
 class ExporterOptions:
+	
+	def read_state(self):
+		reg = Blender.Registry.GetKey('flt_export',1)
+		if reg:
+			for key in self.state:
+				if reg.has_key(key):
+					self.state[key] = reg[key]
+	
+	def write_state(self):
+		d = dict()
+		for key in self.state:
+			d[key] = self.state[key]
+			Blender.Registry.SetKey('flt_export', d, 1) 
 	def __init__(self):
 		self.verbose = 1
 		self.tolerance = 0.001
 		self.writevcol = True
 		
-		#new stuff
-		self.export_shading = 0
-		self.shading_default = 45.0
-		self.basepath = os.path.dirname(Blender.Get('filename'))
-		self.scale = 1.0
-		
-		#set externals path
-		if(os.path.exists(os.path.join(self.basepath,'externals'))):
-			self.externalspath = os.path.join(self.basepath,'externals')
+		self.state = {'export_shading' : 0, 
+				'shading_default' : 45, 
+				'basepath' : os.path.dirname(Blender.Get('filename')),
+				'scale': 1.0,
+				'doxrefs' : 1,
+				'attrib' : 0,
+				'copytex' : 0,
+				'transform' : 0,
+				'xapp' : 1}
+				
+		#default externals path
+		if(os.path.exists(os.path.join(self.state['basepath'],'externals'))):
+			self.state['externalspath'] = os.path.join(self.state['basepath'],'externals')
 		else:
-			self.externalspath = self.basepath 
+			self.state['externalspath'] = self.state['basepath'] 
 		
-		self.doxrefs = 1
-		
-		#texture options
-		if(os.path.exists(os.path.join(self.basepath,'textures'))):
-			self.texturespath = os.path.join(self.basepath,'textures')
+		if(os.path.exists(os.path.join(self.state['basepath'],'textures'))):
+			self.state['texturespath'] = os.path.join(self.state['basepath'],'textures')
 		else:
-			self.texturespath = self.basepath
+			self.state['texturespath'] = self.state['basepath']
+
+		self.state['xappath'] = ''
+		self.read_state() #read from registry
 		
-		#misc
-		self.write_attrib_files = 0
-		self.copy_textures = 0
-		self.export_transform = 0
-		self.flattenmesh = False
 		
-		self.xapp = 1
-		reg = Blender.Registry.GetKey('flt_export',1)
-		if(reg and 'xappath' in reg.keys()):
-			self.xappath = reg['xappath']
-		else:
-			self.xappath = ''
 options = ExporterOptions()
 tex_files = dict() #a list of (possibly) modified texture path names
 
@@ -221,7 +227,7 @@
 		indexhash = self.namehash[object.name]
 		
 		#export in global space? THIS HAS BEEN MADE REDUNDANT... REMOVE ME
-		if not options.export_transform:
+		if not options.state['transform']:
 			vertex = shadowVert(vertex,object,True,flatShadeNorm)
 		else:
                         vertex = shadowVert(vertex,object,False,flatShadeNorm)
@@ -463,9 +469,9 @@
 		self.object = object
 		if object:
 			self.name = self.object.name
-			if not options.export_transform:
+			if not options.state['transform']:
 				oloc = Blender.Mathutils.Vector(object.getLocation('worldspace'))
-				vec = Blender.Mathutils.Vector(oloc[0] * options.scale, oloc[1] * options.scale, oloc[2] * options.scale) #scale
+				vec = Blender.Mathutils.Vector(oloc[0] * options.state['scale'], oloc[1] * options.state['scale'], oloc[2] * options.state['scale']) #scale
 				self.matrix =  self.object.getMatrix('worldspace') *  Blender.Mathutils.TranslationMatrix(vec - oloc)			
 			else:
 				self.matrix = self.object.getMatrix('localspace') #do matrix mult here.
@@ -802,13 +808,13 @@
 			self.exportmesh.getFromObject(self.object.name)			
 
 			for vert in self.exportmesh.verts:
-				if not options.export_transform:
+				if not options.state['transform']:
 					vec = vert.co
-					vec = Blender.Mathutils.Vector(vec[0] * options.scale, vec[1] * options.scale, vec[2] * options.scale) #scale
+					vec = Blender.Mathutils.Vector(vec[0] * options.state['scale'], vec[1] * options.state['scale'], vec[2] * options.state['scale']) #scale
 					vert.co =  Blender.Mathutils.TranslationMatrix(vec) * (vert.co * self.object.getMatrix('worldspace'))						
 				
-				if options.scale != 1.0:
-					vert.co = vert.co * options.scale
+				if options.state['scale'] != 1.0:
+					vert.co = vert.co * options.state['scale']
 
 			if("FLT_VCOL") in self.mesh.verts.properties:
 				for v in self.exportmesh.verts:
@@ -825,7 +831,7 @@
 			default = None
 
 
-			if options.export_shading:
+			if options.state['export_shading']:
 				mods = self.object.modifiers
 				hasedsplit = False
 				for mod in mods:
@@ -834,7 +840,7 @@
 						break
 				if not hasedsplit:
 					default = mods.append(Modifier.Types.EDGESPLIT)
-					default[Modifier.Settings.EDGESPLIT_ANGLE] = options.shading_default
+					default[Modifier.Settings.EDGESPLIT_ANGLE] = options.state['shading_default']
 					default[Modifier.Settings.EDGESPLIT_FROM_ANGLE] = True
 					default[Modifier.Settings.EDGESPLIT_FROM_SHARP] = False
 					self.object.makeDisplayList()
@@ -843,17 +849,17 @@
 
 			#recalculate vertex positions
 			for vert in self.exportmesh.verts:
-				if not options.export_transform:
+				if not options.state['transform']:
 					vec = vert.co
-					vec = Blender.Mathutils.Vector(vec[0] * options.scale, vec[1] * options.scale, vec[2] * options.scale) #scale
+					vec = Blender.Mathutils.Vector(vec[0] * options.state['scale'], vec[1] * options.state['scale'], vec[2] * options.state['scale']) #scale
 					vert.co =  Blender.Mathutils.TranslationMatrix(vec) * (vert.co * self.object.getMatrix('worldspace'))						
 				
-				if options.scale != 1.0:
-					vert.co = vert.co * options.scale			
+				if options.state['scale'] != 1.0:
+					vert.co = vert.co * options.state['scale']			
 			
 			flipped = self.object.getMatrix('worldspace').determinant()
 			
-			if not options.export_transform:
+			if not options.state['export_transform']:
 				self.exportmesh.calcNormals()
 			
 
@@ -885,7 +891,7 @@
 			self.buildNormFaces()
 			self.buildTexData()
 			
-			if not options.export_transform:
+			if not options.state['export_transform']:
 				if flipped < 0:
 					for vdesc in self.header.GRR.vertex_lst:
 						vdesc.accum = 0
@@ -1041,9 +1047,9 @@
 			if self.props.has_key(key):
 				exportdict[key] = self.props[key]
 
-                if self.opcode == 63 and options.externalspath:
+                if self.opcode == 63 and options.state['externalspath']:
 				try:
-					exportdict['3t200!filename'] = os.path.join(options.externalspath,self.object.DupGroup.name+'.flt')
+					exportdict['3t200!filename'] = os.path.join(options.state['externalspath'],self.object.DupGroup.name+'.flt')
 					self.header.xrefnames.append(self.object.DupGroup.name)
 				except:
 					pass
@@ -1071,7 +1077,7 @@
 
 		self.write_longid(self.name) #fix this!
 		
-		if options.export_transform or self.opcode == 63:
+		if options.state['export_transform'] or self.opcode == 63:
 			#writing transform matrix....
 			self.write_matrix()
 
@@ -1234,21 +1240,16 @@
 
 		self.write_push()
 		
-		if options.flattenmesh:
-			self.mnodes.reverse()
-			for mnode in self.mnodes:
-				mnode.write_faces()
-		else:
-			for child in self.children:
-				child.write()
+		for child in self.children:
+			child.write()
 		self.write_pop()
 	
 	def export_textures(self,texturepath):
 		for i in xrange(self.GRR.texture_count()):
 			texture = self.GRR.texture_lst[i]
 			
-			if options.copy_textures:
-				filename = os.path.normpath(os.path.join(options.texturespath, os.path.basename(self.GRR.request_texture_filename(i))))
+			if options.state['copytex']:
+				filename = os.path.normpath(os.path.join(options.state['texturespath'], os.path.basename(self.GRR.request_texture_filename(i))))
 			else:
 				filename = os.path.normpath(self.GRR.request_texture_filename(i))
 			
@@ -1335,10 +1336,10 @@
 	global xrefsdone
 	global options
 
-	if exportlevel == 0 or not options.externalspath:
-		fname = os.path.join(options.basepath,scene.name + '.flt')
+	if exportlevel == 0 or not options.state['externalspath']:
+		fname = os.path.join(options.state['basepath'],scene.name + '.flt')
 	else:
-		fname = os.path.join(options.externalspath,scene.name + '.flt')
+		fname = os.path.join(options.state['externalspath'],scene.name + '.flt')
 	
 	fw = FltOut(fname)
 	db = Database(scene,fw)
@@ -1352,7 +1353,7 @@
 	db.write()
 	fw.close_file()
 	
-	if options.doxrefs:
+	if options.state['doxrefs']:
 		for xname in xreflist:
 			try:
 				xrefscene = Blender.Scene.Get(xname)
@@ -1387,7 +1388,7 @@
 	Blender.Window.WaitCursor(False)
 	
 	#optional: Copy textures
-	if options.copy_textures:
+	if options.state['copy_textures']:
 		for imgname in tex_files:
 			#Check to see if texture exists in target directory
 			if not os.path.exists(tex_files[imgname]):
@@ -1398,11 +1399,11 @@
 					shutil.copyfile(origpath,tex_files[imgname])
 	
 	#optional: Write attribute files
-	if options.write_attrib_files:
+	if options.state['attrib']:
 		write_attribute_files()
 
-	if options.xapp:
-		cmd= options.xappath + " " + fname 
+	if options.state['xapp']:
+		cmd= options.state['xappath'] + " " + fname 
 		status = os.system(cmd)
 	
 
@@ -1442,31 +1443,28 @@
 
 def setshadingangle(ID,val):
 	global options
-	options.shading_default = val
+	options.state['shading_default'] = val
 def setBpath(fname):
 	global options
-	options.basepath = os.path.dirname(fname)
+	options.state['basepath'] = os.path.dirname(fname)
 	#update xref and textures path too....
-	if(os.path.exists(os.path.join(options.basepath,'externals'))):
-		options.externalspath = os.path.join(options.basepath,'externals')
-	if(os.path.exists(os.path.join(options.texturespath,'textures'))):
-		options.texturespath = os.path.join(options.basepath,'textures')
+	if(os.path.exists(os.path.join(options.state['basepath'],'externals'))):
+		options.state['externalspath'] = os.path.join(options.state['basepath'],'externals')
+	if(os.path.exists(os.path.join(options.state['basepath'],'textures'))):
+		options.state['texturespath'] = os.path.join(options.state['basepath'],'textures')
 def setexportscale(ID,val):
 	global options
-	options.scale = val
+	options.state['scale'] = val
 
 def setTpath(fname):
 	global options
-	options.texturespath = os.path.dirname(fname)
+	options.state['texturespath'] = os.path.dirname(fname)
 def setXpath(fname):
 	global options
-	options.externalspath = os.path.dirname(fname)

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list