TextureMapping Performance in Rhino 8 Problem

Hello everyone,
I have developed a plugin in Rhino7 using RhinoCommon in C# and currently working on creating a plugin version for Rhino8. One of the functionalities in this plugin involves assigning and modifying texture mapping. While the functionality works smoothly in Rhino7, I’ve encountered two specific efficiency issues in the Rhino8 version. I need assistance in resolving these problems.

  1. Texture Assignment Code Efficiency: In Rhino7, I use the following code to assign texture mapping:

Csharp code

resultInt = obj.SetTextureMapping(channel, tm);

Here, tm is a mesh with textureCoordinate made by us. The process is so slow in Rhino8, sometimes exceeding 10 seconds under certain mesh conditions. In Rhino 7 it is never happened.

If I SetTextureMapping Once, It will be fast when I do that again.

  1. Redraw Time After Texture Modification: I also modify the texture mapping within the plugin. After modification, I use the same code obj.SetTextureMapping(channel, tm); to assign it back. The assignment is fast, but when I invoke view.Redraw(), the redraw time becomes excessively long.

Additionally, I’ve noticed that our plugin experiences slower performance under .NET 7.0 or .NET 4.8, but it performs normally in Rhino7.

Rhino8 Version:8.2

Your assistance in resolving these performance issues would be greatly appreciated. Thank you!

I apologize for repeating this issue, but I’m genuinely in need of assistance.

@dale Please assist me in solving this problem, Thank you!!!

@andy - can you have a look at this?

Hello @陳志鵬

Sorry, it took this long to get to this. I’m looking into it now.

I’m running the code I received by email on a 500k poly mesh.

These timings are made with Debug builds:

Rhino 7:
New Object Set the Same TextureMapping Back. Time:1 ms
New Object Set rebuild TextureMapping Time:10872 ms
New Object Set rebuild TextureMapping AGAIN. Time:6 ms

Rhino 8:
New Object Set the Same TextureMapping Back. Time:10515 ms
New Object Set rebuild TextureMapping Time:2 ms
New Object Set rebuild TextureMapping AGAIN. Time:2 ms

I will do some profiling next to see where the time is spent. Sometimes SetTextureMapping modifies the object attributes and causes ModifyObjectAttributes event.

The time is spent computing texture coordinates for the object mesh (for mesh objects there aren’t separate render meshes as there are for nurbs objects). This involves looking at the mapping mesh and the object mesh and figuring out how they would best map to one another. This computation sometimes happens as the object is drawn, sometimes it happens right away when new mapping is set and sometimes it may for example happen when an object is exported to file. This may explain why sometimes it is the SetTextureMapping that takes long and sometimes the Redraw call.

I have logged a bug about computing texture coordinates when object attributes are changed: https://mcneel.myjetbrains.com/youtrack/issue/RH-79898

Sometimes valid texture coordinates get copied when an object is duplicated. So in those cases the texture coordinate computation will usually be skipped completely.

We have gradually changed how texture mapping is done since Rhino 6. So it is expected that there is difference between Rhino 7 and Rhino 8 as well. However, if there is a model that shows significantly longer times for Rhino 8 then I would like to take a look. Please upload such files to Rhino - Upload to Support

Hey @curtisw, who would be the right person to assist with this?

Hi Jussi,
I have uploaded our file, thank you!

Thank you, I have received the model. I will inspect it next week :slight_smile:

1 Like

Hi Jussi,
Could you please provide an update on the problem?
If there are any additional documents required, please let me know. Thank you!

I could not see a big difference in times between Rhino 7 and Rhino 8 with your model. But I see different behavior in which calls take the time. Some plug-ins modify texture mappings and that could be the reason why your Rhino 8 behaves different to mine. You can run _SystemInfo command and send the report so I can check.

We are actively working on the texture mapping area at the moment.

Thanks for your replying!
I have uploaded our system information files to [ Rhino - Upload to Support
If there is any way to resolve or circumvent this problem, please let us know.
Thank you!

Hi @陳志鵬

I started looking into why the texture mapping needs to be applied at all in Rhino 8 when executing your test code. Applying the texture mapping once should be enough and it usually is already applied by Rhino display.
I found two bugs in the RhinoObject.SetTextureMapping method:

  • RH-81859 RhinoCommon: RhinoObject.SetTextureMapping misses existing channels
  • RH-81860 RhinoCommon: RhinoObject.SetTextureMapping ignores object transform

I’m testing a fix for those bugs.

When you get the texture mapping for an object you should also get the object transform. That transform describes how the object has been moved since the mapping was applied. And if you want to apply the same mapping to a copy of that object you also then need to pass in the same object transform. Here’s the code:

...
var tm = obj.GetTextureMapping(1, out Transform objectTransform);
...
oNew.SetTextureMapping(1, tm, objectTransform);
...

The Texture mapping UI shows this transform here:


For some legacy reasons the Size XYZ shows the scaling doubled.

Thank you!
We will do more testing after RH-81859 & RH-81860 be fixed in version 8.8!

hi @Jussi_Aaltonen
this bug in map texture in rhino 8
please fix it: