[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38836] branches/soc-2011-cucumber/source/ gameengine: Adding support for more than 2 UV layers.

Daniel Stokes kupomail at gmail.com
Fri Jul 29 23:47:44 CEST 2011


Revision: 38836
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38836
Author:   kupoman
Date:     2011-07-29 21:47:44 +0000 (Fri, 29 Jul 2011)
Log Message:
-----------
Adding support for more than 2 UV layers. Rather than just having two uv variables stored in various places, UVs are now stored in arrays that have a size equal to RAS_TexVert::MAX_UNIT. Most traces of the hacks used to get the second UV layer to work have been removed. The python API still needs to be updated to give access to the new layers (it was updated to still work properly for the first 2 layers). VBOs still need some extra attention as well.

Modified Paths:
--------------
    branches/soc-2011-cucumber/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_BlenderShader.cpp
    branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_Material.cpp
    branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_Material.h
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
    branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_VertexProxy.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_IRasterizer.h
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MeshObject.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_MeshObject.h
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_TexVert.cpp
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_TexVert.h
    branches/soc-2011-cucumber/source/gameengine/Rasterizer/RAS_texmatrix.cpp

Modified: branches/soc-2011-cucumber/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2011-07-29 21:28:18 UTC (rev 38835)
+++ branches/soc-2011-cucumber/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2011-07-29 21:47:44 UTC (rev 38836)
@@ -770,6 +770,7 @@
 	}
 	MT_Point2 uv[4];
 	MT_Point2 uv2[4];
+	MT_Point2 uvs[4][MAXTEX];
 	const char *uvName = "", *uv2Name = "";
 
 	
@@ -822,6 +823,21 @@
 	// get uv sets
 	if(validmat) 
 	{
+		for (int lay=0; lay<MAX_MTFACE; lay++)
+		{
+			MTF_localLayer& layer = layers[lay];
+			if (layer.face == 0) break;
+
+			uvs[0][lay].setValue(layer.face->uv[0]);
+			uvs[1][lay].setValue(layer.face->uv[1]);
+			uvs[2][lay].setValue(layer.face->uv[2]);
+			
+			if (mface->v4)
+				uvs[3][lay].setValue(layer.face->uv[3]);
+			else
+				uvs[3][lay].setValue(0.0f, 0.0f);
+		}
+
 		bool isFirstSet = true;
 
 		// only two sets implemented, but any of the eight 
@@ -885,8 +901,7 @@
 	}
 
 	material->SetConversionRGB(rgb);
-	material->SetConversionUV(uvName, uv);
-	material->SetConversionUV2(uv2Name, uv2);
+	material->SetConversionUV(uvs);
 
 	if(validmat)
 		material->matname	=(mat->id.name);
@@ -960,8 +975,7 @@
 	{
 		Material* ma = 0;
 		bool collider = true;
-		MT_Point2 uv0(0.0,0.0),uv1(0.0,0.0),uv2(0.0,0.0),uv3(0.0,0.0);
-		MT_Point2 uv20(0.0,0.0),uv21(0.0,0.0),uv22(0.0,0.0),uv23(0.0,0.0);
+		MT_Point2 uvs[4][RAS_TexVert::MAX_UNIT];
 		unsigned int rgb0,rgb1,rgb2,rgb3 = 0;
 
 		MT_Point3 pt0, pt1, pt2, pt3;
@@ -1042,13 +1056,7 @@
 				rgb0 = rgb[0]; rgb1 = rgb[1];
 				rgb2 = rgb[2]; rgb3 = rgb[3];
 
-				bl_mat->GetConversionUV(uv);
-				uv0 = uv[0]; uv1 = uv[1];
-				uv2 = uv[2]; uv3 = uv[3];
-
-				bl_mat->GetConversionUV2(uv);
-				uv20 = uv[0]; uv21 = uv[1];
-				uv22 = uv[2]; uv23 = uv[3];
+				bl_mat->GetConversionUV(uvs);
 				
 				/* then the KX_BlenderMaterial */
 				if (kx_blmat == NULL)
@@ -1082,12 +1090,12 @@
 					visible = !(tface->mode & TF_INVISIBLE);
 					twoside = ((tface->mode & TF_TWOSIDE)!=0);
 					
-					uv0.setValue(tface->uv[0]);
-					uv1.setValue(tface->uv[1]);
-					uv2.setValue(tface->uv[2]);
+					uvs[0][0].setValue(tface->uv[0]);
+					uvs[1][0].setValue(tface->uv[1]);
+					uvs[2][0].setValue(tface->uv[2]);
 	
 					if (mface->v4)
-						uv3.setValue(tface->uv[3]);
+						uvs[3][0].setValue(tface->uv[3]);
 				} 
 				else {
 					/* no texfaces, set COLLSION true and everything else FALSE */
@@ -1189,12 +1197,12 @@
 			poly->SetTwoside(twoside);
 			//poly->SetEdgeCode(mface->edcode);
 
-			meshobj->AddVertex(poly,0,pt0,uv0,uv20,tan0,rgb0,no0,flat,mface->v1);
-			meshobj->AddVertex(poly,1,pt1,uv1,uv21,tan1,rgb1,no1,flat,mface->v2);
-			meshobj->AddVertex(poly,2,pt2,uv2,uv22,tan2,rgb2,no2,flat,mface->v3);
+			meshobj->AddVertex(poly,0,pt0,uvs[0],tan0,rgb0,no0,flat,mface->v1);
+			meshobj->AddVertex(poly,1,pt1,uvs[1],tan1,rgb1,no1,flat,mface->v2);
+			meshobj->AddVertex(poly,2,pt2,uvs[2],tan2,rgb2,no2,flat,mface->v3);
 
 			if (nverts==4)
-				meshobj->AddVertex(poly,3,pt3,uv3,uv23,tan3,rgb3,no3,flat,mface->v4);
+				meshobj->AddVertex(poly,3,pt3,uvs[3],tan3,rgb3,no3,flat,mface->v4);
 		}
 
 		if (tface) 

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_BlenderShader.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_BlenderShader.cpp	2011-07-29 21:28:18 UTC (rev 38835)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_BlenderShader.cpp	2011-07-29 21:47:44 UTC (rev 38836)
@@ -99,14 +99,8 @@
 			if(attribs.layer[i].glindex > attrib_num)
 				continue;
 
