Menu

How to Change Mesh Color

Help
Fisad
2019-03-30
2019-04-12
  • Fisad

    Fisad - 2019-03-30

    How I can change the mesh color at runtime, by code?
    Can somebody show a simple code for change a mesh color by code at runtime?

     
  • shine world

    shine world - 2019-04-01

    Without use library you can change directly in FreeFrom object:

         FreeForm1.Material.LibMaterialName := '';
         FreeForm1.Material.FaceCulling := fcNoCull;
         FreeForm1.Material.BlendingMode := bmOpaque;
         FreeForm1.Material.BackProperties.Diffuse.Alpha := 1;
         FreeForm1.Material.FrontProperties.Diffuse.Alpha := 1;
         FreeForm1.Material.BackProperties.Diffuse.Color := clrOrange;
         FreeForm1.Material.FrontProperties.Diffuse.Color := clrOrange;
    
     
  • Fisad

    Fisad - 2019-04-01

    Thanks for the comment, but I mean a Mesh and not all the freeform.

    It's funny how many of the comments I've read on this site, when a Mesh speaks many respond with the freeform.

    I have a freeform with more than 9500 Mesh objects inside and I need to change the color of one of them only!!!

     
  • Jerome.D (BeanzMaster)

    Hi Fisad read this topic

     
  • Fisad

    Fisad - 2019-04-02

    Thanks Jerome,

    I can understand that the trick is to use the facegroups, I use them for the creation of the mesh but not for the change of color or material.
    I'll try with this way.

     
  • tempo

    tempo - 2019-04-11

    Yes i have the same problems like Fisad.

    I found a crapy way to paint a mesh object with this code

    //Get all Vertices from kind of thoot
    for I := 0 to GLFreeForm1.MeshObjects[11].Vertices.Count -1 do
    begin
    //Paint tooth Nr. 11 in shiny red
    GLFreeForm1.MeshObjects[11].Colors.add(ConvertRGBColor([255,0,0]));
    end

    but i think it is not the clean way.
    Lets try hard...

     
  • Fisad

    Fisad - 2019-04-11

    @tempo,

    You're right, I've used your technique to duplicate a Mesh and show its duplicate as the selected object

     
  • tempo

    tempo - 2019-04-12

    Hi Fisad
    this is my code and it works very nice.

    Important thing is you need to add a lightsource and MaterialLibrary in your FreeForm.

    After that you append you MaterialLibrary to FreeForm and add some Material clicking on the MaterialLibrary1 component, example add "gold" then double click at ( TGLMaterial) in the objektinspector and set the gold color by front back in the Diffuse tab so then look at my code:

    glcmrCamera.MoveAroundTarget(100, 678);

    //Load Obj
    GLFreeForm1.LoadFromFile(ExtractFilePath(ParamStr(0)) + '/3d/mundmitzaehne.3ds'); //Teeth.obj //IncisiveTooth.3DS

    //Alle zähne
    for I := 0 to GLFreeForm1.MeshObjects.Count -1 do
    begin
    GLFreeForm1.MeshObjects[i].FaceGroups[0].MaterialName := 'gold';
    end;

    //zahnfleisch
    GLFreeForm1.MeshObjects.FindMeshByName('lowgums').FaceGroups[0].MaterialName := 'zahnfleisch';
    GLFreeForm1.MeshObjects.FindMeshByName('upgums').FaceGroups[0].MaterialName := 'zahnfleisch';

    //GLFreeForm1.MeshObjects.FindMeshByName('upgums').Clear;

    //Zahn ID: 31 in rot
    GLFreeForm1.MeshObjects[31].FaceGroups[0].MaterialName := 'mrot';

    //Zahn entfehrnen
    GLFreeForm1.MeshObjects[31].Clear;

    GLFreeForm1.Scale.Scale(0.05);
    //GLFreeForm1.Roll(0); // ggf. drehen etc.
    GLFreeForm1.Turn(90);

    I hope it help some one ;)

     
  • Fisad

    Fisad - 2019-04-12

    @tempo,

    Thanks for the tips.

    My application is somewhat different in structure since I create the structure in time of execution and my models can have from 3000 to 60000 Mesh or more.

    Iterate all components becomes a bit slow and expensive in terms of quality and performance. I prefer to store a pointer related to each mesh and then operate using that technique.

    Thanks for your code.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.