浏览代码

IRRMESH/IRR
- improved handling of materials with multiple textures
- BUG: lightmapping is now broken for the moment

AssimpView
- Skyboxes and bg images work again
- Improved lightmap handling.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@341 67173fc5-114c-0410-ac8e-9d2fd5bffc1f

aramis_acg 16 年之前
父节点
当前提交
055c3f0d24

+ 4 - 1
code/IRRMeshLoader.cpp

@@ -217,12 +217,15 @@ void IRRMeshImporter::InternReadFile( const std::string& pFile,
 						int idx = 1;
 						int idx = 1;
 						MaterialHelper* mat = ( MaterialHelper* ) curMat;
 						MaterialHelper* mat = ( MaterialHelper* ) curMat;
 
 
-						if (curMatFlags & (AI_IRRMESH_MAT_solid_2layer | AI_IRRMESH_MAT_lightmap)){
+						if (curMatFlags & AI_IRRMESH_MAT_lightmap){
 							mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_LIGHTMAP(0));
 							mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_LIGHTMAP(0));
 						}
 						}
 						else if (curMatFlags & AI_IRRMESH_MAT_normalmap_solid){
 						else if (curMatFlags & AI_IRRMESH_MAT_normalmap_solid){
 							mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_NORMALS(0));
 							mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_NORMALS(0));
 						}
 						}
+						else if (curMatFlags & AI_IRRMESH_MAT_solid_2layer) {
+							mat->AddProperty(&idx,1,AI_MATKEY_UVWSRC_DIFFUSE(1));
+						}
 					}
 					}
 				}
 				}
 				else if (!ASSIMP_stricmp("tangents", t))
 				else if (!ASSIMP_stricmp("tangents", t))

+ 28 - 9
code/IRRShared.cpp

@@ -275,6 +275,11 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
 						: aiShadingMode_NoShading);
 						: aiShadingMode_NoShading);
 					mat->AddProperty(&val,1,AI_MATKEY_SHADING_MODEL);
 					mat->AddProperty(&val,1,AI_MATKEY_SHADING_MODEL);
 				}
 				}
+				else if (prop.name == "BackfaceCulling")
+				{
+					int val = (!prop.value);
+					mat->AddProperty(&val,1,AI_MATKEY_TWOSIDED);
+				}
 			}
 			}
 			// String properties - textures and texture related properties
 			// String properties - textures and texture related properties
 			else if (!ASSIMP_stricmp(reader->getNodeName(),"texture") ||
 			else if (!ASSIMP_stricmp(reader->getNodeName(),"texture") ||
@@ -339,6 +344,9 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
 						{
 						{
 							matFlags = AI_IRRMESH_MAT_normalmap_ta;
 							matFlags = AI_IRRMESH_MAT_normalmap_ta;
 						}
 						}
+						else {
+							DefaultLogger::get()->warn("IRRMat: Unrecognized material type: " + prop.value);
+						}
 					}
 					}
 
 
 					// Up to 4 texture channels are supported
 					// Up to 4 texture channels are supported
@@ -352,8 +360,7 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
 					else if (prop.name == "Texture2")
 					else if (prop.name == "Texture2")
 					{
 					{
 						// 2-layer material lightmapped?
 						// 2-layer material lightmapped?
-						if (matFlags & (AI_IRRMESH_MAT_solid_2layer | AI_IRRMESH_MAT_lightmap))
-						{
+						if (matFlags & AI_IRRMESH_MAT_lightmap)	{
 							++cnt;
 							++cnt;
 							s.Set(prop.value);
 							s.Set(prop.value);
 							mat->AddProperty(&s,AI_MATKEY_TEXTURE_LIGHTMAP(0));
 							mat->AddProperty(&s,AI_MATKEY_TEXTURE_LIGHTMAP(0));
@@ -362,8 +369,7 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
 							matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
 							matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
 						}
 						}
 						// alternatively: normal or parallax mapping
 						// alternatively: normal or parallax mapping
-						else if (matFlags & AI_IRRMESH_MAT_normalmap_solid)
-						{
+						else if (matFlags & AI_IRRMESH_MAT_normalmap_solid)	{
 							++cnt;
 							++cnt;
 							s.Set(prop.value);
 							s.Set(prop.value);
 							mat->AddProperty(&s,AI_MATKEY_TEXTURE_NORMALS(0));
 							mat->AddProperty(&s,AI_MATKEY_TEXTURE_NORMALS(0));
@@ -371,6 +377,15 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
 							// set the corresponding material flag
 							// set the corresponding material flag
 							matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
 							matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
 						}
 						}
+						// or just as second diffuse texture
+						else if (matFlags & AI_IRRMESH_MAT_solid_2layer)	{
+							++cnt;
+							s.Set(prop.value);
+							mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(1));
+
+							// set the corresponding material flag
+							matFlags |= AI_IRRMESH_EXTRA_2ND_TEXTURE;
+						}
 						else DefaultLogger::get()->warn("IRRmat: Skipping second texture");
 						else DefaultLogger::get()->warn("IRRmat: Skipping second texture");
 					}
 					}
 					else if (prop.name == "Texture3")
 					else if (prop.name == "Texture3")
