Rdk content creation/instancing issues

I have some issues with the RenderContent create/copy/instance APIs in v7, which are working differently for me here than in v6. In a nutshell, my types are able to reference other types (of mine, or others), and they should be able to reference a given instance multiple times, at different slots in a given type, displaying to the user as a link to the referenced instance. This is working for me in v6, but not in more recent builds of v7 (not sure exactly when it changed).

Below are some detailed sequences (done on the most recent v6 SR and the most recent v7 RC) to demonstrate what I am referring to, based on use of this test code:

TestLinkTextures.cs (6.6 KB)

v6

1. create a Test Link textures material
2. click the first "Choose texture" link
3. choose a new 2D Checker Texture

  a. the new texture does not show up in the Textures list
  b. it is shown below the material in tree view
  c. the material xml shows one "rcm-2d-checker-texture"

4. click the second "Choose texture" link
5. try to create an instance of the checker texture

  a. you cannot, because it does not appear in the list

6. right-click > Copy the texture in the material tree
7. right-click > Paste as Instance in the textures panel

  a. the texture is added, with "(Shared)" appended
  b. the texture now has a non-empty Group ID
  
8. repeat step 5, which is now possible

  a. the texture shows up under the material in the tree
  b. both instances of the texture have unique Instance IDs
  c. the material xml shows a second "rcm-2d-checker-texture"

9. save & re-open the file, everything looks ok

v7 - approach 1

1. create a Test Link Textures material
2. click the first "Choose texture" link
3. choose a new 2D Checker Texture

  a. a new texture appears in the Textures list
  b. it is also shown below the material in tree view
  c. the material xml shows one "rcm-2d-checker-texture"

4. click the second "Choose texture" link
5. try to create an instance of the checker texture

  a. you can do so, but MakeGroupInstance will fail
  b. MakeCopy will be used instead, and will succeed
  c. "(Instanced)" is appended in the Textures list
  d. the texture still has an empty Group ID
  e. the texture now shows up twice in the material tree
  f. both copies show the same Instance ID
  g. the material xml has added a "texture-proxy"

6. save & re-open, one of the textures is a "Texture Proxy"

v7 - approach 2

1. create a new 2D Checker texture
2. create a new Test Link Textures material
3. click the first "Choose texture" link
4. create an instance of the texture

  a. MakeGroupInstance will fail
  b. MakeCopy will be used instead, and will succeed
  c. "(Instanced)" is appended in the Textures list
  d. the texture still has an empty Group ID
  e. it is shown below the material in tree view
  f. the material xml shows one "texture-proxy"

5. repeat steps 3 & 4 with the second "Choose texture" link

  a. a sequence of events similar to above will occur
  b. all "instances" of the texture show the same Instance ID
  c. the material xml shows a second "texture-proxy"

6. save & re-open

  a. two "Texture Proxy" textures show up in the Textures list
  b. both of these are linked in the material tree

I know it is possible to make things work, since the built-in texture chooser (e.g. used in the cycles glass material) is able to correctly do what I am trying to accomplish. However, that uses a different API (the Fields.AddTextured one), so it is probably not purely using c# rhcommon, internally.

I had a similar issue once before, where I was not calling RenderContent.Replace in a certain spot (after calling RenderContent.Edit), so hopefully it is just something like that, but the very different behavior of the two versions, and the fact that the example works as I expect in v6, makes me uncertain about what is really happening.

Hi @jdhill,

Thanks for the detailed report. I will look into this as soon as possible.

Regards,

John

Thanks!

Hi @jdhill,

You have uncovered a bug in the C++ function CRhRdkContent::MakeGroupInstance() which is called by the C# code. This bug was introduced when we added to ability to display child textures in the Texture Palette. These ‘Texture Proxies’ appearing in the UI is a side-effect of this bug.

https://mcneel.myjetbrains.com/youtrack/issue/RH-63533

I have fixed the bug and the fix will be available in the next service release. Sorry for the inconvenience. If you need the fix fast, I could send you a special link to download it immediately.

Regards,

John

1 Like

May I assume the fix applies to Rhino 7 itself, and not rhcommon? Asking because I build against v6, so in the former case I would not need any pre-release link and it will just start working correctly for my users once they update, while in the latter, I’d have to change things around and start offering version-specific plugin builds.

Hi @jdhill,

Yes, the fix is in the Rhino (RDK) core C++ implementation and should start working when you get the next release.

John

1 Like

Perfect – thanks!

Hi @jdhill,

Were you able to confirm that this now works properly?

Thanks,

John

Indeed it appears to be working correctly now, thanks!

@jdhill,

Thanks for confirming.

John