Răsfoiți Sursa

Trying to find a way to treat the two passes. Material and depth
*Changes the blenderscripts/mesh.py to accept an initializer class

Panagiotis Christopoulos Charitos 16 ani în urmă
părinte
comite
ea82889c03

+ 12 - 8
blenderscripts/main.py

@@ -11,9 +11,6 @@ reload( sys.modules["mesh"] )
 from skeleton import *
 reload( sys.modules["skeleton"] )
 
-from vweights import *
-reload( sys.modules["vweights"] )
-
 from material import *
 reload( sys.modules["material"] )
 
@@ -28,12 +25,19 @@ if len(objs) < 1:
 	ERROR( "Not selected objs" )
 
 for obj in objs:
-	mesh = GetMesh( obj )
-	mtl = GetMaterial( mesh )
-	skel = GetSkeleton( obj )
+	mi = mesh_init_t()
+	
+	mi.mesh = GetMesh( obj )
+	mi.skeleton = GetSkeleton( obj )
+	mi.save_path = path
+	mi.write_comments = true
+	mtl = GetMaterial( mi.mesh )
+	mi.material_filename = "models/imp/" + mtl.getName() + ".mtl"
+	
+	
 	
-	ExportMesh( path, mesh, skel, "models/imp/" + mtl.getName() + ".mtl" , cmnts )
-	ExportSkeleton( path, skel, cmnts )
+	ExportMesh( mi )
+	#ExportSkeleton( path, skel, cmnts )
 	#ExportVWeights( path, mesh, skel, cmnts )
 	#ExportMaterial( path, epath, mtl, cmnts )
 

+ 116 - 95
blenderscripts/mesh.py

@@ -3,6 +3,17 @@ from common import *
 reload( sys.modules["common"] )
 
 
+#===================================================================================================
+# mesh_init_t                                                                                      =
+#===================================================================================================
+class mesh_init_t:
+	mesh = NULL
+	skeleton = NULL
+	material_filename = "*put material filename*"
+	write_comments = false
+	save_path = ""
+	
+
 #===================================================================================================
 # GetMesh                                                                                          =
 #===================================================================================================
@@ -18,11 +29,99 @@ def GetMesh( obj ):
 	mesh = obj.getData( 0, 1 ) 
 	return mesh
 
+
+#===================================================================================================
+# ScriptVWeights                                                                                   =
+#===================================================================================================
+def ScriptVWeights( mesh_init ):
+	mesh = mesh_init.mesh
+	skeleton = mesh_init.skeleton
+	b_cmnts = mesh_init.write_comments
+
+	#check if mesh is the correct class
+	if( mesh.__class__.__name__ != "Blender Mesh" ):
+		ERROR( "The given func param is not a \"Blender Mesh\" class but a \"" + mesh.__class__.__name__ + "\"" )
+		return "error"
+	
+	#check if skeleton is the correct class
+	if( skeleton.__class__.__name__ != "Armature" ):
+		ERROR( "The given func param is not a \"Armature\" class but a \"" + skeleton.__class__.__name__ + "\"" )
+		return "error"
+	
+	bone_names = skeleton.bones.keys()
+	bone_names.sort()
+	
+	# init text
+	ftxt = ""
+	
+	# link the vert groups to the bone ids
+	vgroup2bone_id = {}   # we give the vgroup name and we get the bone's id in the skeleton
+	vgroup_names = mesh.getVertGroupNames()
+	
+	for vgroup_name in vgroup_names:
+		bone_id = -1
+		for bone_name in bone_names:
+			if bone_name == vgroup_name:
+				bone_id = bone_names.index( bone_name )
+				break
+		
+		if bone_id == -1:
+			WARNING( "Vert group \"" + vgroup_name + "\" cant link to a bone" )
+		
+		vgroup2bone_id[ vgroup_name ] = bone_id
+	
+	if( b_cmnts ):ftxt += "/*VERT_WEIGHTS*/ "
+	ftxt += str( len( mesh.verts ) ) + "\n"
+	
+	# for every vert do some shit
+	for vert in mesh.verts:
+		influences = mesh.getVertexInfluences( vert.index )
+		
+		influences_num = 0
+		sumw = 0.0
+		# calc the influences num and the total weight (NOTE:we may have...
+		# ...a vert group that doesnt connect to a bone)
+		for influence in influences:
+			vgroup = influence[0]
+			weight = influence[1]
+			
+			if vgroup2bone_id[ vgroup ] != -1:
+				influences_num = influences_num + 1
+				sumw = sumw + weight
+		
+		# a check
+		if( influences_num > 4 ):
+			ERROR( "Cannot have more than 4 bones per vert" );
+			return "error"
+	
+		# write to file
+		if( b_cmnts ): ftxt += "\t/*VERT_ID " + str( vert.index ) + "*/\n"
+		
+		if( b_cmnts ): ftxt += "\t/*BONE_CONNECTIONS*/ "
+		ftxt += str( influences_num ) + "\n"
+				
+		for influence in influences:
+			vgroup = influence[0]
+			weight = influence[1]
+			
+			if vgroup2bone_id[ vgroup ] != -1:	
+				if( b_cmnts ): ftxt += "\t\t/*BONE_ID*/ "
+				ftxt += str( vgroup2bone_id[ vgroup ] ) + " "
+				if( b_cmnts ): ftxt += "/*WEIGHT*/ "
+				ftxt += str( weight/sumw ) + "\n"
+	# end for all verts
+	
+	return ftxt
+	
 		
 #===================================================================================================
 # ScriptMesh                                                                                       =
 #===================================================================================================
