How to keep Texture mapping result

Hi @angelwang,

I’ve logged a bug about this issue: https://mcneel.myjetbrains.com/youtrack/issue/RH-48159

In your sample you can work around the issue by calling

crmInOut.SetUseObjectsMappingChannels(true);

instead of

crmInOut.SetUseObjectsMappingChannels(false);

because you are not modifying the render mesh at all - your custom render mesh will look the same as the object with its texture mapping. Can you use the same work around in your plug-in?

Hi @Jussi_Aaltonen

Thank you very much~
I try to set

crmInOut.SetUseObjectsMappingChannels(true);

It works fine for texture mapping in Raytraced mode and rendered mode.

But I have another problem, the view option on the document properties on Rhino5, my customer will copy render display mode and rename it to be “UV Rendered” and setting as following

They use UV Rendered display mode to check uv mapping quality, it likes as following picture.

But same setting on Rhino6, I run command “DES_TextureTest” in my probject “DESNewSample”, when I set ScaleX=5 and ScaleY=5 and select picture in Rendered mode and then change to UV Rendered display mode the scale seems to be become 1. It likes as following

Could you check what’s happen?

Thanks~

Hi @angelwang, you have just found yet another bug, thanks for reporting it!

Logged as https://mcneel.myjetbrains.com/youtrack/issue/RH-48199 and under investigation.

Thanks,
Jussi

Hi @angelwang,

The problem with your UV Rendered mode will be fixed in next service release of Rhino 6 in about 2 weeks.

Hi @Jussi_Aaltonen

When I call SampleRMP.rar (1.4 KB)

RhRdkCustomRenderMeshManager().Add(new CSampleRMP());

on load plugin.

I open Sole.zip (332.2 KB) which is iges file, I can’t see the 3d file on Rendered mode, but It can display on Shaded mode.

If I don’t add

RhRdkCustomRenderMeshManager().Add(new CSampleRMP());

on load plugin.

I open Sole.igs file, I can see it on rendered mode.

Could you check the problem?
Thanks~

my Rhino6 is 6.9.18271.20591
SDK is 6.9.18271.20591

Hi @angelwang,

If you set a break point into CSampleRMP::BuildCustomMeshes where the GetMeshes is called you will find out that no meshes are returned. This is because the iges file doesn’t have render meshes at all - only the brep geometry. In this case you need to const cast the Rhino object and call CreateMeshes. This is one of the exceptions where const casting is needed.

See my example of how to do this: SampleRMP_with_CreateMeshes.zip (1.6 KB)

Hi @Jussi_Aaltonen

Thank you for your reply.

Now, it work ok :grinning:

1 Like

Hi @Jussi_Aaltonen

I reference to SampleRMP to deform render mesh, that run on Rhino6 SR9, it works fine.
But run on Rhino6 SR12 or SR13, it doesn’t stable.

On Rhino6 SR9, I change Radius value and click compute, I can see the deform result immediately.

On Rhino6 SR12 or SR13, I change Radius value and click compute, I can’t see the deform result immediately, if I change display mode to Shaded, it show the deform result.

About the problem, do you have any ideal?

Same program run different Rhino6 version has different result.

Hi @angelwang

Sorry for the delayed answer and thanks for reporting and testing!

So the bug will be fixed in SR15. Here’s a workaround for you until SR15 is released:
In your command after updating the custom render mesh call
context.Document()->Redraw(CRhinoView::mark_display_hint);

Hi @Jussi_Aaltonen
Thank you for your reply.
I try the “context.Document()->Redraw(CRhinoView::mark_display_hint)” on Rhino6 SR13, it is OK.

But I have question
when I update the custom render mesh,
I call “context.Document()->Redraw(CRhinoView::mark_display_hint)”,
is it more stable than
call “context.Document()->Redraw(CRhinoView::regenerate_display_hint)” for Rhino6 any version?

Hi @angelwang,

The CRhinoView::mark_display_hint should be equally stable as CRhinoView::regenerate_display_hint. The reason you need to use mark_display_hint in this case is to get around a bug in the display which is fixed in SR15. Once SR15 is release you can go back to doing a normal Redraw.

The mark_display_hint forces the display draw lists to re-populate themselves which means it also refreshes the cache, so it will find the newly updated geometry.

