Ver Fonte

# make source UV index for tangent space computation configurable via the AI_CONFIG_PP_CT_TEXTURE_CHANNEL_INDEX option.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1027 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
aramis_acg há 14 anos atrás
pai
commit
323b9d8400
3 ficheiros alterados com 33 adições e 13 exclusões
  1. 18 9
      code/CalcTangentsProcess.cpp
  2. 1 0
      code/CalcTangentsProcess.h
  3. 14 4
      include/aiConfig.h

+ 18 - 9
code/CalcTangentsProcess.cpp

@@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // internal headers
 #include "CalcTangentsProcess.h"
 #include "ProcessHelper.h"
+#include "TinyFormatter.h"
 
 using namespace Assimp;
 
@@ -77,9 +78,11 @@ bool CalcTangentsProcess::IsActive( unsigned int pFlags) const
 void CalcTangentsProcess::SetupProperties(const Importer* pImp)
 {
 	// get the current value of the property
-	this->configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE,45.f);
-	this->configMaxAngle = std::max(std::min(this->configMaxAngle,45.0f),0.0f);
-	this->configMaxAngle = AI_DEG_TO_RAD(this->configMaxAngle);
+	configMaxAngle = pImp->GetPropertyFloat(AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE,45.f);
+	configMaxAngle = std::max(std::min(configMaxAngle,45.0f),0.0f);
+	configMaxAngle = AI_DEG_TO_RAD(configMaxAngle);
+
+	configSourceUV = pImp->GetPropertyInteger(AI_CONFIG_PP_CT_TEXTURE_CHANNEL_INDEX,0);
 }
 
 // ------------------------------------------------------------------------------------------------
@@ -92,7 +95,7 @@ void CalcTangentsProcess::Execute( aiScene* pScene)
 	for( unsigned int a = 0; a < pScene->mNumMeshes; a++)
 		if(ProcessMesh( pScene->mMeshes[a],a))bHas = true;
 
-	if (bHas)DefaultLogger::get()->debug("CalcTangentsProcess finished. Tangents have been calculated");
+	if (bHas)DefaultLogger::get()->info("CalcTangentsProcess finished. Tangents have been calculated");
 	else DefaultLogger::get()->debug("CalcTangentsProcess finished");
 }
 
@@ -117,12 +120,18 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex)
 		return false;
 	}
 
-	// what we can check, though, is if the mesh has normals and texture coord. That's a requirement
-	if( pMesh->mNormals == NULL || pMesh->mTextureCoords[0] == NULL)
+	// what we can check, though, is if the mesh has normals and texture coordinates. That's a requirement
+	if( pMesh->mNormals == NULL)
+	{
+		DefaultLogger::get()->error("Failed to compute tangents; need normals");
+		return false;
+	}
+	if( configSourceUV >= AI_MAX_NUMBER_OF_TEXTURECOORDS || !pMesh->mTextureCoords[configSourceUV] )
 	{
-		DefaultLogger::get()->error("Unable to compute tangents: UV0 and normals must be there ");
+		DefaultLogger::get()->error((Formatter::format("Failed to compute tangents; need UV data in channel"),configSourceUV));
 		return false;
 	}
+	 
 	const float angleEpsilon = 0.9999f;
 
 	std::vector<bool> vertexDone( pMesh->mNumVertices, false);
@@ -134,7 +143,7 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex)
 
 	const aiVector3D* meshPos = pMesh->mVertices;
 	const aiVector3D* meshNorm = pMesh->mNormals;
-	const aiVector3D* meshTex = pMesh->mTextureCoords[0];
+	const aiVector3D* meshTex = pMesh->mTextureCoords[configSourceUV];
 	aiVector3D* meshTang = pMesh->mTangents;
 	aiVector3D* meshBitang = pMesh->mBitangents;
 	
@@ -222,7 +231,7 @@ bool CalcTangentsProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex)
 	}
 	std::vector<unsigned int> verticesFound;
 
-	const float fLimit = cosf(this->configMaxAngle); 
+	const float fLimit = cosf(configMaxAngle); 
 	std::vector<unsigned int> closeVertices;
 
 	// in the second pass we now smooth out all tangents and bitangents at the same local position 

+ 1 - 0
code/CalcTangentsProcess.h

@@ -111,6 +111,7 @@ private:
 
 	/** Configuration option: maximum smoothing angle, in radians*/
 	float configMaxAngle;
+	unsigned int configSourceUV;
 };
 
 } // end of namespace Assimp

+ 14 - 4
include/aiConfig.h

@@ -102,6 +102,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 // Various stuff to fine-tune the behavior of a specific post processing step.
 // ###########################################################################
 
+
 // ---------------------------------------------------------------------------
 /** @brief Maximum bone count per mesh for the SplitbyBoneCount step.
  *
@@ -123,16 +124,25 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 // ---------------------------------------------------------------------------
 /** @brief  Specifies the maximum angle that may be between two vertex tangents
- *         that their tangents and bitangents are smoothed.
+ *         that their tangents and bi-tangents are smoothed.
  *
  * This applies to the CalcTangentSpace-Step. The angle is specified
- * in degrees, so 180 is PI. The default value is
- * 45 degrees. The maximum value is 175.
- * Property type: float. 
+ * in degrees. The maximum value is 175.
+ * Property type: float. Default value: 45 degrees
  */
 #define AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE \
 	"PP_CT_MAX_SMOOTHING_ANGLE"
 
+// ---------------------------------------------------------------------------
+/** @brief Source UV channel for tangent space computation.
+ *
+ * The specified channel must exist or an error will be raised. 
+ * Property type: integer. Default value: 0
+ */
+// ---------------------------------------------------------------------------
+#define AI_CONFIG_PP_CT_TEXTURE_CHANNEL_INDEX \
+	"PP_CT_TEXTURE_CHANNEL_INDEX"
+
 // ---------------------------------------------------------------------------
 /** @brief  Specifies the maximum angle that may be between two face normals
  *          at the same vertex position that their are smoothed together.