- Workaround for Collada exporter in SketchUp 15.3.331 (possibly others) where it'll export the wrong "count" when exporting "lines".

- When I encounter this condition I just print a warning and use the actual number of points in the file instead of the number they give, as opposed to throwing an exception and bailing on the whole file.
	- For an example of this kind of file see https://3dwarehouse.sketchup.com/warehouse/getpubliccontent?contentId=e4587719-2609-49ed-a2f6-20b98d1215f3&fn=Kartell-GE.zip
	- Some people have complained about this on http://forums.sketchup.com/t/bug-in-lines-exported-at-collada-format/8145
pull/615/head
Wil Shipley 2015-05-17 18:36:17 -07:00
parent d1f36bf947
commit 91ca983d5f
2 changed files with 27 additions and 4 deletions

View File

@ -1983,7 +1983,8 @@ void ColladaParser::ReadIndexData( Mesh* pMesh)
}
// small sanity check
if (primType != Prim_TriFans && primType != Prim_TriStrips)
if (primType != Prim_TriFans && primType != Prim_TriStrips &&
primType != Prim_Lines) // this is ONLY to workaround a bug in SketchUp 15.3.331 where it writes the wrong 'count' when it writes out the 'lines'.
ai_assert(actualPrimitives == numPrimitives);
// only when we're done reading all <p> tags (and thus know the final vertex count) can we commit the submesh
@ -2091,9 +2092,15 @@ size_t ColladaParser::ReadPrimitives( Mesh* pMesh, std::vector<InputChannel>& pP
}
// complain if the index count doesn't fit
if( expectedPointCount > 0 && indices.size() != expectedPointCount * numOffsets)
if( expectedPointCount > 0 && indices.size() != expectedPointCount * numOffsets) {
if (pPrimType == Prim_Lines) {
// HACK: We just fix this number since SketchUp 15.3.331 writes the wrong 'count' for 'lines'
ReportWarning( "Expected different index count in <p> element, %d instead of %d.", indices.size(), expectedPointCount * numOffsets);
pNumPrimitives = (indices.size() / numOffsets) / 2;
} else
ThrowException( "Expected different index count in <p> element.");
else if( expectedPointCount == 0 && (indices.size() % numOffsets) != 0)
} else if( expectedPointCount == 0 && (indices.size() % numOffsets) != 0)
ThrowException( "Expected different index count in <p> element.");
// find the data for all sources
@ -2696,6 +2703,21 @@ AI_WONT_RETURN void ColladaParser::ThrowException( const std::string& pError) co
throw DeadlyImportError( boost::str( boost::format( "Collada: %s - %s") % mFileName % pError));
}
void ColladaParser::ReportWarning(const char* msg,...)
{
ai_assert(NULL != msg);
va_list args;
va_start(args,msg);
char szBuffer[3000];
const int iLen = vsprintf(szBuffer,msg,args);
ai_assert(iLen > 0);
va_end(args);
DefaultLogger::get()->warn("Validation warning: " + std::string(szBuffer,iLen));
}
// ------------------------------------------------------------------------------------------------
// Skips all data until the end node of the current element
void ColladaParser::SkipElement()

View File

@ -213,6 +213,7 @@ protected:
protected:
/** Aborts the file reading with an exception */
AI_WONT_RETURN void ThrowException( const std::string& pError) const AI_WONT_RETURN_SUFFIX;
void ReportWarning(const char* msg,...);
/** Skips all data until the end node of the current element */
void SkipElement();