-			if(attribs.layer[i].type == CD_MTFACE) {
-				if(!mat->uvName.IsEmpty() && strcmp(mat->uvName.ReadPtr(), attribs.layer[i].name) == 0)
-					ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_UV1, attribs.layer[i].glindex);
-				else if(!mat->uv2Name.IsEmpty() && strcmp(mat->uv2Name.ReadPtr(), attribs.layer[i].name) == 0)
-					ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_UV2, attribs.layer[i].glindex);
-				else
-					ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_UV1, attribs.layer[i].glindex);
-			}
+			if(attribs.layer[i].type == CD_MTFACE)
+				ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_UV1, attribs.layer[i].glindex);
 			else if(attribs.layer[i].type == CD_TANGENT)
 				ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT, attribs.layer[i].glindex);
 			else if(attribs.layer[i].type == CD_ORCO)

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_Material.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_Material.cpp	2011-07-29 21:28:18 UTC (rev 38835)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_Material.cpp	2011-07-29 21:47:44 UTC (rev 38836)
@@ -66,11 +66,11 @@
 	num_users = 1;
 	share = false;
 
-	int i;
+	int i,j;
 	for(i=0; i<4; i++)
 	{
-		uv[i] = MT_Point2(0.f,1.f);
-		uv2[i] = MT_Point2(0.f, 1.f);
+		for(j=0; j<MAXTEX; j++)
+			uvs[i][j] = MT_Point2(0.0,0.0);
 	}
 
 	for(i=0; i<MAXTEX; i++) // :(
@@ -113,36 +113,23 @@
 	*nrgb   = rgb[3];
 }
 
