Assimp: .blend importer generates corrupted vertex colors.

Created on 26 Jun 2016  路  6Comments  路  Source: assimp/assimp

Hello,
I was testing the assimp importer for blender to see how well It would work in my project and I have to say I am quite satisfied with the results, features and the simplicity of use in assimp as a whole.

But recently when testing vertex colors in my application I noticed that assimp was giving me negative color values for some of the vertices. (needless to say I did not paint in a color value of [-160.0,-160.0,-160.0,-1.0] in blender considering it doesn't even let you set the value below 0 in the vertex painter, and blender doesn't even support vertex alpha). So, I thought it was just my own code that was doing something unusual to the data but then I tried out _assimp viewer_ only to find this bizarre pattern of vertex colors on my model:
Import BLEND file, Bad Vertex Colors
image

I checked to see if this was a bug that applied to the entire library, but when importing the model as a .ply file It displayed perfectly:
Import PLY file, Displayed Accurately
image

I've tried figuring out what was wrong with it myself. I edited the photos using different inversions, color balances and whatever else I could think of. I played with the image channels in blenders compositor. and when that failed I started trying to convert Visual Studio's Debug values of the color channel from (what I assume to be) IEEE-754 floating point into binary/hexadecimal, unsigned integers and whatever I could think of to see where some interpretation of data could have gone astray but I couldn't find the problem, It seems like it somewhat resembles the original model so Its probably not related to any order of processing vertices.

_What I'm using:_
Assimp3.2
Blender 2.77
Visual Studio 2015 Professional
CMake 3.2.2
Win32 Release Build (I have the debug environment set up in my project though)

(As a side-note I have been getting a ton of Handled Exceptions coming from the library, could it possibly be related?)

Exception thrown at 0x76AFC42D in astrengine.exe: Microsoft C++ exception: Assimp::Blender::Error at memory location 0x086BDFC8.
Exception thrown at 0x76AFC42D in astrengine.exe: Microsoft C++ exception: Assimp::Blender::Error at memory location 0x086BDB18.
Exception thrown at 0x76AFC42D in astrengine.exe: Microsoft C++ exception: Assimp::Blender::Error at memory location 0x086BDB18.

   (This Message Repeats about a thousand times, I couldn't tell if the scroll bar was working...)

Exception thrown at 0x76AFC42D in astrengine.exe: Microsoft C++ exception: Assimp::Blender::Error at memory location 0x086BDB18.
Exception thrown at 0x76AFC42D in astrengine.exe: Microsoft C++ exception: Assimp::Blender::Error at memory location 0x086BDB18.
Exception thrown at 0x76AFC42D in astrengine.exe: Microsoft C++ exception: Assimp::Blender::Error at memory location 0x086BDD60.

_My project's design relies heavily on vertex blending to control various shader blending parameters and procedural vertex shader animations, so Vertex Colors are an essential part of the project. I would also like to continue using the current version of blender without complicating the workflow with exporting to other formats (unless skeletal animation is required)._

_Any and all help is greatly appreciated. Thank you!_

Bug

All 6 comments

Just as a notice. This issue is still not resolved yet...

I was just testing vertex colors with blender files, and I also see negative values. I also get the endless stream of exceptions which slows down importing of blender files

The negative colors seems to be caused by this code

template <> inline void Structure :: Convert (char& dest,const FileDatabase& db) const
{
// automatic rescaling from char to float and vice versa (seems useful for RGB colors)
if (name == "float") {
dest = static_cast(db.reader->GetF4() * 255.f);
return;
}
else if (name == "double") {
dest = static_cast(db.reader->GetF8() * 255.f);
return;
}
ConvertDispatcher(dest,*this,db);
}

It is using char, when it should be unsigned char

I'll see if I can figure out this Blender import code and create a patch.

Well I fixed it locally.
One thing I'm not sure about..
Blender importer is converting color to 0-255 range.
But aiColor4D says that color shall be represented as 0-1
Blender importer is not following this, so I think I'll scale it back to 0-1

I put a pull request up that fixes the colors

I fixed the vertex colors, but I see that the blender importer is also mishandling some other colors that it is importing.

I'm not sure what they are though(maybe material colors?) so I'm not going to change that code..

Was this page helpful?
0 / 5 - 0 ratings