[Fixed] Max 2009 -> Irrlicht, multiple UVs, batch export

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
poulpi33
Posts: 31
Joined: Tue Jan 06, 2009 8:01 pm
Location: Bordeaux, France

[Fixed] Max 2009 -> Irrlicht, multiple UVs, batch export

Post by poulpi33 »

Hello,

I've searched the forum about how to export meshes from max to irrlicht with 2 uv coords, but did not found any solution working with max 2009.

- second uv in panda .x files is not readable by irrlicht (FVFData error)
- b3d does not work for max 8 to 2009
- ogre .mesh did not worked too
...

[FIXED]
Has been fixed on irrlicht SVN. It is now working with panda exporter, and it is the only way (at least with latest 3d max 2009 32 & 64bit)

[EDIT]
If you want to batch export multiples objects to differents .x meshs at once, you can use panda exporter maxscript tool
Last edited by poulpi33 on Mon Jan 19, 2009 7:49 pm, edited 4 times in total.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

I would open the X file in MilkShape3D and save to B3D or MS3D format, or fix loading the second set of texture coords in the X loader.
No promises here but if you can post an X file with two sets of texture coordinates it would make a good bit of test data for anyone looking to improve the X loader.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
skumar
Posts: 201
Joined: Thu Feb 14, 2008 6:24 pm
Location: kerala state india
Contact:

Post by skumar »

hi,
I use lightmapping(2uv) using 3ds max and b3d exporter by onigirl. I have tested it on max7 and 2008 and worked fine. I have seen that the plugin has some problem in max2009. You may get help from the author of that plugin (www.onigirl.com).

Presently im using 3ds max 7 and works fine....
skumar
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The FVF data parser is already implemented, this should be in 1.5 already. Question is if the meshbuffers are properly created. The remaining problem is that you cannot specify to use lightmaps in the file format. So you have to do some things manually when going the .x way.
poulpi33
Posts: 31
Joined: Tue Jan 06, 2009 8:01 pm
Location: Bordeaux, France

Post by poulpi33 »

Thanks for help.
bitplane wrote:I would open the X file in MilkShape3D and save to B3D or MS3D format, or fix loading the second set of texture coords in the X loader.
No promises here but if you can post an X file with two sets of texture coordinates it would make a good bit of test data for anyone looking to improve the X loader.
MilkShape can't import .x but i will try with fbx.
Here a simple mesh.x with 2 uv coords:
http://www.ecranbl.eu/archi/mesh.x
hybrid wrote:The FVF data parser is already implemented, this should be in 1.5 already. Question is if the meshbuffers are properly created. The remaining problem is that you cannot specify to use lightmaps in the file format. So you have to do some things manually when going the .x way.
I use panda exporter, and set up textures in iirlicht manually, with custom material and shader. When running the app i got the following error in the console:
Unknown data object in mesh in x file: FVFData
And the mesh does not show at all
http://www.ecranbl.eu/archi/mesh.x
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Oh yes, you're right. It's only in SVN/trunk, the DeclData had been made before. Moreover, I found a bug in the binary .x loader, which is fixed as of revision 2053. Still, your mesh does not show up... Have to test some more.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

poulpi33

Import it in 3DS, create a multiple surface type, put your first UV in ID1 and the second UV in ID2 (surface ID)

Then put all the UVs in the same channel (normally channel 1).

That method worked for me.

