2
0
Эх сурвалжийг харах

Fix #325; Blender UV unwrap issue

The BMesh converter might be missing more details, but this should get basic UVs working for now.
Adam Petrone 11 жил өмнө
parent
commit
625d2b7c4a

+ 20 - 0
code/BlenderBMesh.cpp

@@ -143,9 +143,13 @@ void BlenderBMeshConverter::DestroyTriMesh( )
 void BlenderBMeshConverter::ConvertPolyToFaces( const MPoly& poly )
 {
 	const MLoop* polyLoop = &BMesh->mloop[ poly.loopstart ];
+	const MLoopUV* loopUV = &BMesh->mloopuv[ poly.loopstart ];
+	
 	if ( poly.totloop == 3 || poly.totloop == 4 )
 	{
 		AddFace( polyLoop[ 0 ].v, polyLoop[ 1 ].v, polyLoop[ 2 ].v, poly.totloop == 4 ? polyLoop[ 3 ].v : 0 );
+		
+		AddTFace( loopUV[ 0 ].uv, loopUV[ 1 ].uv, loopUV[ 2 ].uv, poly.totloop == 4 ? loopUV[ 3 ].uv : 0 );
 	}
 	else if ( poly.totloop > 4 )
 	{
@@ -173,4 +177,20 @@ void BlenderBMeshConverter::AddFace( int v1, int v2, int v3, int v4 )
 	triMesh->totface = triMesh->mface.size( );
 }
 
+// ------------------------------------------------------------------------------------------------
+void BlenderBMeshConverter::AddTFace( const float* uv1, const float *uv2, const float *uv3, const float* uv4 )
+{
+	MTFace mtface;
+	memcpy( &mtface.uv[ 0 ], uv1, sizeof(float) * 2 );
+	memcpy( &mtface.uv[ 1 ], uv2, sizeof(float) * 2 );
+	memcpy( &mtface.uv[ 2 ], uv3, sizeof(float) * 2 );
+	
+	if ( uv4 )
+	{
+		memcpy( &mtface.uv[ 3 ], uv4, sizeof(float) * 2 );
+	}
+	
+	triMesh->mtface.push_back( mtface );
+}
+
 #endif // ASSIMP_BUILD_NO_BLEND_IMPORTER

+ 1 - 0
code/BlenderBMesh.h

@@ -80,6 +80,7 @@ namespace Assimp
 		void DestroyTriMesh( );
 		void ConvertPolyToFaces( const Blender::MPoly& poly );
 		void AddFace( int v1, int v2, int v3, int v4 = 0 );
+		void AddTFace( const float* uv1, const float* uv2, const float *uv3, const float* uv4 = 0 );
 
 		const Blender::Mesh* BMesh;
 		Blender::Mesh* triMesh;