Page 1 of 1

Changing colour of mesh face and mesh wireframe

Posted: Tue Jan 07, 2025 12:48 am
by RJD
Hi,

I was wondering if it was possible to change the colour of a collection mesh faces separately to the whole mesh? An example use case might be to highlight a circular section on a mesh surface. Also, I'm not sure how to change the wireframe colour of the mesh. Commands similar to:

Code: Select all

var material = entity.GetAppearance().As<IMaterial_DG>();
material.WireFrameColor = Color.Red;
or

Code: Select all

var material = entity.GetAppearance().As<IMaterial_DG>();
material.SetColor(LightComponent_DG.WireFrame, Color.Red);
don't seem to work.

Thank you in advance!

Re: Changing colour of mesh face and mesh wireframe

Posted: Wed Jan 08, 2025 2:26 am
by Prashant Kande
Hi

There is a way to define per vertex color, but it is not what you are asking about because per vertex color blends the color into all adjacent faces (simplices).

Frankly, per mesh face color does not make much sense to me as a built-in functionality. I am pretty sure the right way for doing this is extracting a sub-mesh for presentation as an entity and applying the color to it.

It is better to offset the presentation mesh outwards along normal slightly to avoid aliasing. IMesh_DG.Offset() is an easy way.

Extraction needs a bit of attention. A safe (not sure the best) way it to build a copy in code similar to the Morph sample. This way offsetting is easy as well.

Regards

Re: Changing colour of mesh face and mesh wireframe

Posted: Wed Jan 08, 2025 9:00 pm
by Measure
Prashant, can you post a code snippet showing how to set the vertex color?

I am using 32-bit ocx. Using IMeshAlgor to create vertexes and IMeshTopol to create simplices. How can I set the color of each vertex in the mesh? I think I need to use IMeshShading_KC but so far I have not gotten the expected results.

Re: Changing colour of mesh face and mesh wireframe

Posted: Thu Jan 09, 2025 3:08 am
by Prashant Kande
Hi Measure,
It is a good question. It was a while since I touched this.

My quick look produced this:
We used to have "Shading" check box in Morph.
PerVertexMorph.png
PerVertexMorph.png (122.9 KiB) Viewed 789 times
But it was removed a while ago. I do not remember the reason. I will dig in the next few days and will post more here. It works in v5.2. This is where the screenshot comes from.

Just recently I saw per vertex colors working in v7.2 where the mesh was imported via VRML. So, as the worst-case scenario you could generated the vrml in memory (not too bad coding). I think there should be a better way.

Thanks for pointing out the problem.

Re: Changing colour of mesh face and mesh wireframe

Posted: Thu Jan 09, 2025 2:24 pm
by Measure
OK, helpful thank you.

I was able to produce a similar example.

1) Use IMeshAlgor to add vertex points.
2) Use IMeshShading_KC to setShadingType and then update color for each vertex using SetVertexColor
3) Use IMeshTopol to add simplex from the verticies using AddSimplex

So that works but I have to manually load the mesh facet by facet.

If I create the mesh via loading the file, is there a way to iterate thru the mesh and update the vertex color? Should I use IIterator object for this?

Thanks!

Re: Changing colour of mesh face and mesh wireframe

Posted: Thu Jan 09, 2025 9:09 pm
by Prashant Kande
Great.
Yes, just iterate the vertices. Here is the snippet from v5.2 C++ Morph CMorphDlg::OnShading()OnShading()

Code: Select all

			IIteratorT* iVertexIterator;
			m_iMesh->GetVertexIterator(&iVertexIterator);
			INT_PTR posnVertex = 0;
			iVertexIterator->GetHeadPosition(&posnVertex);

			byte color[3];	// Integers in range 0 to 255

			while(posnVertex)
			{
				//... Define the color
				iMeshSahding->SetVertexColor(posnVertex, color[0], color[1], color[2], 255 );	// 255 - completely opaque
				iVertexIterator->GetNext(&posnVertex);				// Move to the next
			}
			iMetr->Release();	iVertexIterator->Release();
I have attached the project.

It works if I load the installed knot.mdg via the File menu of the sample and click the Shading check box:
KnotPerVertex.png
KnotPerVertex.png (164.22 KiB) Viewed 671 times
I intend to add more about v7.2 version of this asap.

Re: Changing colour of mesh face and mesh wireframe

Posted: Fri Jan 10, 2025 1:27 am
by Prashant Kande
v6.2 C++ Morph (the last version which has the CMorphDlg::OnShading() code) works in 64 bit with DGK 7.2 installed.
Replace int nDim = 0; in the code with EDim_DG nDim = e0D; to get it compiled.

So, old KC interface works for per vertex colors with the latest DGK.

IMesh_DG.EnableShading() and IMesh_DG.SetVertexColor() should work as well. Checking ....

Re: Changing colour of mesh face and mesh wireframe

Posted: Sun Jan 12, 2025 5:27 am
by Prashant Kande
It works. So, this is sample's problem. This check box and the handler was lost in v6.0 release. I have attached a fixed version of C++ Morph. It will be in the next update hopefully with other languages also.

Re: Changing colour of mesh face and mesh wireframe

Posted: Sun Jan 12, 2025 5:30 am
by Prashant Kande
BTW the colors look somewhat dull because of lighting. They would be fully bright if lighting was disabled.