The result is that you will have all the UV in the SAME channel, but each UV is set on a specific surface ID. For example, this is great for having a UV texture specificaly on a BODY and one for the HEAD (Two textures). All the UV are in the same channel, but each surface (HEAD is specifically using the material "HEAD" and using specific UV inside the channel. The same for the body.

If done this in Hammer and it worked flawlessly. It should work also in IRRlicht.
poulpi33
Posts: 31
Joined: Tue Jan 06, 2009 8:01 pm
Location: Bordeaux, France

Post by poulpi33 »

hi christianclavet (c'est français ca non ? :wink:)

This can't work for lightmaps because this is the exact same faces wich need two uv coords.

I've tried importing to milkshape with .fbx and export in .b3d an .ms3d, did not worked. Could not verifiy if the problem here comes from the import of .fbx in milkshape or from the export, because i did not found a way in the milkshape uv editor to show uv2

I downloaded the last svn version revision 2053 and like hybrid, no fvfdata error anymore but the mesh still not show. I will try different .x exports ...


Definitely need a way to easily import meshs with multiples coords from max, couldn't live without that !
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Maybe you can create a mesh which is not just a flat plane? I had even some problems with the MView from the DX SDK, because I had to turn the camera properly to see anything. Just make a cube and texture it.
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

@poulpi33

As far as I know b3d is really your optimal choice, especially if you have max... As it looks though the exporter doesnt support max 2009.

Anyone correct me if I'm wrong but from my experience neither .fbx nor .obj support 2 UV sets... So what I did is export my mesh twice, one time with the first UV set and the diffuse map, second time with 2nd UV set and the lightmap set as diffuse map. Then merge the UV sets inside irrlicht... I've written a function to accomplish that...

Code: Select all

scene::SMesh* LoadLightmapMeshes(scene::IAnimatedMesh* texturemesh, scene::IAnimatedMesh* lightmapmesh )
{

	scene::IMesh* workTextureMesh = texturemesh->getMesh(0);
	scene::IMesh* workLightmapMesh = lightmapmesh->getMesh(0);

	scene::SMesh* SFinalMesh = new irr::scene::SMesh();

	u32 TmbCount = workTextureMesh->getMeshBufferCount();
	u32 LMmbCount = workLightmapMesh->getMeshBufferCount();
	printf("Amount of Buffers in texturemesh: %d \n",TmbCount);
	printf("Amount of Buffers in lightmapmesh: %d \n\n",LMmbCount);

	if(TmbCount == LMmbCount){
		u32 i;
		for(i=0; i < workTextureMesh->getMeshBufferCount(); i++){

			//printf("Mesh Buffer#: %d \n ",i);

			scene::SMeshBufferLightMap * new2Tbuffer = new scene::SMeshBufferLightMap();
			scene::IMeshBuffer* bufferTM = workTextureMesh->getMeshBuffer(i);
			scene::IMeshBuffer* bufferLM = workLightmapMesh->getMeshBuffer(i);


			u32 numVerticesTM = bufferTM->getVertexCount(); // get the amount of vertices in Texturemesh meshbuffer
			u32 numIndicesTM = bufferTM->getIndexCount(); // get the amount of indices in Texturemesh meshbuffer

			u32 numVerticesLM = bufferLM->getVertexCount(); // get the amount of vertices in Lightmapmesh meshbuffer
			u32 numIndicesLM = bufferLM->getIndexCount(); // get the amount of indices in Lightmapmesh meshbuffer

			printf("Amount of Vertices in texturemesh: %d \n ",numVerticesTM);
			printf("Amount of Vertices in lightmapmesh: %d \n \n ",numVerticesLM);

			//get pointer to Vertices and cast to irr::video::S3DVertex - Texturemesh
			video::S3DVertex *bufferVerticesTM = (irr::video::S3DVertex*)bufferTM->getVertices(); 

			//get pointer to Indices - Texturemesh
			irr::u16 *bufferIndicesTM = bufferTM->getIndices();

			//get pointer to Vertices and cast to irr::video::S3DVertex - LightmapMesh
			video::S3DVertex *bufferVerticesLM = (irr::video::S3DVertex*)bufferLM->getVertices();

			//get pointer to Indices - LightmapMesh
			irr::u16 *bufferIndicesLM = bufferLM->getIndices();

			//Create storage for new combined S3DVertex2TCoords,indices and material
			core::array<video::S3DVertex2TCoords> vertices; 
			core::array<u16> indices; 
			video::SMaterial CurrMaterial = bufferTM->getMaterial();

			// push vertices into Storage and push
			// TCoords of Lightmapmesh to TCoords2 of Texturemesh
			u32 j;
			u32 Cmax;
			if(numVerticesTM > numVerticesLM){
				Cmax = numVerticesLM;
			}else if(numVerticesLM > numVerticesTM){
				Cmax = numVerticesTM;
			}else if(numVerticesLM == numVerticesTM){
				Cmax = numVerticesLM;
			}
			for (j = 0; j < Cmax; ++j){ 
				bufferVerticesTM[j].Color = 16777215; //Maya X-Exporter bug
				vertices.push_back(video::S3DVertex2TCoords(bufferVerticesTM[j].Pos, bufferVerticesTM[j].Normal, 
				bufferVerticesTM[j].Color, bufferVerticesTM[j].TCoords, bufferVerticesLM[j].TCoords)); 
			}

			// push indices into Storage
			u32 k;
			for (k = 0; k < numIndicesTM; ++k) 
				indices.push_back(bufferIndicesTM[k]); 

			//get Texture from slot1 of Lightmapmesh
			video::SMaterial CurrMaterialLM = bufferLM->getMaterial();
			video::ITexture* CurrentTextureLM = CurrMaterialLM.getTexture(0);

			//change Material Type and apply Lightmapmeshs Texture to slot2 of Texturemesh
			CurrMaterial.MaterialType = irr::video::EMT_LIGHTMAP_LIGHTING_M2;
			CurrMaterial.setTexture(1,CurrentTextureLM);
			CurrMaterial.Lighting = false;

			//Add stored data to new buffer
			new2Tbuffer->Material = CurrMaterial;
			new2Tbuffer->Vertices = vertices;
			new2Tbuffer->Indices = indices;


			new2Tbuffer->recalculateBoundingBox();
			SFinalMesh->addMeshBuffer(new2Tbuffer);

		}
	}else{
		printf("Unsane operation... trying to combine meshes with different amounts of Materials");
		return 0;
	}
	SFinalMesh->recalculateBoundingBox();
	return SFinalMesh;
}
maybe it helps...
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

zillion42 wrote: Anyone correct me if I'm wrong but from my experience neither .fbx nor .obj support 2 UV sets... So what I did is export my mesh twice, one time with the first UV set and the diffuse map, second time with 2nd UV set and the lightmap set as diffuse map. Then merge the UV sets inside irrlicht... I've written a function to accomplish that...
CuteAlien did a similar thing, the code is here. The tool merges two LWO files together into a new mesh format, and the loader allows Irrlicht to load this new format.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
poulpi33
Posts: 31
Joined: Tue Jan 06, 2009 8:01 pm
Location: Bordeaux, France

Post by poulpi33 »

These workarounds are too much work for bigger projects.
You have to duplicate each object in max wich have 2 coords and copy uv2 on uv1 each time you wan't to export. For 4 or 5 object it's ok, but for a complete scene ...

Maybe de .x multiple uv is working know in latest svn version, but actually .x mesh is not drawn on the screen.

here a simple box in .x format with multiple coords, and a texture wich if applied on uv1 show "UV1" on the mesh, and if applied on uv2 show "UV2"
http://www.ecranbl.eu/irr/
.3ds show in the viewport, .x doesn't
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, looks like the mesh data is somehow not properly added to the meshbuffers, or the material is broken. But if you save the mesh with the old MView the file works, both with ASCII and binary. I'll try to debug this some more, but it definitely works also with 2 uv coords.
skumar
Posts: 201
Joined: Thu Feb 14, 2008 6:24 pm
Location: kerala state india
Contact:

Post by skumar »

Since i am using max 7 i have no probs with b3d pipeline......

I recommend just writing to the b3d dev for getting a max 2009 version.....

i think b3d is only the choice if we use 2uv for big projects....

NB: B3d pipeline works upto max 2008, i have tested and confirmed
skumar
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

I'd actually be quite happy if .x would work aswell...
Post Reply