[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22566] branches/soc-2009-kazanbas/release /io: Ported X3D exporter.

Arystanbek Dyussenov arystan.d at gmail.com
Mon Aug 17 16:29:31 CEST 2009


Revision: 22566
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22566
Author:   kazanbas
Date:     2009-08-17 16:29:29 +0200 (Mon, 17 Aug 2009)

Log Message:
-----------
Ported X3D exporter.

Modified Paths:
--------------
    branches/soc-2009-kazanbas/release/io/export_3ds.py
    branches/soc-2009-kazanbas/release/io/export_x3d.py

Modified: branches/soc-2009-kazanbas/release/io/export_3ds.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_3ds.py	2009-08-17 12:48:56 UTC (rev 22565)
+++ branches/soc-2009-kazanbas/release/io/export_3ds.py	2009-08-17 14:29:29 UTC (rev 22566)
@@ -60,6 +60,22 @@
 # 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 = []
@@ -941,18 +957,10 @@
 # 	for ob in sce.objects.context:
 
 		# get derived objects
-		derived = []
+		free, derived = create_derived_objects(ob)
 
-		# ignore dupli children
-		if ob.parent and ob.parent.dupli_type != 'NONE':
-			continue
+		if derived == None: continue
 
-		if ob.dupli_type != 'NONE':
-			ob.create_dupli_list()
-			derived = [(dob.object, dob.matrix) for dob in ob.dupli_list]
-		else:
-			derived = [(ob, ob.matrix)]
-
 		for ob_derived, mat in derived:
 # 		for ob_derived, mat in getDerivedObjects(ob, False):
 
@@ -1003,8 +1011,12 @@
 						if f.material_index >= mat_ls_len:
 # 						if f.mat >= mat_ls_len:
 							f.material_index = 0
-# 							f.mat = 0
-	
+							# f.mat = 0
+
+		if free:
+			free_derived_objects(ob)
+
+
 	# Make material chunks for all materials used in the meshes:
 	for mat_and_image in materialDict.values():
 		object_info.add_subchunk(make_material_chunk(mat_and_image[0], mat_and_image[1]))

Modified: branches/soc-2009-kazanbas/release/io/export_x3d.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/export_x3d.py	2009-08-17 12:48:56 UTC (rev 22565)
+++ branches/soc-2009-kazanbas/release/io/export_x3d.py	2009-08-17 14:29:29 UTC (rev 22566)
@@ -54,10 +54,13 @@
 ####################################
 
 import math
+import os
 
 import bpy
 import Mathutils
 
+from export_3ds import create_derived_objects, free_derived_objects
+
 # import Blender
 # from Blender import Object, Lamp, Draw, Image, Text, sys, Mesh
 # from Blender.Scene import Render
@@ -166,8 +169,10 @@
 		self.file.write("<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.0//EN\" \"http://www.web3d.org/specifications/x3d-3.0.dtd\">\n")
 		self.file.write("<X3D version=\"3.0\" profile=\"Immersive\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema-instance\" xsd:noNamespaceSchemaLocation=\"http://www.web3d.org/specifications/x3d-3.0.xsd\">\n")
 		self.file.write("<head>\n")
-		self.file.write("\t<meta name=\"filename\" content=\"%s\" />\n" % sys.basename(bfile))
-		self.file.write("\t<meta name=\"generator\" content=\"Blender %s\" />\n" % Blender.Get('version'))
+		self.file.write("\t<meta name=\"filename\" content=\"%s\" />\n" % os.path.basename(bfile))
+		# self.file.write("\t<meta name=\"filename\" content=\"%s\" />\n" % sys.basename(bfile))
+		self.file.write("\t<meta name=\"generator\" content=\"Blender %s\" />\n" % '2.5')
+		# self.file.write("\t<meta name=\"generator\" content=\"Blender %s\" />\n" % Blender.Get('version'))
 		self.file.write("\t<meta name=\"translator\" content=\"X3D exporter v1.55 (2006/01/17)\" />\n")
 		self.file.write("</head>\n")
 		self.file.write("<Scene>\n")
