Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 993)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp	(revision 994)
@@ -25,4 +25,7 @@
 	geoMeshView->deactiveLodTree();
 
+	geoMeshView->resetTextures();
+	BuildLoadTextureSubMeshMenu();
+
 	//	Repaint the window.
 	mMainWindow->redraw();
@@ -33,14 +36,41 @@
 	fltk::FileChooser	*fcho =	new fltk::FileChooser("","*.jpg",fltk::FileChooser::CREATE,"Open image file");
 	fcho->exec();
+	char filename[256]="";	
 	if (fcho->value())
-		geoMeshView->LoadTexture(fcho->value());
+	{
+		strcpy(filename,fcho->value());
+		geoMeshView->LoadTexture(filename);
+	}
 }
 
 void GeoMeshViewUI::cb_menuFileLoadTexture(fltk::Item *o, void *v)
 {
-	((GeoMeshViewUI*)	(o->parent()->parent()->parent()->user_data()))
+	((GeoMeshViewUI*)	(o->parent()->parent()->parent()->parent()->user_data()))
 										->
 										cb_menuFileLoadTexture_i(o,v);
 }
+
+inline void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh_i(fltk::Item *item, void *)
+{
+	const char * label = item->label();
+	int isubmesh = label[strlen(label)-1]-48;
+
+	fltk::FileChooser	*fcho =	new fltk::FileChooser("","*.jpg",fltk::FileChooser::CREATE,"Open image file");
+	fcho->exec();
+	char filename[256]="";
+	if (fcho->value())
+	{
+		strcpy(filename,fcho->value());
+		geoMeshView->LoadTextureSubMesh(isubmesh,filename);
+	}
+}
+
+void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh(fltk::Item *o, void *v)
+{
+	((GeoMeshViewUI*)	(o->parent()->parent()->parent()->parent()->user_data()))
+										->
+										cb_menuFileLoadTextureSubMesh_i(o,v);
+}
+
 
 
@@ -2540,4 +2570,6 @@
 	//	Initialize the menus application state.
 	mApplicationState	=	NONE;
+
+	SubMeshNames=NULL;
 	
 	{
@@ -2791,6 +2823,6 @@
 
 				{
-					fltk::Item* o = menuFileLoadTexture = new fltk::Item("Load texture");
-					o->callback((fltk::Callback*)cb_menuFileLoadTexture);
+					menuLoadTextures = new fltk::ItemGroup("Load Textures");
+					o->add(menuLoadTextures);
 				}
 
@@ -3097,2 +3129,32 @@
 }
 
+
+void GeoMeshViewUI::BuildLoadTextureSubMeshMenu(void)
+{
+	if (SubMeshNames)
+	{
+		menuLoadTextures->clear();
+		for (int i=0; i<numSubMeshNames; i++)
+		{
+			delete[] SubMeshNames[i];
+		}
+		delete[] SubMeshNames;
+	}
+
+	menuFileLoadTexture = new fltk::Item("Entire model");
+	menuFileLoadTexture->callback((fltk::Callback*)cb_menuFileLoadTexture);
+	menuLoadTextures->add(menuFileLoadTexture);
+
+	numSubMeshNames=geoMeshView->getSubMeshCount();
+	SubMeshNames=new char*[numSubMeshNames];
+
+	for (int i=0; i<numSubMeshNames; i++)
+	{
+		SubMeshNames[i]=new char[10];
+
+		sprintf(SubMeshNames[i],"submesh %d",i);
+		fltk::Item *item = new fltk::Item(SubMeshNames[i]);
+		item->callback((fltk::Callback*)cb_menuFileLoadTextureSubMesh);
+		menuLoadTextures->add(item);
+	}
+}
Index: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
===================================================================
--- GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp	(revision 993)
+++ GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp	(revision 994)
@@ -436,4 +436,5 @@
 
 		current_texture = 0;
+		current_texture_submesh=NULL;
 		use_texture_mapping = true;
 }
@@ -461,4 +462,10 @@
 	
 	glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,color_blanco);
+
+	if (current_texture_submesh)
+		delete[] current_texture_submesh;
+	current_texture_submesh=new GLuint[getSubMeshCount()];
+	for (int i=0; i<getSubMeshCount(); i++)
+		current_texture_submesh[i]=0;
 }
 
@@ -663,4 +670,16 @@
 	geosubmesh	=	&geoMesh->mSubMesh[submesh];
 
