From 625d2b7c4aead89ab406c953d8d46faa0c8f4578 Mon Sep 17 00:00:00 2001 From: Adam Petrone Date: Sat, 30 Aug 2014 00:39:03 -0400 Subject: [PATCH] Fix #325; Blender UV unwrap issue The BMesh converter might be missing more details, but this should get basic UVs working for now. --- code/BlenderBMesh.cpp | 20 ++++++++++++++++++++ code/BlenderBMesh.h | 1 + 2 files changed, 21 insertions(+) diff --git a/code/BlenderBMesh.cpp b/code/BlenderBMesh.cpp index 0e517f4c8..47dd657fc 100644 --- a/code/BlenderBMesh.cpp +++ b/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 diff --git a/code/BlenderBMesh.h b/code/BlenderBMesh.h index 47afbf437..f26a2a043 100644 --- a/code/BlenderBMesh.h +++ b/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;