From c84a14a7a8ae4329114269a0ffc1921c838eda9e Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Fri, 3 Feb 2012 18:16:15 +0000 Subject: [PATCH] [3118522] OBJ material/texture filename with spaces support. I also added a test case for this issue. (see https://sourceforge.net/tracker/?func=detail&aid=3118522&group_id=226462&atid=1067632) git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1157 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/ObjTools.h | 11 ++- test/models/OBJ/box_mat_with_spaces.obj | 30 ++++++++ test/models/OBJ/box_spaces.mtl | 99 +++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 test/models/OBJ/box_mat_with_spaces.obj create mode 100644 test/models/OBJ/box_spaces.mtl diff --git a/code/ObjTools.h b/code/ObjTools.h index 6eb034d6c..6f9a54444 100644 --- a/code/ObjTools.h +++ b/code/ObjTools.h @@ -146,7 +146,8 @@ inline char_t skipLine( char_t it, char_t end, unsigned int &uiLine ) return it; } -/** @brief Get a name, must be separated with a blank. +/** @brief Get a name from the current line. Preserve space in the middle, + * but trim it at the end. * @param it set to current position * @param end set to end of scratch buffer for readout * @param name Separated name @@ -161,8 +162,14 @@ inline char_t getName( char_t it, char_t end, std::string &name ) return end; char *pStart = &( *it ); - while ( !isEndOfBuffer( it, end ) && !isSeparator( *it ) ) + while ( !isEndOfBuffer( it, end ) && !isNewLine( *it ) ) { ++it; + } + + while(isEndOfBuffer( it, end ) || isNewLine( *it ) || isSeparator(*it)) { + --it; + } + ++it; // Get name std::string strName( pStart, &(*it) ); diff --git a/test/models/OBJ/box_mat_with_spaces.obj b/test/models/OBJ/box_mat_with_spaces.obj new file mode 100644 index 000000000..adb970eba --- /dev/null +++ b/test/models/OBJ/box_mat_with_spaces.obj @@ -0,0 +1,30 @@ +# Vertices: 8 +# Points: 0 +# Lines: 0 +# Faces: 6 +# Materials: 1 +mtllib ./box_spaces.mtl +o 1 + +# Vertex list + +v -0.5 -0.5 0.5 +v -0.5 -0.5 -0.5 +v -0.5 0.5 -0.5 +v -0.5 0.5 0.5 +v 0.5 -0.5 0.5 +v 0.5 -0.5 -0.5 +v 0.5 0.5 -0.5 +v 0.5 0.5 0.5 + +# Point/Line/Face list + +usemtl Material name with many, many spaces +f 4 3 2 1 +f 2 6 5 1 +f 3 7 6 2 +f 8 7 3 4 +f 5 8 4 1 +f 6 7 8 5 + +# End of file diff --git a/test/models/OBJ/box_spaces.mtl b/test/models/OBJ/box_spaces.mtl new file mode 100644 index 000000000..0e0cc244e --- /dev/null +++ b/test/models/OBJ/box_spaces.mtl @@ -0,0 +1,99 @@ +# Max2Mtl Version 4.0 Mar 10th, 2001 +# +newmtl Material name with many, many spaces +Ka 0.2 0.2 0.2 +Kd 0.2 0.2 0.2 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Door +Ka 0.8 0.6 0.4 +Kd 0.8 0.6 0.4 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Floor +Ka 0.9 0.9 0.7 +Kd 0.9 0.9 0.7 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Rafter +Ka 0.8 0.5 0.2 +Kd 0.8 0.5 0.2 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Ridging +Ka 0.4 0.3 0.3 +Kd 0.4 0.3 0.3 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Sill +Ka 0.2 0.2 0.2 +Kd 0.2 0.2 0.2 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Site +Ka 0.5 0.7 0.4 +Kd 0.5 0.7 0.4 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Roof +Ka 0.9 0.9 0.6 +Kd 0.9 0.9 0.6 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Terraindæk +Ka 0.4 0.3 0.3 +Kd 0.4 0.3 0.3 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Wall-inner +Ka 0.8 0.7 0.5 +Kd 0.8 0.7 0.5 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Wall-out +Ka 0.5 0.0 0.0 +Kd 0.5 0.0 0.0 +Ks 0.9 0.9 0.9 +d 1.0 +Ns 0.0 +illum 2 +# +newmtl Windows +Ka 0.6 0.7 0.8 +Kd 0.6 0.7 0.8 +Ks 0.9 0.9 0.9 +d 0.5 +Ns 0.0 +illum 2 +# +# EOF