Hey Everyone,
I've come here for answers to questions before, but this is my first time posting. I have a problem and I am hoping y'all can help me out. So I created a map in Cartography Shop with a lightmap and exported it as a .x file. When CShop exports the .x file it actually exports two .x files, one containing the actual geometry/texture information and the other containing the lightmap information. Now, I don't know if this is an Irrlicht specific question, but is there any way to combine the two? Because when I load up just the base mesh I get all the geometry and textures, but no lightmap. And when I load up the lightmap mesh, I get all the lightmapping, but no textures. Any help here is appreciated and thanks for your time.
-AJ
Combing base mesh and lightmap
I've written this long time ago, but I guess it still works. It's simply a method which accepts two meshes as Input and returns one mesh which combines the UV's of both... Meshes must have same amount of meshbuffers, vertices and indices. I've called them texturemesh and lightmapmesh for better understanding. Hope it helps !
EDIT: It also takes the texture of the lightmap mesh and applies it to the 2nd slot of the newly created SMesh, and it changes the material type to EMT_LIGHTMAP_LIGHTING_M2... the resulting mesh should then actually be completly processed...
EDIT: It also takes the texture of the lightmap mesh and applies it to the 2nd slot of the newly created SMesh, and it changes the material type to EMT_LIGHTMAP_LIGHTING_M2... the resulting mesh should then actually be completly processed...
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++){
scene::SMeshBufferLightMap * new2Tbuffer = new scene::SMeshBufferLightMap();
scene::IMeshBuffer* bufferTM = workTextureMesh->getMeshBuffer(i);
scene::IMeshBuffer* bufferLM = workLightmapMesh->getMeshBuffer(i);
// get the amount of vertices in Texturemesh meshbuffer
u32 numVerticesTM = bufferTM->getVertexCount();
// get the amount of indices in Texturemesh meshbuffer
u32 numIndicesTM = bufferTM->getIndexCount();
// get the amount of vertices in Lightmapmesh meshbuffer
u32 numVerticesLM = bufferLM->getVertexCount();
// get the amount of indices in Lightmapmesh meshbuffer
u32 numIndicesLM = bufferLM->getIndexCount();
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){
//Maya X-Exporter bug (vertex color is black)
bufferVerticesTM[j].Color = 16777215;
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;
}
OK, so I went ahead and started using Irrlicht's built in CSM loader, but I am having a problem getting the texture path set properly. Even when I try setting the CSM_TEXTURE_PATH to the fully qualified path to the directory where my textures are it still can't find the textures. Any advice would be greatly appreciated. It's probably something simple, but I've been up for 18 hours now after 3 hours of sleep, so hopefully it's just a brain fart. Thanks.
-AJ
-AJ
OK, I'm still having trouble so I uploaded it to http://www.mediafire.com/?j1yy1lg1mic I very much appreciate your help in this matter.
-AJ
-AJ
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
The 1.5 version does load the textures only if they are at the proper location. Simply check the debug output when textures are not correctly loaded and you'll see the place. For 1.6 I will add some more tests for possible places.
However! Your mesh seems to have corrupted lightmaps. The size of the actually stored lightmaps is wrong. This leads to a crash right upon loading the lightmaps. Maybe try with smaller ones, or just re-export. The file you uploaded is definitely broken.
However! Your mesh seems to have corrupted lightmaps. The size of the actually stored lightmaps is wrong. This leads to a crash right upon loading the lightmaps. Maybe try with smaller ones, or just re-export. The file you uploaded is definitely broken.