unity-game-engine3dvirtual-realitymeshlab

How are molecules colored in common molecular visualization software?


I will try to describe this situation as accurately as possible, apologies if some details are missing.

A few years ago we began experimenting with virtual reality apps for STEM education developed in Unity. We were specifically interested in viewing molecular structures of proteins and small molecules. Since we weren't sure of the computational load of loading full structures, we decided to first try downloading the molecules from the RCSB database into Chimera, coloring and styling them the way we wanted, then saving them as 3D objects and importing them into Unity. This worked except it striped out all of the colors (for some reason, this didn't happen to small molecules downloaded from PubChem). We tried a variety of methods to see if we could preserve the colors. We saved in every common 3d file format, we tried converting between formats, we tried passing through different 3d modeling software (Blender, Rhino and MeshLab). I seem to recall MeshLab loaded the colors correctly but we still couldn't get them correctly into Unity.

I did a deep dive in the web to see if I could find an answer and the best I was able to do was to find a website that implied that by convention, most molecular visualization software colored the molecules using vertex coloring instead of meshes. That sounds odd to me, especially when talking about molecular surfaces, but I've never been able to find the site again to explore the issue in more depth.

It's mostly a moot point now as we switched to UnityMol once we became more comfortable with the development process, but a reviewer on one of our manuscripts is interested in the technical challenges we faced in development. I would like to mention the color issue but preferably in a way that makes sense. Does anyone who has worked in the molecular visualization space have any idea what I'm talking about?


Solution

  • I think the source of the confusion stems from the fact that most of the standard Unity shaders don't represent vertex colors in any way. You would need a custom shader for that or AFAIK the Unity standard particle shader also shows vertex colors.

    Vertex colors are not used 'instead' of meshes but on top of the other vertex data inside the mesh, such as: Vector3 for position, Vector2 uv (or texcoord), Color for vertex color (float4 inside a shader) and so on. For any mesh or 3D model, some of them are optional, as with vertex colors.

    Many 3D models do not "use" vertex colors in any way so they often aren't even saved inside the model file. Still, if you want to work without textures but have some nice colors, vertex colors are perfect for that (e.g. in scientific contexts).

    Let me know if this helps or if you need more information!