Hello. I’m developing a program that has as entry a list of polygons identifiers with a color associated to each one. This list is the output of another independent program that solves illumination problems and calculates the color of each polygon in a static mesh. The goal is to apply the colors to the static mesh and show the result.
Then, my question is if is there a way to edit the color of each polygon of a static mesh in Unreal Engine at runtime, or some c++ plugin that I could use to solve this.
Off hand depending on complexity of the mesh you could use modeling software like Maya or blender to give different material IDs to each face then unreal would pick that up and you could make a blueprint that would assign a material at runtime.
I have never tried it in unreal alone, I know there was something on here a while back about this but i cannot find the question. My way would be to model lets say a cube in a 3d modeling program. Assign 6 different materials, one to each face, they dont have to be permanent because you can override them in unreal. Then in unreal, in the mesh editor you will have 6 material slots to either assign a material or in blueprint you can you assign a material. I will keep looking for the question posted earlier about this, i think it was 4 months ago. I know its possible, I will try to answer back today unless someone beats me to it.
Yeah it’s fairly easy to do. Get FRawMesh from your UStaticMesh, it has WedgeColors member (FColor), this is where vertex colors per index are. Change them, then you can rebuild your UStaticMesh from the changed FRawMesh.
Looks like you are not building in Editor mode. RawMesh will only work in Editor, since that particular code block is in WITH_EDITORONLY_DATA ifdef. You are also linking in UnrealEd, which is also an Editor only module I believe, so you should be building Editor.
I switched to DebugGame_editor and the problem was solved immediately! I really thank you for your time and your fast answers! Now I will try to paint those triangles!
Hey! It’s me again, I’m having a lot of problems trying to set the colors. The wedgecolors array is empty, and when I insert colors in this array the engine crashes instantly, and the same happens when I do many other actions using the model, and when this happens the project gets broken and keeps broken when I undo changes, it’s really annoying.
Some idea to solve this? Is there a problem or conflict with materials associated with faces? The rawMesh.FaceMaterialIndices array has information, all the faces have the same material associated.
I tried loading a material with a parameter in the basecolor too, but when I instantiate the dynamic material the project crashes.