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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
Without use library you can change directly in FreeFrom object:
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!!!
Hi Fisad read this topic
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.
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...
@tempo,
You're right, I've used your technique to duplicate a Mesh and show its duplicate as the selected object
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 ;)
@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.