Ejemplo n.º 1
0
bool CModelExporter::ExportNode( IGameNode* pNode )
{
    IGameMesh* pMesh = (IGameMesh*)pNode->GetIGameObject();
    IGameMaterial* pRootMat = pNode->GetNodeMaterial();

    pMesh->SetUseWeightedNormals();
    pMesh->InitializeData();
    int uFaceCount = pMesh->GetNumberOfFaces();

    for(int i = 0; i < uFaceCount; ++i)
    {
        FaceEx* pFace = pMesh->GetFace(i);
        for(int  j = 0; j < 3; ++j)
        {
            DWORD mapIndex[3];
            Point3 ptUV;
            int indexUV = pFace->texCoord[j];
            IGameTextureMap* pMap = GetTextureMap(pRootMat, ID_DI);
            int nChannel = pMap->GetMapChannel();
            if(pMesh->GetMapFaceIndex(nChannel, pFace->meshFaceIndex, mapIndex))
                ptUV = pMesh->GetMapVertex(nChannel, mapIndex[j]);
            else
                ptUV = pMesh->GetMapVertex(nChannel, indexUV);

            int indexPos = pFace->vert[j];
            Point3 pos = pMesh->GetVertex(indexPos);
        }
    }

    return true;
}
Ejemplo n.º 2
0
void CModelExporter::ExportMaterialTexture( IGameNode* pNode, IGameMaterial* pMat )
{
    IGameTextureMap* pTex = GetTextureMap(pMat, ID_DI);
    if(pTex != NULL)
    {
        this->ExportTexture(pNode, pMat, pTex);
    }
    bool bSetOpacityTexture = GetTextureMap(pMat, ID_OP) != NULL;
    if (bSetOpacityTexture)
    {
        IGameTextureMap* pTex = GetTextureMap(pMat, ID_OP);
        const TCHAR* pszTexFileName = pTex->GetBitmapFileName();
        BEATS_ASSERT(pszTexFileName != NULL);
        std::string textureName = GetFileFullNameFromPathName(pszTexFileName, (size_t)_tcslen(pszTexFileName));
        bSetOpacityTexture = textureName.length() > 0;
    }
    m_serializer << bSetOpacityTexture;
}
Ejemplo n.º 3
0
void CModelExporter::ExportMeshVertex(IGameNode* /*pNode*/, IGameMesh* pMesh, IGameMaterial* pMat, size_t uMatID, BOOL bMultiMat)
{
    pMesh->SetUseWeightedNormals();
    pMesh->InitializeData();

    Tab<FaceEx*> faceTab;

    CollectMeshFaces(faceTab, pMesh, uMatID, bMultiMat);
    size_t uFaceCount = faceTab.Count();
    size_t uVertexCount = uFaceCount * 3;
    m_serializer << uVertexCount;

    BOOL bDiffusemap = GetTextureMap(pMat, ID_DI) == NULL ? FALSE : TRUE;
    BOOL bNormalmap = GetTextureMap(pMat, ID_BU) == NULL ? FALSE : TRUE;
    BOOL bSpecularmap = GetTextureMap(pMat, ID_SS) == NULL ? FALSE : TRUE;
    BOOL bLightmap = GetTextureMap(pMat, ID_AM) == NULL ? FALSE : TRUE;
    float centerX = 0;
    float centerY = 0;
    float centerZ = 0;
    for(size_t i = 0; i < uFaceCount; ++i)
    {
        FaceEx* pFace = faceTab[i];
        for(int  j = 0; j < 3; ++j)
        {
            DWORD mapIndex[3];
            Point3 ptUV;
            int indexUV = pFace->texCoord[j];
            int nChannel = 0;
            if(bDiffusemap || bNormalmap || bSpecularmap)
            {
                IGameTextureMap* pMap = GetTextureMap(pMat, ID_DI);
                nChannel = pMap->GetMapChannel();
            }
            else if(bLightmap)
            {
                IGameTextureMap* pMap = GetTextureMap(pMat, ID_AM);
                nChannel = pMap->GetMapChannel();
            }
            if(pMesh->GetMapFaceIndex(nChannel, pFace->meshFaceIndex, mapIndex))
                ptUV = pMesh->GetMapVertex(nChannel, mapIndex[j]);
            else
                ptUV = pMesh->GetMapVertex(nChannel, indexUV);
            int indexPos = pFace->vert[j];
            Point3 pos = pMesh->GetVertex(indexPos);

            m_serializer << pos.x << pos.y << pos.z;
            m_serializer << ptUV.x << ptUV.y;
            centerX += pos.x;
            centerY += pos.y;
            centerZ += pos.z;
        }
    }
    if (uFaceCount > 0)
    {
        centerX /= (uFaceCount * 3);
        centerY /= (uFaceCount * 3);
        centerZ /= (uFaceCount * 3);
        m_serializer << centerX << centerY << centerZ;
    }
}
Ejemplo n.º 4
0
void MaterialHandler::ProcessData(FbxSurfaceMaterial* pMaterial, unsigned int materialCount, MaterialExport* outputMat, SceneMap* sceneMap)
{
	MaterialHeader materialStruct;
	
	
	//diffuse property
	FbxProperty diffProp = pMaterial->FindProperty(FbxSurfaceMaterial::sDiffuse);
	unsigned int diffMapCount = diffProp.GetSrcObjectCount<FbxFileTexture>();
	
	memcpy(materialStruct.matName, pMaterial->GetName(), sizeof(char) * 256);

	materialStruct.Id = sceneMap->materialHash[pMaterial->GetName()];
	//check if there are texturemaps
	if (diffMapCount > 0)
	{
		memcpy(materialStruct.diffMap, GetTextureMap(diffProp), sizeof(char) * 256);
		materialStruct.diffuseVal[0] = 0.0f;
		materialStruct.diffuseVal[1] = 0.0f;
		materialStruct.diffuseVal[2] = 0.0f;
	}
	else
	{
		GetDiffuse(pMaterial, materialStruct.diffuseVal);
		memcpy(materialStruct.diffMap, "", sizeof(char) * 256);
	}

	//SpecularProperty
	FbxProperty specProp = pMaterial->FindProperty(FbxSurfaceMaterial::sSpecular);
	unsigned int specMapCount = specProp.GetSrcObjectCount<FbxFileTexture>();
	FbxSurfacePhong* tmpCompare = (FbxSurfacePhong*)pMaterial;
	if (specMapCount > 0)
	{
		memcpy(materialStruct.specMap, GetSpecularMap(specProp), sizeof(char) * 256);
		materialStruct.specularVal[0] = 0.0f;
		materialStruct.specularVal[1] = 0.0f;
		materialStruct.specularVal[2] = 0.0f;
		
	}
	else
	{
		if (pMaterial->GetClassId().Is(FbxSurfacePhong::ClassId))
		{
			GetSpecular(pMaterial, materialStruct.specularVal);
			memcpy(materialStruct.specMap, "", sizeof(char) * 256);
		}
		else
		{
			materialStruct.specularVal[0] = 0.0f;
			materialStruct.specularVal[1] = 0.0f;
			materialStruct.specularVal[2] = 0.0f;
			memcpy(materialStruct.specMap, "", sizeof(char) * 256);
		}

	}

	//NormalMap properties
	FbxProperty normMapProp = pMaterial->FindProperty(FbxSurfaceMaterial::sNormalMap);
	unsigned int normMapCount = normMapProp.GetSrcObjectCount<FbxFileTexture>();

	if (normMapCount > 0)
	{
		memcpy(materialStruct.normalMap, GetNormalMap(normMapProp), sizeof(char) * 256);
	}
	else
	{

		memcpy(materialStruct.normalMap, "", sizeof(char) * 256);
	}

	//GlowMap proporties
	
	FbxProperty glowMapProp = pMaterial->FindProperty(FbxSurfaceMaterial::sEmissive);
	unsigned int glowMapCount = glowMapProp.GetSrcObjectCount<FbxFileTexture>();

	if (glowMapCount > 0)
	{
		memcpy(materialStruct.glowMap, GetGlowMap(glowMapProp), sizeof(char) * 256);
	}
	else
	{
		memcpy(materialStruct.glowMap, "", sizeof(char) * 256);
	}

	outputMat->materials->push_back(materialStruct);
	std::cout << "";
	
}