-def ScriptMesh( mesh, mtl_fname, b_cmnts ):
+def ScriptMesh( mesh_init ):
+	mesh = mesh_init.mesh
+	b_cmnts = mesh_init.write_comments
+	skeleton = mesh_init.skeleton
+
 	#check if mesh is the correct class
 	if( mesh.__class__.__name__ != "Blender Mesh" ):
 		ERROR( "The given func param is not a \"Blender Mesh\" class but a \"" + mesh.__class__.__name__ + "\"" )
@@ -43,7 +142,7 @@ def ScriptMesh( mesh, mtl_fname, b_cmnts ):
 	
 	# material
 	if(b_cmnts): ftxt += "/*MATERIAL*/ "
-	ftxt += "\"" + mtl_fname + "\"\n"
+	ftxt += "\"" + mesh_init.material_filename + "\"\n"
 	
 	# the verts
 	if(b_cmnts): ftxt += "/*VERTS*/ "
@@ -157,87 +256,15 @@ def ScriptMesh( mesh, mtl_fname, b_cmnts ):
 		if(b_cmnts): ftxt += "\t/*VERT_ID " + str(i) + " UV_COORDS*/ "
 				
 		ftxt += str( vertuvs[i][0] ) + " " + str( vertuvs[i][1] ) + "\n"
-	
-	
-	return ftxt
-
-
-#===================================================================================================
-# ScriptVWeights                                                                                   =
-#===================================================================================================
-def ScriptVWeights( mesh, skeleton, b_cmnts ):
-	#check if mesh is the correct class
-	if( mesh.__class__.__name__ != "Blender Mesh" ):
-		ERROR( "The given func param is not a \"Blender Mesh\" class but a \"" + mesh.__class__.__name__ + "\"" )
-		return "error"
-	
-	#check if skeleton is the correct class
-	if( skeleton.__class__.__name__ != "Armature" ):
-		ERROR( "The given func param is not a \"Armature\" class but a \"" + skeleton.__class__.__name__ + "\"" )
-		return "error"
-	
-	bone_names = skeleton.bones.keys()
-	bone_names.sort()
-	
-	# init text
-	ftxt = ""
-	
-	# link the vert groups to the bone ids
-	vgroup2bone_id = {}   # we give the vgroup name and we get the bone's id in the skeleton
-	vgroup_names = mesh.getVertGroupNames()
-	
-	for vgroup_name in vgroup_names:
-		bone_id = -1
-		for bone_name in bone_names:
-			if bone_name == vgroup_name:
-				bone_id = bone_names.index( bone_name )
-				break
-		
-		if bone_id == -1:
-			WARNING( "Vert group \"" + vgroup_name + "\" cant link to a bone" )
 		
-		vgroup2bone_id[ vgroup_name ] = bone_id
-	
-	if( b_cmnts ):ftxt += "/*VERT_WEIGHTS*/ "
-	ftxt += str( len( mesh.verts ) ) + "\n"
-	
-	# for every vert do some shit
-	for vert in mesh.verts:
-		influences = mesh.getVertexInfluences( vert.index )
-		
-		influences_num = 0
-		sumw = 0.0
-		# calc the influences num and the total weight (NOTE:we may have...
-		# ...a vert group that doesnt connect to a bone)
-		for influence in influences:
-			vgroup = influence[0]
-			weight = influence[1]
-			
-			if vgroup2bone_id[ vgroup ] != -1:
-				influences_num = influences_num + 1
-				sumw = sumw + weight
-		
-		# a check
-		if( influences_num > 4 ):
-			ERROR( "Cannot have more than 4 bones per vert" );
-			return "error"
+	# and now the vertex weights
+	if skeleton != NULL:
+		ftxt += ScriptVWeights( mesh_init )
+	else:
+		if b_cmnts:
+			ftxt += "/*VERT_WEIGHTS*/ "
+		ftxt += "0"
 	
