ofxAssimpModelLoader adding mesh colors (for tangents)

I’m trying to use mesh colors to store the vertex tangents. I’m able to get the meshes and calculate the tangents, but i can’t find a way to modify the mesh in the ofxAssimpModelLoader. This line doesnt work:

ofMesh* meshPtr = &model.getMesh(i);

I get no compile error but the pointed mesh is empty (no vertices, indices, etc).

I tried using the “ofxAssimpMeshHelper”. I was able to set a pointer to the “cachedMesh” and “aiMesh”, but in both cases i wasnt modifying the meshes of the ofxAssimpModelLoader.

2 questions:
1 - is there a way to modify that mesh (i cant transfer it to an ofMesh and use that, it’s an animated model)

2 - i saw in the “aiMesh” from the ofxAssimpMeshHelper that it already contained tangents (and bitangents). Is there a way to access those from a vertex shader? Like does the renderer pass them like it does for vertex positions, normals, colors and texture coordinates?

Wow it is a super specific application!
I would recommend you to fork ofxAssimpModelLoader and be free to make your modifications to fit your purpose, this way you can advance and try different implementations of your idea.

Do you need to update the mesh itself to be able to export an animated and edited mesh after? or just for display on screen?

Tks for the answer!

I need the tangents in my fragment shader in order to do normal mapping and anisotropic reflection. I thought this was pretty standard. Is there another way to do it?

I’m sorry, i’m not familiar with this. I googled it and it seems to be something related to creating new processes. I’m not sure i understand what you are suggesting.

Im not sure i understand this question either. The animation is handled by ofxAssimpModelLoader. I don’t want to do them manually, that’s why i cant just take the mesh and draw it.

I need to add colors to the meshes of the ofxAssimpModelLoader. I’m not going to add colors, i’m going to use the color vectors to store my tangents. That way i will be able to access them through the “in color” in my fragment shader. If there is a way to directly access the tangents that seems to already be there from my shader, i wont need to mod the mesh.

two ideas:
1 - you get the mesh for every animation frame, modify and draw, so you have both the animationg going and your modified mesh.

2 - by the fork I mean, you actually modify ofxAssimpModelLoader in your computer to meet your expectations, or by turning public your needed tangents or by adding a way of returning this data, so you don’t need to be constrained of how ofxAssimpModelLoader works today.

Humm, since i just have to mod the colors and i dont have much going on in that scene, this might work. Tks, ill try that.

I tried that but the mesh is stored in an “aiMesh” in the loader. When you call “getMesh”, the method converts the aiMesh to a ofMesh. Thats why even though i was able to set a pointer to the ofMesh i got, i wasnt actually modifying the real mesh. I was able to figure out where the colors are stored in that aiMesh, but i dont understand how the storing is done. It seems to use arrays instead of vectors. From what i understand, if the loaded model did not have any color, it’s not possible to add colors to the aiMesh afterwards (because the size of the array is “0” and not extendable). I’m not 100% sure of all this, but that’s how i interpreted it.

You probably have to look at Assimp project to know more about aiMesh
https://assimp-docs.readthedocs.io/en/v5.1.0/

1 Like