Changing colour of mesh face and mesh wireframe

Everything DG Kernel: Technical discussions and issues
Post Reply
RJD
Posts: 4
Joined: Thu Nov 28, 2024 4:57 am

Changing colour of mesh face and mesh wireframe

Post 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!
Prashant Kande
Posts: 71
Joined: Tue Jun 18, 2024 6:12 am

Re: Changing colour of mesh face and mesh wireframe

Post 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
Measure
Posts: 2
Joined: Wed Oct 23, 2024 1:54 pm

Re: Changing colour of mesh face and mesh wireframe

Post 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.
Prashant Kande
Posts: 71
Joined: Tue Jun 18, 2024 6:12 am

Re: Changing colour of mesh face and mesh wireframe

Post 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 785 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.
Measure
Posts: 2
Joined: Wed Oct 23, 2024 1:54 pm

Re: Changing colour of mesh face and mesh wireframe

Post 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!
Prashant Kande
Posts: 71
Joined: Tue Jun 18, 2024 6:12 am

Re: Changing colour of mesh face and mesh wireframe

Post 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 667 times
I intend to add more about v7.2 version of this asap.
Attachments
Morph_KC5_2.zip
(43.99 KiB) Downloaded 26 times
Prashant Kande
Posts: 71
Joined: Tue Jun 18, 2024 6:12 am

Re: Changing colour of mesh face and mesh wireframe

Post 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 ....
Prashant Kande
Posts: 71
Joined: Tue Jun 18, 2024 6:12 am

Re: Changing colour of mesh face and mesh wireframe

Post 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.
Attachments
Morph.zip
(49.14 KiB) Downloaded 20 times
Prashant Kande
Posts: 71
Joined: Tue Jun 18, 2024 6:12 am

Re: Changing colour of mesh face and mesh wireframe

Post by Prashant Kande »

BTW the colors look somewhat dull because of lighting. They would be fully bright if lighting was disabled.
Post Reply