+	// bind current texture to use
+	GLuint usetex = 0;
+	if (use_texture_mapping)
+	{
+		if (current_texture_submesh[submesh])
+			usetex=current_texture_submesh[submesh];
+		else if (current_texture)
+			usetex=current_texture;
+	}
+	glBindTexture(GL_TEXTURE_2D,usetex);
+
+
 	//	For each one of the strips.
 	for (int strip = 0; strip < geosubmesh->mStripCount; strip++)
@@ -726,9 +745,9 @@
 
 			// set the texture coordinates if needed
-			if (current_texture && use_texture_mapping)
+			if (usetex)
 			{
 				vector2 = geosubmesh->mVertexBuffer->mTexCoords[position];
-				x				=	vector3[0];
-				y				=	vector3[1];
+				x				=	vector2[0];
+				y				=	vector2[1];
 				glTexCoord2f(x,y);
 			}
@@ -812,9 +831,20 @@
 		}
 	}
+
+	// bind current texture to use
+	GLuint usetex = 0;
+	if (use_texture_mapping)
+	{
+		if (current_texture_submesh[submesh])
+			usetex=current_texture_submesh[submesh];
+		else if (current_texture)
+			usetex=current_texture;
+	}
+	glBindTexture(GL_TEXTURE_2D,usetex);
 	
 	//	Enable arrays.
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_NORMAL_ARRAY);
-	if (current_texture && use_texture_mapping)
+	if (usetex)
 		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 	else
@@ -826,5 +856,5 @@
 		glVertexPointer(3, GL_FLOAT, 0, mSharedPosArray);
 		glNormalPointer(GL_FLOAT, 0, mSharedNorArray);
-		if (current_texture && use_texture_mapping)
+		if (usetex)
 			glTexCoordPointer(2, GL_FLOAT, 0, mSharedTexCoordArray);
 	}
@@ -833,5 +863,5 @@
 		glVertexPointer(3, GL_FLOAT, 0, mPosArray[submesh]);
 		glNormalPointer(GL_FLOAT, 0, mNorArray[submesh]);
-		if (current_texture && use_texture_mapping)
+		if (usetex)
 			glTexCoordPointer(2, GL_FLOAT, 0, mTexCoordArray[submesh]);
 	}
@@ -848,4 +878,107 @@
 //---------------------------------------------------------------------------
 void GeoMeshView::drawLodStrip()
