CBMeshFileExporter.cpp
#include "CBMeshFileExporter.hpp"
#include
#include "Vertex.hpp"
#include "CBMeshVertex.hpp"
CBMeshFileExporter::~CBMeshFileExporter() {
}
CBMeshFileExporter::CBMeshFileExporter( const std::string& exportFileName, FileType fileType ) {
m_fileName = exportFileName;
m_fileType = fileType;
m_exportedToFile = false;
}
bool CBMeshFileExporter::exportMaxNodeDataToFile( const std::vector& exportNodes ) {
bool didExport = false;
didExport = exportMaxNodeDataToFileAsBinary( exportNodes );
return didExport;
}
bool CBMeshFileExporter::exportMaxNodeDataToFileAsBinary( const std::vector& exportNodes ) {
CBMaterialManager& materialManager = CBMaterialManager::getSharedMaterialManager();
materialManager.formMaterialToIDMappingsForExistingMaterials();
std::ofstream* binaryOutputFile = new std::ofstream( m_fileName.c_str(), std::ios::binary | std::ios::out );
// Export Materials First
std::map& materialIDMappings = materialManager.getMaterialIDMappings();
std::map::iterator itMaterial;
int numMaterials = static_cast( materialIDMappings.size() );
binaryOutputFile->write( (char*) &numMaterials, sizeof( numMaterials ) );
for ( itMaterial = materialIDMappings.begin(); itMaterial != materialIDMappings.end(); ++itMaterial ) {
IGameMaterial* material = itMaterial->first;
int materialID = itMaterial->second;
writeMaterialsToBinaryFile( binaryOutputFile, materialID, material );
}
writeNodeDataVectorToBinaryFile( binaryOutputFile, exportNodes );
binaryOutputFile->flush();
binaryOutputFile->close();
delete binaryOutputFile;
return true;
}
void CBMeshFileExporter::writeMaterialsToBinaryFile( std::ofstream* binaryExportFile, int materialNumber, IGameMaterial* material ) {
if ( material != nullptr ) {
binaryExportFile->write( (char*) &materialNumber, sizeof( materialNumber ) );
const TCHAR* materialNameAsWChar = material->GetMaterialName();
std::string materialNameAsString;
cbengine::convertWideCharToString( materialNameAsWChar, materialNameAsString );
int sizeOfMaterialNameString = static_cast( materialNameAsString.size() );
binaryExportFile->write( (char*) &sizeOfMaterialNameString, sizeof( sizeOfMaterialNameString ) );
binaryExportFile->write( &materialNameAsString[0], sizeOfMaterialNameString );
std::string diffuseTextureName;
getDiffuseTextureFilePath( material, diffuseTextureName );
int sizeOfDiffuseTexture = static_cast( diffuseTextureName.size() );
binaryExportFile->write( (char*) &sizeOfDiffuseTexture, sizeof( sizeOfDiffuseTexture ) );
binaryExportFile->write( &diffuseTextureName[0], sizeOfDiffuseTexture );
std::string normalTextureName;
getNormalMapTextureFilePath( material, normalTextureName );
int sizeOfNormalTexture = static_cast( normalTextureName.size() );
binaryExportFile->write( (char*) &sizeOfNormalTexture, sizeof( sizeOfNormalTexture ) );
binaryExportFile->write( (char*) &normalTextureName[0], sizeOfNormalTexture );
std::string specularLevelTextureName;
getSpecularLevelTextureFilePath( material, specularLevelTextureName );
int sizeOfSpecularLevelTexture = static_cast( specularLevelTextureName.size() );
binaryExportFile->write( (char*) &sizeOfSpecularLevelTexture, sizeof( sizeOfSpecularLevelTexture ) );
binaryExportFile->write( (char*) &specularLevelTextureName[0], sizeOfSpecularLevelTexture );
std::string specularColorTextureName;
getSpecularColorTextureFilePath( material, specularColorTextureName );
int sizeOfSpecularColorTexture = static_cast( specularColorTextureName.size() );
binaryExportFile->write( (char*) &sizeOfSpecularColorTexture, sizeof( sizeOfSpecularColorTexture ) );
binaryExportFile->write( (char*) &specularColorTextureName[0], sizeOfSpecularColorTexture );
std::string emissiveTextureName;
getEmissiveTextureFilePath( material, emissiveTextureName );
int sizeOfEmissiveTexture = static_cast( emissiveTextureName.size() );
binaryExportFile->write( (char*) &sizeOfEmissiveTexture, sizeof( sizeOfEmissiveTexture ) );
binaryExportFile->write( (char*) &emissiveTextureName[0], sizeOfEmissiveTexture );
}
}
void CBMeshFileExporter::writeNodeDataVectorToBinaryFile( std::ofstream* binaryExportFile, const std::vector& exportNodes ) {
int totalNumberOfNodes = static_cast( exportNodes.size() );
binaryExportFile->write( (char*) &totalNumberOfNodes, sizeof( totalNumberOfNodes ) );
for ( size_t i = 0; i < exportNodes.size(); ++i ) {
CBExportNode* exportNode = exportNodes[i];
const ExportNodeType& nodeType = exportNode->getExportNodeType();
if ( nodeType == TYPE_EXPORT_NODE) {
writeNodeDataToBinaryFile( binaryExportFile, exportNode );
} else if ( nodeType == TYPE_EXPORT_MESH ) {
CBExportMesh* exportMesh = static_cast( exportNode );
writeMeshDataToBinaryFile( binaryExportFile, exportMesh );
} else if ( nodeType == TYPE_EXPORT_BONE ) {
writeBoneNodeDataToBinaryFile( binaryExportFile, exportNode );
} else if ( nodeType == TYPE_EXPORT_SKINNED_MESH ) {
CBExportSkinnedMesh* exportSkinnedMesh = static_cast( exportNode );
writeSkinnedMeshDataToBinaryFile( binaryExportFile, exportSkinnedMesh );
}
}
}
void CBMeshFileExporter::writeNodeDataToBinaryFile( std::ofstream* binaryExportFile, CBExportNode* nodeToWrite ) {
// Write the node type
int sizeOfNodeString = static_cast( NODE_TYPE_STRING.size() );
binaryExportFile->write( (char*) &sizeOfNodeString, sizeof( sizeOfNodeString ) );
binaryExportFile->write( &NODE_TYPE_STRING[0], sizeOfNodeString );
const std::string& nodeNameString = nodeToWrite->getNodeName();
int sizeOfNodeNameString = static_cast( nodeNameString.size() );
binaryExportFile->write( (char*) &sizeOfNodeNameString, sizeof( sizeOfNodeNameString ) );
binaryExportFile->write( (char*) &nodeNameString[0], sizeOfNodeNameString );
// Write the index of the node
int nodeIndex = nodeToWrite->getNodeIndex();
binaryExportFile->write( (char*) &nodeIndex, sizeof( nodeIndex ) );
// Write the parent index
int parentIndex = -1;
CBExportNode* exportNodeParent = nodeToWrite->getParentNode();
if ( exportNodeParent != nullptr ) {
parentIndex = exportNodeParent->getNodeIndex();
}
binaryExportFile->write( (char*) &parentIndex, sizeof( parentIndex ) );
// Local to World Transform
const GMatrix& localToWorldTransform = nodeToWrite->getInitialLocalToWorldTransformationMatrix();
binaryExportFile->write( (char*) &localToWorldTransform.GetAddr()[0], sizeof( GMatrix ) );
// World to Local Transform
const GMatrix& worldToLocalTransform = nodeToWrite->getInitialWorldToLocalTransformationMatrix();
binaryExportFile->write( (char*) &worldToLocalTransform.GetAddr()[0], sizeof( GMatrix ) );
const std::vector& animationVector = nodeToWrite->getAnimationTransformations();
int numberOfAnimTransformations = static_cast( animationVector.size() );
bool shouldExportAnimationList = false;
if ( numberOfAnimTransformations == 0 ) {
shouldExportAnimationList = false;
} else {
const GMatrix& firstMatrix = animationVector[0];
for ( int i = 1; i < numberOfAnimTransformations; ++i ) {
const GMatrix& matrixToCheck = animationVector[i];
if ( !firstMatrix.Equals( matrixToCheck ) ) {
shouldExportAnimationList = true;
break;
}
}
}
if ( shouldExportAnimationList ) {
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
// Animations
for ( int i = 0; i < numberOfAnimTransformations; ++i ) {
const GMatrix& animTransform = animationVector[i];
binaryExportFile->write( (char*) &animTransform.GetAddr()[0], sizeof( GMatrix ) );
}
} else {
if ( numberOfAnimTransformations > 0 ) {
numberOfAnimTransformations = 1;
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
const GMatrix& firstMatrix = animationVector[0];
binaryExportFile->write( (char*) &firstMatrix.GetAddr()[0], sizeof( GMatrix ) );
} else {
numberOfAnimTransformations = 0;
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
}
}
}
void CBMeshFileExporter::writeBoneNodeDataToBinaryFile( std::ofstream* binaryExportFile, CBExportNode* boneNodeToWrite ) {
// Write the node type
int sizeOfNodeString = static_cast( BONE_TYPE_STRING.size() );
binaryExportFile->write( (char*) &sizeOfNodeString, sizeof( sizeOfNodeString ) );
binaryExportFile->write( &BONE_TYPE_STRING[0], sizeOfNodeString );
const std::string& nodeNameString = boneNodeToWrite->getNodeName();
int sizeOfNodeNameString = static_cast( nodeNameString.size() );
binaryExportFile->write( (char*) &sizeOfNodeNameString, sizeof( sizeOfNodeNameString ) );
binaryExportFile->write( (char*) &nodeNameString[0], sizeOfNodeNameString );
// Write the index of the node
int nodeIndex = boneNodeToWrite->getNodeIndex();
binaryExportFile->write( (char*) &nodeIndex, sizeof( nodeIndex ) );
// Write out the bone index of the nodes
CBSkeletalBoneManager& skeletalBoneManager = CBSkeletalBoneManager::getSharedCBSkeletalBoneManager();
int boneIndex = skeletalBoneManager.getBoneIndexForCBExportNode( boneNodeToWrite );
binaryExportFile->write( (char*) &boneIndex, sizeof( boneIndex ) );
assert( boneIndex != -1 );
// Write the parent index
int parentIndex = -1;
CBExportNode* exportNodeParent = boneNodeToWrite->getParentNode();
if ( exportNodeParent != nullptr ) {
parentIndex = exportNodeParent->getNodeIndex();
}
binaryExportFile->write( (char*) &parentIndex, sizeof( parentIndex ) );
// Local to World Transform
const GMatrix& localToWorldTransform = boneNodeToWrite->getInitialLocalToWorldTransformationMatrix();
binaryExportFile->write( (char*) &localToWorldTransform.GetAddr()[0], sizeof( GMatrix ) );
// World to Local Transform
const GMatrix& worldToLocalTransform = boneNodeToWrite->getInitialWorldToLocalTransformationMatrix();
binaryExportFile->write( (char*) &worldToLocalTransform.GetAddr()[0], sizeof( GMatrix ) );
const std::vector& animationVector = boneNodeToWrite->getAnimationTransformations();
int numberOfAnimTransformations = static_cast( animationVector.size() );
bool shouldExportAnimationList = false;
if ( numberOfAnimTransformations == 0 ) {
shouldExportAnimationList = false;
} else {
const GMatrix& firstMatrix = animationVector[0];
for ( int i = 1; i < numberOfAnimTransformations; ++i ) {
const GMatrix& matrixToCheck = animationVector[i];
if ( !firstMatrix.Equals( matrixToCheck ) ) {
shouldExportAnimationList = true;
break;
}
}
}
if ( shouldExportAnimationList ) {
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
// Animations
for ( int i = 0; i < numberOfAnimTransformations; ++i ) {
const GMatrix& animTransform = animationVector[i];
binaryExportFile->write( (char*) &animTransform.GetAddr()[0], sizeof( GMatrix ) );
}
} else {
if ( numberOfAnimTransformations > 0 ) {
numberOfAnimTransformations = 1;
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
const GMatrix& firstMatrix = animationVector[0];
binaryExportFile->write( (char*) &firstMatrix.GetAddr()[0], sizeof( GMatrix ) );
} else {
numberOfAnimTransformations = 0;
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
}
}
}
void CBMeshFileExporter::writeMeshDataToBinaryFile( std::ofstream* binaryExportFile, CBExportMesh* meshToWrite ) {
// Write the node type
int sizeOfMeshString = static_cast( MESH_TYPE_STRING.size() );
binaryExportFile->write( (char*) &sizeOfMeshString, sizeof( sizeOfMeshString ) );
binaryExportFile->write( &MESH_TYPE_STRING[0], sizeOfMeshString );
const std::string& nodeNameString = meshToWrite->getNodeName();
int sizeOfNodeNameString = static_cast( nodeNameString.size() );
binaryExportFile->write( (char*) &sizeOfNodeNameString, sizeof( sizeOfNodeNameString ) );
binaryExportFile->write( (char*) &nodeNameString[0], sizeOfNodeNameString );
// Write the index of the node
int nodeIndex = meshToWrite->getNodeIndex();
binaryExportFile->write( (char*) &nodeIndex, sizeof( nodeIndex ) );
// Write the parent index
int parentIndex = -1;
CBExportNode* exportNodeParent = meshToWrite->getParentNode();
if ( exportNodeParent != nullptr ) {
parentIndex = exportNodeParent->getNodeIndex();
}
binaryExportFile->write( (char*) &parentIndex, sizeof( parentIndex ) );
// Local to World Transform
const GMatrix& localToWorldTransform = meshToWrite->getInitialLocalToWorldTransformationMatrix();
binaryExportFile->write( (char*) &localToWorldTransform.GetAddr()[0], sizeof( GMatrix ) );
// World to Local Transform
const GMatrix& worldToLocalTransform = meshToWrite->getInitialWorldToLocalTransformationMatrix();
binaryExportFile->write( (char*) &worldToLocalTransform.GetAddr()[0], sizeof( GMatrix ) );
const std::vector& animationVector = meshToWrite->getAnimationTransformations();
int numberOfAnimTransformations = static_cast( animationVector.size() );
// Animations
bool shouldExportAnimationList = false;
if ( numberOfAnimTransformations == 0 ) {
shouldExportAnimationList = false;
} else {
const GMatrix& firstMatrix = animationVector[0];
for ( int i = 1; i < numberOfAnimTransformations; ++i ) {
const GMatrix& matrixToCheck = animationVector[i];
if ( !firstMatrix.Equals( matrixToCheck ) ) {
shouldExportAnimationList = true;
break;
}
}
}
if ( shouldExportAnimationList ) {
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
for ( int i = 0; i < numberOfAnimTransformations; ++i ) {
const GMatrix& animTransform = animationVector[i];
binaryExportFile->write( (char*) &animTransform.GetAddr()[0], sizeof( GMatrix ) );
}
} else {
if ( numberOfAnimTransformations > 0 ) {
numberOfAnimTransformations = 1;
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
const GMatrix& firstMatrix = animationVector[0];
binaryExportFile->write( (char*) &firstMatrix.GetAddr()[0], sizeof( GMatrix ) );
} else {
numberOfAnimTransformations = 0;
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
}
}
// Extract Mesh Tribatches
writeTriangleBatchDataToBinaryFile( binaryExportFile, meshToWrite );
}
void CBMeshFileExporter::writeSkinnedMeshDataToBinaryFile( std::ofstream* binaryExportFile, CBExportSkinnedMesh* meshToWrite ) {
// Write the node type
int sizeOfSkinnedMeshString = static_cast( SKINNED_MESH_TYPE_STRING.size() );
binaryExportFile->write( (char*) &sizeOfSkinnedMeshString, sizeof( sizeOfSkinnedMeshString ) );
binaryExportFile->write( &SKINNED_MESH_TYPE_STRING[0], sizeOfSkinnedMeshString );
const std::string& nodeNameString = meshToWrite->getNodeName();
int sizeOfNodeNameString = static_cast( nodeNameString.size() );
binaryExportFile->write( (char*) &sizeOfNodeNameString, sizeof( sizeOfNodeNameString ) );
binaryExportFile->write( (char*) &nodeNameString[0], sizeOfNodeNameString );
// Write the index of the node
int nodeIndex = meshToWrite->getNodeIndex();
binaryExportFile->write( (char*) &nodeIndex, sizeof( nodeIndex ) );
// Write the parent index
int parentIndex = -1;
CBExportNode* exportNodeParent = meshToWrite->getParentNode();
if ( exportNodeParent != nullptr ) {
parentIndex = exportNodeParent->getNodeIndex();
}
binaryExportFile->write( (char*) &parentIndex, sizeof( parentIndex ) );
// Local to World Transform
const GMatrix& localToWorldTransform = meshToWrite->getInitialLocalToWorldTransformationMatrix();
binaryExportFile->write( (char*) &localToWorldTransform.GetAddr()[0], sizeof( GMatrix ) );
// World to Local Transform
const GMatrix& worldToLocalTransform = meshToWrite->getInitialWorldToLocalTransformationMatrix();
binaryExportFile->write( (char*) &worldToLocalTransform.GetAddr()[0], sizeof( GMatrix ) );
const std::vector& animationVector = meshToWrite->getAnimationTransformations();
int numberOfAnimTransformations = static_cast( animationVector.size() );
// Animations
bool shouldExportAnimationList = false;
if ( numberOfAnimTransformations == 0 ) {
shouldExportAnimationList = false;
} else {
const GMatrix& firstMatrix = animationVector[0];
for ( int i = 1; i < numberOfAnimTransformations; ++i ) {
const GMatrix& matrixToCheck = animationVector[i];
if ( !firstMatrix.Equals( matrixToCheck ) ) {
shouldExportAnimationList = true;
break;
}
}
}
if ( shouldExportAnimationList ) {
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
for ( int i = 0; i < numberOfAnimTransformations; ++i ) {
const GMatrix& animTransform = animationVector[i];
binaryExportFile->write( (char*) &animTransform.GetAddr()[0], sizeof( GMatrix ) );
}
} else {
if ( numberOfAnimTransformations > 0 ) {
numberOfAnimTransformations = 1;
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
const GMatrix& firstMatrix = animationVector[0];
binaryExportFile->write( (char*) &firstMatrix.GetAddr()[0], sizeof( GMatrix ) );
} else {
numberOfAnimTransformations = 0;
binaryExportFile->write( (char*) &numberOfAnimTransformations, sizeof( numberOfAnimTransformations ) );
}
}
// Extract Skinned Mesh Tribatches
writeSkinnedTriangleBatchDataToBinaryFile( binaryExportFile, meshToWrite );
}
void CBMeshFileExporter::writeTriangleBatchDataToBinaryFile( std::ofstream* binaryExportFile, CBExportMesh* meshToWrite ) {
CBMaterialManager& materialManager = CBMaterialManager::getSharedMaterialManager();
int totalNumTriBatches = 0;
const std::map& triBatchMap = meshToWrite->getTriBatchMap();
totalNumTriBatches = static_cast( triBatchMap.size() );
binaryExportFile->write( (char*) &totalNumTriBatches, sizeof( totalNumTriBatches ) );
std::map::const_iterator itBatch;
for ( itBatch = triBatchMap.begin(); itBatch != triBatchMap.end(); ++itBatch ) {
IGameMaterial* batchMaterial = itBatch->first;
CBTriBatch* triBatch = itBatch->second;
int materialIndex = materialManager.getIndexOfIGameMaterial( batchMaterial );
if ( materialIndex != MATERIAL_NOT_FOUND ) {
binaryExportFile->write( (char*) &materialIndex, sizeof( materialIndex ) );
const std::vector& triBatchVerts = triBatch->getVerts();
int numVertsInBatch = static_cast( triBatchVerts.size() );
binaryExportFile->write( (char*) &numVertsInBatch, sizeof( numVertsInBatch ) );
for ( int i = 0; i < numVertsInBatch; ++i ) {
const CBMeshVertex& meshVert = triBatchVerts[i];
const cbengine::Vertex& vert = meshVert.getVertex();
binaryExportFile->write( (char*) &vert, sizeof( cbengine::Vertex ) );
}
} else {
// SHIT
assert( true == true );
}
}
}
void CBMeshFileExporter::writeSkinnedTriangleBatchDataToBinaryFile( std::ofstream* binaryExportFile, CBExportSkinnedMesh* meshToWrite ) {
CBMaterialManager& materialManager = CBMaterialManager::getSharedMaterialManager();
int totalNumTriBatches = 0;
const std::map& triBatchMap = meshToWrite->getTriBatchMap();
totalNumTriBatches = static_cast( triBatchMap.size() );
binaryExportFile->write( (char*) &totalNumTriBatches, sizeof( totalNumTriBatches ) );
std::map::const_iterator itBatch;
for ( itBatch = triBatchMap.begin(); itBatch != triBatchMap.end(); ++itBatch ) {
IGameMaterial* batchMaterial = itBatch->first;
CBTriBatch* triBatch = itBatch->second;
int materialIndex = materialManager.getIndexOfIGameMaterial( batchMaterial );
if ( materialIndex != MATERIAL_NOT_FOUND ) {
binaryExportFile->write( (char*) &materialIndex, sizeof( materialIndex ) );
const std::vector& triBatchVerts = triBatch->getVerts();
int numVertsInBatch = static_cast( triBatchVerts.size() );
binaryExportFile->write( (char*) &numVertsInBatch, sizeof( numVertsInBatch ) );
for ( int i = 0; i < numVertsInBatch; ++i ) {
// Extract Vert Data
const CBMeshVertex& meshVert = triBatchVerts[i];
const cbengine::Vertex& vert = meshVert.getVertex();
binaryExportFile->write( (char*) &vert, sizeof( cbengine::Vertex ) );
// Extract Bone Data
const std::multiset& vertBones = meshVert.getSkeletalBones();
std::multiset::const_iterator itBone;
int numBones = static_cast( vertBones.size() );
binaryExportFile->write( (char*) &numBones, sizeof( numBones ) );
for ( itBone = vertBones.begin(); itBone != vertBones.end(); ++itBone ) {
const CBSkeletalBone& boneToExtract = *(itBone);
int boneIndex = boneToExtract.getBoneIndex();
float boneWeight = boneToExtract.getBoneWeight();
binaryExportFile->write( (char*) &boneIndex, sizeof( boneIndex ) );
binaryExportFile->write( (char*) &boneWeight, sizeof( boneWeight ) );
}
}
} else {
// SHIT
assert( true == true );
}
}
}
void CBMeshFileExporter::getDiffuseTextureFilePath( IGameMaterial* material, std::string& diffuseTextureName ) {
diffuseTextureName = "None";
if ( material == nullptr ) {
return;
}
int textureCount = material->GetNumberOfTextureMaps();
for ( int j = 0; j < textureCount; ++j ) {
IGameTextureMap* textureMap = material->GetIGameTextureMap(j);
if ( textureMap != nullptr ) {
if ( textureMap->IsEntitySupported() ) {
int textureType = textureMap->GetStdMapSlot();
if ( textureType == ID_DI ) {
const TCHAR* textureNameWideChar = textureMap->GetBitmapFileName();
cbengine::convertWideCharToString( textureNameWideChar, diffuseTextureName );
}
}
}
}
}
void CBMeshFileExporter::getSpecularColorTextureFilePath( IGameMaterial* material, std::string& specularTextureName ) {
specularTextureName = "None";
if ( material == nullptr ) {
return;
}
int textureCount = material->GetNumberOfTextureMaps();
for ( int j = 0; j < textureCount; ++j ) {
IGameTextureMap* textureMap = material->GetIGameTextureMap(j);
if ( textureMap != nullptr ) {
if ( textureMap->IsEntitySupported() ) {
int textureType = textureMap->GetStdMapSlot();
if ( textureType == ID_SP ) { // SPEC COLOR
const TCHAR* textureNameWideChar = textureMap->GetBitmapFileName();
cbengine::convertWideCharToString( textureNameWideChar, specularTextureName );
}
}
}
}
}
void CBMeshFileExporter::getSpecularLevelTextureFilePath( IGameMaterial* material, std::string& specularLevelTextureName ) {
specularLevelTextureName = "None";
if ( material == nullptr ) {
return;
}
int textureCount = material->GetNumberOfTextureMaps();
for ( int j = 0; j < textureCount; ++j ) {
IGameTextureMap* textureMap = material->GetIGameTextureMap(j);
if ( textureMap != nullptr ) {
if ( textureMap->IsEntitySupported() ) {
int textureType = textureMap->GetStdMapSlot();
if ( textureType == ID_SS ) { // SPEC COLOR
const TCHAR* textureNameWideChar = textureMap->GetBitmapFileName();
cbengine::convertWideCharToString( textureNameWideChar, specularLevelTextureName );
}
}
}
}
}
void CBMeshFileExporter::getNormalMapTextureFilePath( IGameMaterial* material, std::string& normalMapTextureName ) {
normalMapTextureName = "None";
if ( material == nullptr ) {
return;
}
int textureCount = material->GetNumberOfTextureMaps();
for ( int j = 0; j < textureCount; ++j ) {
IGameTextureMap* textureMap = material->GetIGameTextureMap(j);
if ( textureMap != nullptr ) {
if ( textureMap->IsEntitySupported() ) {
int textureType = textureMap->GetStdMapSlot();
if ( textureType == ID_BU ) {
const TCHAR* textureNameWideChar = textureMap->GetBitmapFileName();
cbengine::convertWideCharToString( textureNameWideChar, normalMapTextureName );
}
} else {
// no supported by IGameTextureMap, lets check if we can support it otherwise
Mtl* maxmtl = material->GetMaxMaterial();
StdMat* stdmtl = 0;
if ( maxmtl && maxmtl->ClassID() == Class_ID(DMTL_CLASS_ID,0) )
stdmtl = static_cast( maxmtl );
StdMat2* stdmtl2 = 0;
if ( stdmtl && stdmtl->SupportsShaders() )
stdmtl2 = static_cast( stdmtl );
if ( stdmtl )
{
const int mapslot = ID_BU;
const int chn = stdmtl2 ? stdmtl2->StdIDToChannel(mapslot) : mapslot;
Texmap* texmap = stdmtl->GetSubTexmap( chn );
if ( texmap->NumSubTexmaps() > 0 )
{
Texmap* submap = texmap->GetSubTexmap( 0 );
if ( submap && submap->ClassID() == Class_ID(BMTEX_CLASS_ID,0) )
{
BitmapTex* bmptex = static_cast( submap );
if ( bmptex->GetMapName() )
{
const TCHAR* textureNameWideChar = bmptex->GetMapName();
cbengine::convertWideCharToString( textureNameWideChar, normalMapTextureName );
// NOTE: we dont support crop or uv offset/tiling but we just ignore those here
}
}
}
}
}
}
}
}
void CBMeshFileExporter::getEmissiveTextureFilePath( IGameMaterial* material, std::string& emissiveTextureName ) {
emissiveTextureName = "None";
if ( material == nullptr ) {
return;
}
int textureCount = material->GetNumberOfTextureMaps();
for ( int j = 0; j < textureCount; ++j ) {
IGameTextureMap* textureMap = material->GetIGameTextureMap(j);
if ( textureMap != nullptr ) {
if ( textureMap->IsEntitySupported() ) {
int textureType = textureMap->GetStdMapSlot();
if ( textureType == ID_SI ) {
const TCHAR* textureNameWideChar = textureMap->GetBitmapFileName();
cbengine::convertWideCharToString( textureNameWideChar, emissiveTextureName );
}
}
}
}
}