@@ -211,9 +216,12 @@
 	'''
 	
 	def writeViewpoint(self, ob, mat, scene):
-		context = scene.render
-		ratio = float(context.imageSizeY())/float(context.imageSizeX())
-		lens = (360* (math.atan(ratio *16 / ob.data.getLens()) / math.pi))*(math.pi/180)
+		context = scene.render_data
+		# context = scene.render
+		ratio = float(context.resolution_x)/float(context.resolution_y)
+		# ratio = float(context.imageSizeY())/float(context.imageSizeX())
+		lens = (360* (math.atan(ratio *16 / ob.data.lens) / math.pi))*(math.pi/180)
+		# lens = (360* (math.atan(ratio *16 / ob.data.getLens()) / math.pi))*(math.pi/180)
 		lens = min(lens, math.pi) 
 		
 		# get the camera location, subtract 90 degress from X to orient like X3D does
@@ -221,7 +229,8 @@
 		
 		loc = self.rotatePointForVRML(mat.translationPart())
 		rot = mat.toEuler()
-		rot = (((rot[0]-90)*DEG2RAD), rot[1]*DEG2RAD, rot[2]*DEG2RAD)
+		rot = (((rot[0]-90)), rot[1], rot[2])
+		# rot = (((rot[0]-90)*DEG2RAD), rot[1]*DEG2RAD, rot[2]*DEG2RAD)
 		nRot = self.rotatePointForVRML( rot )
 		# convert to Quaternion and to Angle Axis
 		Q  = self.eulerToQuaternions(nRot[0], nRot[1], nRot[2])
@@ -237,13 +246,18 @@
 
 	def writeFog(self, world):
 		if world:
-			mtype = world.getMistype()
-			mparam = world.getMist()
-			grd = world.getHor()
+			mtype = world.mist.falloff
+			# mtype = world.getMistype()
+			mparam = world.mist
+			# mparam = world.getMist()
+			grd = world.horizon_color
+			# grd = world.getHor()
 			grd0, grd1, grd2 = grd[0], grd[1], grd[2]
 		else:
 			return
-		if (mtype == 1 or mtype == 2):
+		if (mtype == 'LINEAR' or mtype == 'INVERSE_QUADRATIC'):
+			mtype = 1 if mtype == 'LINEAR' else 2
+		# if (mtype == 1 or mtype == 2):
 			self.file.write("<Fog fogType=\"%s\" " % self.namesFog[mtype])						
 			self.file.write("color=\"%s %s %s\" " % (round(grd0,self.cp), round(grd1,self.cp), round(grd2,self.cp)))
 			self.file.write("visibilityRange=\"%s\" />\n\n" % round(mparam[2],self.cp))
@@ -256,7 +270,8 @@
 	def writeSpotLight(self, ob, mtx, lamp, world):
 		safeName = self.cleanStr(ob.name)
 		if world:
-			ambi = world.amb
+			ambi = world.ambient_color
+			# ambi = world.amb
 			ambientIntensity = ((float(ambi[0] + ambi[1] + ambi[2]))/3)/2.5
 		else:
 			ambi = 0
@@ -264,7 +279,8 @@
 
 		# compute cutoff and beamwidth
 		intensity=min(lamp.energy/1.75,1.0)
-		beamWidth=((lamp.spotSize*math.pi)/180.0)*.37;
+		beamWidth=((lamp.spot_size*math.pi)/180.0)*.37;
+		# beamWidth=((lamp.spotSize*math.pi)/180.0)*.37;
 		cutOffAngle=beamWidth*1.3
 
 		dx,dy,dz=self.computeDirection(mtx)
@@ -275,12 +291,14 @@
 		#location=(ob.matrixWorld*MATWORLD).translationPart() # now passed
 		location=(mtx*MATWORLD).translationPart()
 		
-		radius = lamp.dist*math.cos(beamWidth)
+		radius = lamp.distance*math.cos(beamWidth)
+		# radius = lamp.dist*math.cos(beamWidth)
 		self.file.write("<SpotLight DEF=\"%s\" " % safeName)
 		self.file.write("radius=\"%s\" " % (round(radius,self.cp)))
 		self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity,self.cp)))
 		self.file.write("intensity=\"%s\" " % (round(intensity,self.cp)))
-		self.file.write("color=\"%s %s %s\" " % (round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), round(lamp.col[2],self.cp)))
+		self.file.write("color=\"%s %s %s\" " % (round(lamp.color[0],self.cp), round(lamp.color[1],self.cp), round(lamp.color[2],self.cp)))
+		# self.file.write("color=\"%s %s %s\" " % (round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), round(lamp.col[2],self.cp)))
 		self.file.write("beamWidth=\"%s\" " % (round(beamWidth,self.cp)))
 		self.file.write("cutOffAngle=\"%s\" " % (round(cutOffAngle,self.cp)))
 		self.file.write("direction=\"%s %s %s\" " % (round(dx,3),round(dy,3),round(dz,3)))
@@ -290,7 +308,8 @@
 	def writeDirectionalLight(self, ob, mtx, lamp, world):
 		safeName = self.cleanStr(ob.name)
 		if world:
-			ambi = world.amb
+			ambi = world.ambient_color
+			# ambi = world.amb
 			ambientIntensity = ((float(ambi[0] + ambi[1] + ambi[2]))/3)/2.5
 		else:
 			ambi = 0
@@ -300,14 +319,16 @@
 		(dx,dy,dz)=self.computeDirection(mtx)
 		self.file.write("<DirectionalLight DEF=\"%s\" " % safeName)
 		self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity,self.cp)))
-		self.file.write("color=\"%s %s %s\" " % (round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), round(lamp.col[2],self.cp)))
+		self.file.write("color=\"%s %s %s\" " % (round(lamp.color[0],self.cp), round(lamp.color[1],self.cp), round(lamp.color[2],self.cp)))
+		# self.file.write("color=\"%s %s %s\" " % (round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), round(lamp.col[2],self.cp)))
 		self.file.write("intensity=\"%s\" " % (round(intensity,self.cp)))
 		self.file.write("direction=\"%s %s %s\" />\n\n" % (round(dx,4),round(dy,4),round(dz,4)))
 
 	def writePointLight(self, ob, mtx, lamp, world):
 		safeName = self.cleanStr(ob.name)
 		if world:
-			ambi = world.amb
+			ambi = world.ambient_color
+			# ambi = world.amb
 			ambientIntensity = ((float(ambi[0] + ambi[1] + ambi[2]))/3)/2.5
 		else:
 			ambi = 0
@@ -318,9 +339,11 @@
 		
 		self.file.write("<PointLight DEF=\"%s\" " % safeName)
 		self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity,self.cp)))
-		self.file.write("color=\"%s %s %s\" " % (round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), round(lamp.col[2],self.cp)))
+		self.file.write("color=\"%s %s %s\" " % (round(lamp.color[0],self.cp), round(lamp.color[1],self.cp), round(lamp.color[2],self.cp)))
+		# self.file.write("color=\"%s %s %s\" " % (round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), round(lamp.col[2],self.cp)))
 		self.file.write("intensity=\"%s\" " % (round( min(lamp.energy/1.75,1.0) ,self.cp)))
-		self.file.write("radius=\"%s\" " % lamp.dist )
+		self.file.write("radius=\"%s\" " % lamp.distance )
+		# self.file.write("radius=\"%s\" " % lamp.dist )
 		self.file.write("location=\"%s %s %s\" />\n\n" % (round(location[0],3), round(location[1],3), round(location[2],3)))
 	'''
 	def writeNode(self, ob, mtx):
@@ -362,24 +385,41 @@
 		vColors={}	# 'multi':1
 		meshName = self.cleanStr(ob.name)
 		
-		meshME = self.cleanStr(ob.getData(mesh=1).name) # We dont care if its the mesh name or not
+		meshME = self.cleanStr(ob.data.name) # We dont care if its the mesh name or not
+		# meshME = self.cleanStr(ob.getData(mesh=1).name) # We dont care if its the mesh name or not
 		if len(mesh.faces) == 0: return
-		mode = 0
-		if mesh.faceUV:
-			for face in mesh.faces:
-				mode |= face.mode 
+		mode = []
+		# mode = 0
+		if mesh.active_uv_texture:
+		# if mesh.faceUV:
+			for face in mesh.active_uv_texture.data:
+			# for face in mesh.faces:
+				if face.halo and 'HALO' not in mode:
+					mode += ['HALO']
+				if face.billboard and 'BILLBOARD' not in mode:
+					mode += ['BILLBOARD']

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list