@@ -398,13 +413,17 @@ aiMaterial* IrrlichtBase::ParseMaterial(unsigned int& matFlags)
 					else if (prop.name == "TextureWrap2" && cnt >= 2)
 					else if (prop.name == "TextureWrap2" && cnt >= 2)
 					{
 					{
 						int map = ConvertMappingMode(prop.value);
 						int map = ConvertMappingMode(prop.value);
-						if (matFlags & (AI_IRRMESH_MAT_solid_2layer | AI_IRRMESH_MAT_lightmap)) {
-							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_LIGHTMAP(1));
-							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_LIGHTMAP(1));	
+						if (matFlags & AI_IRRMESH_MAT_lightmap) {
+							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_LIGHTMAP(0));
+							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_LIGHTMAP(0));	
 						}
 						}
 						else if (matFlags & (AI_IRRMESH_MAT_normalmap_solid)) {
 						else if (matFlags & (AI_IRRMESH_MAT_normalmap_solid)) {
-							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_NORMALS(1));
-							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_NORMALS(1));	
+							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_NORMALS(0));
+							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_NORMALS(0));	
+						}
+						else if (matFlags & AI_IRRMESH_MAT_solid_2layer) {
+							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_U_DIFFUSE(1));
+							mat->AddProperty(&map,1,AI_MATKEY_MAPPINGMODE_V_DIFFUSE(1));	
 						}
 						}
 					}
 					}
 					else if (prop.name == "TextureWrap3" && cnt >= 3)
 					else if (prop.name == "TextureWrap3" && cnt >= 3)

+ 3 - 9
code/TextureTransform.cpp

@@ -283,9 +283,7 @@ void TextureTransformStep::Execute( aiScene* pScene)
 					{
 					{
 						// ValidateDS should check this
 						// ValidateDS should check this
 						ai_assert(prop2->mDataLength >= 20); 
 						ai_assert(prop2->mDataLength >= 20); 
-
 						::memcpy(&info.mTranslation.x,prop2->mData,sizeof(float)*5);
 						::memcpy(&info.mTranslation.x,prop2->mData,sizeof(float)*5);
-
 						delete[] prop2->mData;
 						delete[] prop2->mData;
 
 
 						// Directly remove this property from the list 
 						// Directly remove this property from the list 
@@ -344,11 +342,8 @@ void TextureTransformStep::Execute( aiScene* pScene)
 						uv = 0;
 						uv = 0;
 					}
 					}
 					
 					
-					if (mesh->mNumUVComponents[info.uvIndex] >= 3)
-					{
-						DefaultLogger::get()->warn("UV transformations on 3D mapping channels "
-							"are not supported by this step");
-
+					if (mesh->mNumUVComponents[info.uvIndex] >= 3){
+						DefaultLogger::get()->warn("UV transformations on 3D mapping channels are not supported");
 						continue;
 						continue;
 					}
 					}
 
 