-void BL_Material::SetConversionUV(const STR_String& name, MT_Point2 *nuv) {
-	uvName = name;
-	uv[0] = *nuv++;
-	uv[1] = *nuv++;
-	uv[2] = *nuv++;
-	uv[3] = *nuv;
+void BL_Material::SetConversionUV(const MT_Point2 nuv[4][MAXTEX]) {
+	for(int i=0; i<4; ++i)
+	{
+		for (int j=0; j<MAXTEX; ++j)
+			uvs[i][j] = nuv[i][j];
+	}
 }
 
-void BL_Material::GetConversionUV(MT_Point2 *nuv){
-	*nuv++ = uv[0];
-	*nuv++ = uv[1];
-	*nuv++ = uv[2];
-	*nuv   = uv[3];
+void BL_Material::GetConversionUV(MT_Point2 nuv[4][8]) {
+	for(int i=0; i<4; ++i)
+	{
+		for (int j=0; j<MAXTEX; ++j)
+			nuv[i][j] = this->uvs[i][j];
+	}
 }
-void BL_Material::SetConversionUV2(const STR_String& name, MT_Point2 *nuv) {
-	uv2Name = name;
-	uv2[0] = *nuv++;
-	uv2[1] = *nuv++;
-	uv2[2] = *nuv++;
-	uv2[3] = *nuv;
-}
 
-void BL_Material::GetConversionUV2(MT_Point2 *nuv){
-	*nuv++ = uv2[0];
-	*nuv++ = uv2[1];
-	*nuv++ = uv2[2];
-	*nuv   = uv2[3];
-}
 
-
 void BL_Material::SetSharedMaterial(bool v)
 {
 	if((v && num_users == -1) || num_users > 1 )

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_Material.h
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_Material.h	2011-07-29 21:28:18 UTC (rev 38835)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/BL_Material.h	2011-07-29 21:47:44 UTC (rev 38836)
@@ -89,21 +89,14 @@
 	EnvMap*				cubemap[MAXTEX];
 
 	unsigned int rgb[4];
-	MT_Point2 uv[4];
-	MT_Point2 uv2[4];
+	MT_Point2 uvs[4][MAXTEX];
 
-	STR_String uvName;
-	STR_String uv2Name;
-
 	void SetConversionRGB(unsigned int *rgb);
 	void GetConversionRGB(unsigned int *rgb);
 
-	void SetConversionUV(const STR_String& name, MT_Point2 *uv);
-	void GetConversionUV(MT_Point2 *uv);
+	void SetConversionUV(const MT_Point2 uv[4][MAXTEX]);
+	void GetConversionUV(MT_Point2 uv[4][MAXTEX]);
 
-	void SetConversionUV2(const STR_String& name, MT_Point2 *uv);
-	void GetConversionUV2(MT_Point2 *uv);
-
 	void SetSharedMaterial(bool v);
 	bool IsShared();
 	void SetUsers(int num);

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_BlenderMaterial.cpp	2011-07-29 21:28:18 UTC (rev 38835)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_BlenderMaterial.cpp	2011-07-29 21:47:44 UTC (rev 38836)
@@ -635,13 +635,6 @@
 		for(int i=0; i<mMaterial->num_enabled; i++) {
 			int mode = mMaterial->mapping[i].mapping;
 
-			if (mode &USECUSTOMUV)
-			{
-				if (!mMaterial->mapping[i].uvCoName.IsEmpty())
-					ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_UV2, i);
-				continue;
-			}
-
 			if( mode &(USEREFL|USEOBJ))
 				ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_GEN, i);
 			else if(mode &USEORCO)

Modified: branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_VertexProxy.cpp
===================================================================
--- branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_VertexProxy.cpp	2011-07-29 21:28:18 UTC (rev 38835)
+++ branches/soc-2011-cucumber/source/gameengine/Ketsji/KX_VertexProxy.cpp	2011-07-29 21:47:44 UTC (rev 38836)
@@ -147,25 +147,25 @@
 PyObject* KX_VertexProxy::pyattr_get_u(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
-	return PyFloat_FromDouble(self->m_vertex->getUV1()[0]);
+	return PyFloat_FromDouble(self->m_vertex->getUV(0)[0]);
 }
 
 PyObject* KX_VertexProxy::pyattr_get_v(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
-	return PyFloat_FromDouble(self->m_vertex->getUV1()[1]);
+	return PyFloat_FromDouble(self->m_vertex->getUV(0)[1]);
 }
 
 PyObject* KX_VertexProxy::pyattr_get_u2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
-	return PyFloat_FromDouble(self->m_vertex->getUV2()[0]);
+	return PyFloat_FromDouble(self->m_vertex->getUV(1)[0]);
 }
 
 PyObject* KX_VertexProxy::pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
-	return PyFloat_FromDouble(self->m_vertex->getUV2()[1]);
+	return PyFloat_FromDouble(self->m_vertex->getUV(1)[1]);
 }
 
 PyObject* KX_VertexProxy::pyattr_get_XYZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
@@ -177,7 +177,7 @@
 PyObject* KX_VertexProxy::pyattr_get_UV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {
 	KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
-	return PyObjectFrom(MT_Point2(self->m_vertex->getUV1()));
+	return PyObjectFrom(MT_Point2(self->m_vertex->getUV(0)));
 }
 
 PyObject* KX_VertexProxy::pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
@@ -246,9 +246,9 @@
 	if (PyFloat_Check(value))
 	{
 		float val = PyFloat_AsDouble(value);
-		MT_Point2 uv = self->m_vertex->getUV1();
+		MT_Point2 uv = self->m_vertex->getUV(0);
 		uv[0] = val;
-		self->m_vertex->SetUV(uv);
+		self->m_vertex->SetUV(0, uv);
 		self->m_mesh->SetMeshModified(true);
 		return PY_SET_ATTR_SUCCESS;
 	}
@@ -261,9 +261,9 @@
 	if (PyFloat_Check(value))
 	{
 		float val = PyFloat_AsDouble(value);
-		MT_Point2 uv = self->m_vertex->getUV1();

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list