-		# write to file
-		if( b_cmnts ): ftxt += "\t/*VERT_ID " + str( vert.index ) + "*/\n"
-		
-		if( b_cmnts ): ftxt += "\t/*BONE_CONNECTIONS*/ "
-		ftxt += str( influences_num ) + "\n"
-				
-		for influence in influences:
-			vgroup = influence[0]
-			weight = influence[1]
-			
-			if vgroup2bone_id[ vgroup ] != -1:	
-				if( b_cmnts ): ftxt += "\t\t/*BONE_ID*/ "
-				ftxt += str( vgroup2bone_id[ vgroup ] ) + " "
-				if( b_cmnts ): ftxt += "/*WEIGHT*/ "
-				ftxt += str( weight/sumw ) + "\n"
-	# end for all verts
 	
 	return ftxt
 
@@ -245,7 +272,10 @@ def ScriptVWeights( mesh, skeleton, b_cmnts ):
 #===================================================================================================
 # ExportMesh                                                                                       =
 #===================================================================================================
-def ExportMesh( path, mesh, skeleton, mtl_fname, b_cmnts ):
+def ExportMesh( mesh_init ):
+	mesh = mesh_init.mesh
+	skeleton = mesh_init.skeleton
+	
 	#check if mesh is the correct class
 	if mesh.__class__.__name__ != "Blender Mesh":
 		ERROR( "The given func param is not a \"Blender Mesh\" class but a \"" + mesh.__class__.__name__ + "\"" )
@@ -258,17 +288,8 @@ def ExportMesh( path, mesh, skeleton, mtl_fname, b_cmnts ):
 			return false
 	
 	INFO( "Trying to export mesh \"" + mesh.name + "\"" )
-	
-	filename = path + mesh.name + ".mesh"
-	
-	str = ScriptMesh( mesh, mtl_fname, b_cmnts );
-	if skeleton != NULL:
-		str += ScriptVWeights( mesh, skeleton, b_cmnts )
-	else:
-		if b_cmnts:
-			str += "/*VERT_WEIGHTS*/ "
-		str += "0"
-	
-	WriteFile( filename, str )
-	
+	filename = mesh_init.save_path + mesh.name + ".mesh"
+	WriteFile( filename, ScriptMesh( mesh_init ) )
 	INFO( "Mesh exported!! \"" + filename + "\"" )	
+	
+	

+ 4 - 6
src/renderer/r_private.h

@@ -132,7 +132,7 @@ void RenderDepth( type_t& t )
 		r::is::shadows::shdr_depth_grass->Bind();
 		r::is::shadows::shdr_depth_grass->LocTexUnit( r::is::shadows::shdr_depth_grass->GetUniformLocation(0), *t.material->grass_map, 0 );
 	}
-	else if( t.material->attribute_locs.vert_weight_bones_num != -1 )
+	else if( t.material->attrib_locs.vert_weight_bones_num != -1 )
 	{
 		r::is::shadows::shdr_depth_hw_skinning->Bind();
 	}
@@ -157,11 +157,9 @@ void RenderDepth( type_t& t )
 }
 
 
-/*
-=======================================================================================================================================
-Render                                                                                                                                =
-=======================================================================================================================================
-*/
+//=====================================================================================================================================
+// Render                                                                                                                             =
+//=====================================================================================================================================
 /// The template function renders an entity. Used by r::ms::RunStage and r::bs::RunStage. Used like macro
 template <typename type_t, bool render_transparent> void Render( type_t* t )
 {

+ 1 - 1
src/resources/material.h

@@ -107,7 +107,7 @@ class material_t: public resource_t
 	//===================================================================================================================================
 	protected:
 		void SetToDefault();
-		bool InitTheOther(); ///< The func is for not poluting Load with extra code
+		bool InitTheOther(); ///< The func is for not polluting Load with extra code
 		
 	public:
 		material_t() { SetToDefault(); }

+ 0 - 1
src/resources/mesh.h

@@ -50,7 +50,6 @@ class mesh_t: public resource_t
 		} vbos;
 
 		string material_name;
-		string dp_material_name;
 
 		bsphere_t bsphere;
 

+ 1 - 0
src/scene/mesh_node.h

@@ -17,6 +17,7 @@ class mesh_node_t: public node_t
 		// resources
 		mesh_t* mesh;
 		material_t* material;
+		material_t* dp_material; ///< Depth pass material
 		// controllers
 		skel_controller_t* skel_controller;
 		// funcs