@@ -357,8 +352,7 @@ void TextureTransformStep::Execute( aiScene* pScene)
 					// Check whether we have this transform setup already
 					// Check whether we have this transform setup already
 					for (it = meshLists[n].begin();it != meshLists[n].end(); ++it)
 					for (it = meshLists[n].begin();it != meshLists[n].end(); ++it)
 					{
 					{
-						if ((*it) == info && (*it).uvIndex == uv)
-						{
+						if ((*it) == info && (*it).uvIndex == uv)	{
 							(*it).updateList.push_back(update);
 							(*it).updateList.push_back(update);
 							break;
 							break;
 						}
 						}

+ 9 - 2
tools/assimp_view/Background.cpp

@@ -433,6 +433,7 @@ void CBackgroundPainter::RecreateNativeResource()
 	}
 	}
 	if (!piSkyBoxEffect)
 	if (!piSkyBoxEffect)
 	{
 	{
+		ID3DXBuffer* piBuffer = NULL;
 		if(FAILED( D3DXCreateEffect(
 		if(FAILED( D3DXCreateEffect(
 			g_piDevice,
 			g_piDevice,
 			g_szSkyboxShader.c_str(),
 			g_szSkyboxShader.c_str(),
@@ -441,11 +442,17 @@ void CBackgroundPainter::RecreateNativeResource()
 			NULL,
 			NULL,
 			D3DXSHADER_USE_LEGACY_D3DX9_31_DLL,
 			D3DXSHADER_USE_LEGACY_D3DX9_31_DLL,
 			NULL,
 			NULL,
-			&piSkyBoxEffect,NULL)))
+			&piSkyBoxEffect,&piBuffer)))
 		{
 		{
+			// failed to compile the shader
+			if( piBuffer) {
+				MessageBox(g_hDlg,(LPCSTR)piBuffer->GetBufferPointer(),"HLSL",MB_OK);
+				piBuffer->Release();
+			}
+
 			CLogDisplay::Instance().AddEntry("[ERROR] Unable to compile skybox shader",
 			CLogDisplay::Instance().AddEntry("[ERROR] Unable to compile skybox shader",
 				D3DCOLOR_ARGB(0xFF,0xFF,0,0));
 				D3DCOLOR_ARGB(0xFF,0xFF,0,0));
-			this->eMode = SIMPLE_COLOR;
+			eMode = SIMPLE_COLOR;
 			return ;
 			return ;
 		}
 		}
 	}
 	}

+ 10 - 3
tools/assimp_view/Material.cpp

@@ -1025,8 +1025,16 @@ int CMaterialManager::CreateMaterial(
 		sMacro[iCurrent].Definition = "1";
 		sMacro[iCurrent].Definition = "1";
 		++iCurrent;
 		++iCurrent;
 
 
+		int idx;
+		if(AI_SUCCESS == aiGetMaterialInteger(pcMat,AI_MATKEY_UVWSRC_LIGHTMAP(0),&idx) && idx >= 1 && pcSource->mTextureCoords[idx])	{
+			sMacro[iCurrent].Name = "AV_TWO_UV";
+			sMacro[iCurrent].Definition = "1";
+			++iCurrent;
+
+			sMacro[iCurrent].Definition = "IN.TexCoord1";
+		}
+		else sMacro[iCurrent].Definition = "IN.TexCoord0";
 		sMacro[iCurrent].Name = "AV_LIGHTMAP_TEXTURE_UV_COORD";
 		sMacro[iCurrent].Name = "AV_LIGHTMAP_TEXTURE_UV_COORD";
-		sMacro[iCurrent].Definition = "IN.TexCoord0";
 		++iCurrent;
 		++iCurrent;
 	}
 	}
 	if (pcMesh->piNormalTexture && !bib)
 	if (pcMesh->piNormalTexture && !bib)
@@ -1170,8 +1178,7 @@ int CMaterialManager::CreateMaterial(
 	if (pcMesh->piLightmapTexture)
 	if (pcMesh->piLightmapTexture)
 		pcMesh->piEffect->SetTexture("LIGHTMAP_TEXTURE",pcMesh->piLightmapTexture);
 		pcMesh->piEffect->SetTexture("LIGHTMAP_TEXTURE",pcMesh->piLightmapTexture);
 
 
-	if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
-	{
+	if (CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode()){
 		pcMesh->piEffect->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
 		pcMesh->piEffect->SetTexture("lw_tex_envmap",CBackgroundPainter::Instance().GetTexture());
 	}
 	}
 
 

+ 2 - 2
tools/assimp_view/Shaders.cpp

@@ -217,7 +217,7 @@ std::string g_szSkyboxShader = std::string(
 		"VS_OUTPUT2 Out;\n"
 		"VS_OUTPUT2 Out;\n"
 
 
 		"Out.Position.xy = INPosition.xy;\n"
 		"Out.Position.xy = INPosition.xy;\n"
-		"Out.Position.z = Out._Position.w = 1.0f;\n"
+		"Out.Position.z = Out.Position.w = 1.0f;\n"
 		"Out.TexCoord0 = INTexCoord0;\n"
 		"Out.TexCoord0 = INTexCoord0;\n"
 
 
 		"return Out;\n"
 		"return Out;\n"
@@ -676,7 +676,7 @@ std::string g_szMaterialShader = std::string(
 		"#endif\n"
 		"#endif\n"
 
 
 		"float2 TexCoord0 : TEXCOORD2;\n"
 		"float2 TexCoord0 : TEXCOORD2;\n"
-		"#ifdef AV_DIFFUSE_TEXTURE2 \n"
+		"#ifdef AV_TWO_UV \n"
 		"float2 TexCoord1 : TEXCOORD3;\n"
 		"float2 TexCoord1 : TEXCOORD3;\n"
 		"#endif \n"
 		"#endif \n"