-David

Hi @Jussi_Aaltonen

Recently we found that Trim had problem
If running on load plugin

  RhRdkCustomRenderMeshManager().Add(new CDES_RenderMeshRMP())    

The display for trim result is NG
Trim_NG

No running on load plugin

  RhRdkCustomRenderMeshManager().Add(new CDES_RenderMeshRMP())    

The display for trim result is OK
Trim_OK

Could you help me to check what happen?

my Rhino6 SDK is 6.31.20315.17001 and
Rhino6 is _6.31.20315.17001

DESNewSample_01.zip (51.6 KB)
Trim.3dm (237.1 KB)

Thanks~

@angelwang What does your RMP do when object is modified by the Trim command? Does it provide an updated mesh created from the trimmed object?

@Jussi_Aaltonen
We need to use RMP on our plugin, when we load our plugin we add

  RhRdkCustomRenderMeshManager().Add(new CDES_RenderMeshRMP())    

, before you recommed.

But, we run Rhino command “Trim” to trim object which is Trim.3dm, it has display problem.

Trim.3dm
Trim_NG

If the object is simple, run Rhino command “Trim” to trim object, the display is no problem.
Simple object
simpleTrim

If we don’t load our plugin(DESSample), when it run Rhino command “Trim” to trim object which is Trim.3dm, the display is no problem.

Trim_OK

I don’t know what happen in RMP.

Trim command does not trigger the OnReplaceObject event. So when Trim ends your event watcher does not call ::RhRdkCustomRenderMeshManager().OnRhinoObjectChanged. Therefore CDES_RenderMeshRMP::BuildCustomMeshes will not be called for that trimmed object. So it will show the same custom render mesh as before the Trim command.

That blue box is an extrusion object. CDES_RenderMeshRMP::WillBuildCustomMesh returns false unless object geometry is an ON_Brep. So that blue box never gets a custom render mesh and therefore it looks normal after Trim command.

So, you need to trigger rebuild for custom render meshes when Trim command ends by calling ::RhRdkCustomRenderMeshManager().OnRhinoObjectChanged in the CSampleRhinoEventWatcher::OnAddObject.

@Jussi_Aaltonen

Thank you very much.

we add

  ::RhRdkCustomRenderMeshManager().OnRhinoObjectChanged in the CSampleRhinoEventWatcher::OnAddObject    

and run Rhino command “Trim” on Trim.3dm, the display is OK.

Great!

Hi @Jussi_Aaltonen

When we load DESSample plugin we add

  RhRdkCustomRenderMeshManager().Add(new CDES_RenderMeshRMP())    

and then open RenderMode_RotateSlow.3dm.
I rotate the obejct on the viewport on render mode, it is slowly or the object changes to wireframe.

If I don’t load DESSample plugin, and then open RenderMode_RotateSlow.3dm
I rotate the obejct on the viewport on render mode, it is fastly.

Could you help me to solve the problem?

3dm
RenderMode_RotateSlow.zip (6.6 MB)

For Rhino6 plugin
DESNewSample.zip (383.4 KB)

@angelwang The slowness comes from drawing so many custom render meshes. Your model has 151 polysurface objects and CDES_RenderMeshRMP::BuildCustomMeshes creates custom render meshes for each of them. Do they all need a custom render mesh?

@Jussi_Aaltonen
Only some objects deform by our plugin, that needs a custom render mesh.
So I try to add if (CUtility_ImagineElf::IsImagineElfObj(pObject)) on the following coding, it is no use, I still hard to rotate the object which has many ploysurface and it is not our plugin object.

bool CDES_RenderMeshRMP::WillBuildCustomMesh(const ON_Viewport& vp, const CRhinoObject* pObject, const CRhinoDoc& doc,
                                             const UUID& uuidRequestingPlugIn, const CDisplayPipelineAttributes*) const
{
	if (nullptr == pObject)
		return false;
    
    if (CUtility_ImagineElf::IsImagineElfObj(pObject))  // only our plugin object run custom render mesh 
    {
      const ON_Brep* Brep = ON_Brep::Cast(pObject->Geometry());
      if (Brep) return true;
    }

	return false;
}