+{
+	SubMesh				*geosubmesh;
+	Index					position;
+	Vector3				vector3;
+	Vector2				vector2;
+	float					x,y,z;
+	float					r,g,b;
+	int						color_index;
+	int						current_strip;
+
+	//	Initialize current strip.
+	current_strip	=	0;
+
+	//	For each submesh.
+	for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
+	{
+		// bind current texture to use
+		GLuint usetex = 0;
+		if (use_texture_mapping)
+		{
+			if (current_texture_submesh[submesh])
+				usetex=current_texture_submesh[submesh];
+			else if (current_texture)
+				usetex=current_texture;
+		}
+		glBindTexture(GL_TEXTURE_2D,usetex);		
+
+		color_index	=	0;
+
+		//	Gets the actual submesh.
+		geosubmesh	=	&geoMesh->mSubMesh[submesh];
+
+		//	For each one of the strips.
+		for (int strip = 0; strip < geosubmesh->mStripCount; strip++)
+		{
+			//	Paint the current strip.
+			glBegin(GL_TRIANGLE_STRIP);
+
+			if (getColorStrips())
+			{
+				//	Gets the color of the strip.
+				r	=	mStripColors[submesh][color_index].r;
+				g	=	mStripColors[submesh][color_index].g;
+				b	=	mStripColors[submesh][color_index].b;
+
+				//	Change to the next color.
+				color_index++;
+
+				//	Paint a new color.
+				glColor3f(r,g,b);
+			}
+
+			//	For each index of the strip.
+			for (int index = 0; index < lodStripsLib->mStrips[current_strip].size(); index++)
+			{
+				position	=	lodStripsLib->mStrips[current_strip][index];
+
+				//	Gets the vertex normal.
+				vector3	=	geosubmesh->mVertexBuffer->mNormal[position];
+
+				x				=	vector3[0];
+				y				=	vector3[1];
+				z				=	vector3[2];
+
+				//	Sets the vertex normal.
+				glNormal3f(x,y,z);
+
+				// set the texture coordinates if needed
+				if (usetex)
+				{
+					vector2 = geosubmesh->mVertexBuffer->mTexCoords[position];
+					x				=	vector2[0];
+					y				=	vector2[1];
+					glTexCoord2f(x,y);
+				}
+
+				//	Gets the vertex coordinates.
+				vector3	=	geosubmesh->mVertexBuffer->mPosition[position];
+
+				x				=	vector3[0];
+				y				=	vector3[1];
+				z				=	vector3[2];
+
+				//	Sets the vertex position.
+				glVertex3f(x,y,z);
+			}
+
+			//	Increments current strip.
+			current_strip++;
+
+			//	A strip is generated.
+			glEnd();
+
+		}
+	}
+	
+}//End drawTriangleStrip.
+
+
+//---------------------------------------------------------------------------
+//	Paint lodtree object.
+//---------------------------------------------------------------------------
+void GeoMeshView::drawLodTree()
 {
 	SubMesh				*geosubmesh;
@@ -860,87 +993,4 @@
 	current_strip	=	0;
 
-	//	For each submesh.
-	for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++)
-	{
-		
-		color_index	=	0;
-
-		//	Gets the actual submesh.
-		geosubmesh	=	&geoMesh->mSubMesh[submesh];
-
-		//	For each one of the strips.
-		for (int strip = 0; strip < geosubmesh->mStripCount; strip++)
-		{
-			//	Paint the current strip.
-			glBegin(GL_TRIANGLE_STRIP);
-
-			if (getColorStrips())
-			{
-				//	Gets the color of the strip.
-				r	=	mStripColors[submesh][color_index].r;
-				g	=	mStripColors[submesh][color_index].g;
-				b	=	mStripColors[submesh][color_index].b;
-
-				//	Change to the next color.
-				color_index++;
-
-				//	Paint a new color.
-				glColor3f(r,g,b);
-			}
-
-			//	For each index of the strip.
-			for (int index = 0; index < lodStripsLib->mStrips[current_strip].size(); index++)
-			{
-				position	=	lodStripsLib->mStrips[current_strip][index];
-
-				//	Gets the vertex normal.
-				vector3	=	geosubmesh->mVertexBuffer->mNormal[position];
-
-				x				=	vector3[0];
-				y				=	vector3[1];
-				z				=	vector3[2];
-
-				//	Sets the vertex normal.
-				glNormal3f(x,y,z);
-
-				//	Gets the vertex coordinates.
-				vector3	=	geosubmesh->mVertexBuffer->mPosition[position];
-
-				x				=	vector3[0];
-				y				=	vector3[1];
-				z				=	vector3[2];
-
-				//	Sets the vertex position.
-				glVertex3f(x,y,z);
-			}
-
-			//	Increments current strip.
-			current_strip++;
-
-			//	A strip is generated.
-			glEnd();
-
-		}
-	}
-	
-}//End drawTriangleStrip.
-
-
-//---------------------------------------------------------------------------
-//	Paint lodtree object.
-//---------------------------------------------------------------------------
-void GeoMeshView::drawLodTree()
-{
-	SubMesh				*geosubmesh;
-	Index					position;
-	Vector3				vector3;
-	float					x,y,z;
-	float					r,g,b;
-	int						color_index;
-	int						current_strip;
-
-	//	Initialize current strip.
-	current_strip	=	0;
-
 
 	// DRAW THE TRUNK AS A LODSTRIP OBJECT
@@ -1098,6 +1148,6 @@
 
 	GLfloat	light_ambient[]	=	{0.3,0.3,0.3,1.0};
-	GLfloat	luzpos[]				=	{0.0,0.0,1.0,0.0};
-	GLfloat	luzcolor[]			=	{1.0,1.0,1.0,1.0};
+	GLfloat	luzpos[]		=	{0.0,0.0,1.0,0.0};
+	GLfloat	luzcolor[]		=	{1.0,1.0,1.0,1.0};
 
 	//	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_ambient);
@@ -1199,2 +1249,31 @@
 	ilShutDown();
 }
+
+
+void	GeoMeshView::LoadTextureSubMesh(int isubmesh, const char *imgfile)
+{
+	ilInit();
+	ilutEnable(ILUT_OPENGL_CONV);
+	ilutRenderer(ILUT_OPENGL);
+
+	current_texture_submesh[isubmesh] = ilutGLLoadImage((const ILstring)imgfile);
+	if (!current_texture_submesh[isubmesh])
+		fltk::alert("Error loading texture!");
+
+	ilShutDown();
+}
+
+void	GeoMeshView::resetTextures(void)
+{
+	if (current_texture)
+	{
+		glDeleteTextures(1,&current_texture);
+		current_texture=0;
+	}
+	if (current_texture_submesh)
+	{
+		glDeleteTextures(getSubMeshCount(),current_texture_submesh);
+		for (int i=0; i<getSubMeshCount(); i++)
+			current_texture_submesh[i]=0;
+	}
+}
