Importing a 3dm results in duplicate RDK materials

Hi

When using the File Import menu command, Rhino imports any RDK materials as new materials in the scene. So importing the same file 3 times results in 3 copies of the materials. This may be the intended functionality. However is there a way to remove the duplicate materials pls and re-assign the materials for all the imported geometry accordingly? Or is there a way I can modify the Octane plugin to handle this situation? I see that when importing, the Rhino.Render.RenderContent.ContentAdded is not firing, so I cannot see how having the plugin cull the duplicates could be done.

Thanks

Paul

Good luck with that Paul. Definitely something we need.

@andy, can you assist?

Is this in Rhino 5?

Yes, Rhino5 Andy.

Any news on this pls? @andy @dale

Paul

It works fine here. Are the RDK materials you are talking about Octane materials?

  • Andy

Yes Andy - they are Octane Materials.

Paul

Any news on this pls?

@paulphysicalc make sure you @ mention me, because otherwise I don’t see these. Sorry for the delay.

The reason is that when your materials come into the file, they have a different RenderCRC from the ones that are already there. So Rhino considers them “not the same” and adds new ones. You’ll have to check the value that’s being returned in RenderCRC.

Thanks Andy - what do you mean by “when you materials come into the file”? How does an RDK plugin know this is happening? Since the Rhino.Render.RenderContent.ContentAdded event is not firing. How can an RDK plugin differentiate between the user creating a duplicate name material, and a duplicate material being imported from a file?

Thanks

Paul

Andy - I have done some more work on this and am really at a loss. I cannot see how a plugin can a) detect that a duplicate material has been created, and b) stop that duplicate from being created. Is there something missing from the Rhino RDK that allows this to happen? This is a big issue for users, since whenever they import large scenes into other scene, they end up with duplicate materials which take a lot of manual correction to fix up.

Paul

@paulphysicalc

When Rhino imports a file, it loads the RDK materials from its material list and compares them with the ones in the host file’s list. The way it compares them is to call CalculateRenderCRC on each. If it finds a match in the host list, it redirects the material assignments in the imported file to the host material. Otherwise, it adds the new material from the import file, and leaves the material assignment intact.

  • Andy

Thanks Andy - I cannot find CalculateRenderCRC anywhere in RhinoCommon or the RDK, or anywhere in the doco. As you sure that’s the right function?

Paul

@paulphysicalc

In V5 C++, it’s called “ComputeRenderCRC” (sorry!). In V6 C++ it will be RenderCRC.

In C# it looks like it’s “CalculateRenderHash” and “RenderHash” (for the accessor)

///


/// Override this method to calculate the render hash of the state that
/// affects how the content is rendered. Does not include children or
/// perform any caching. Render hash values are now automatically cached by
/// the content framework and you do not have to worry about caching. You
/// also do not have to worry about iterating into children. This method
/// is now only called internally by the framework, use the RenderHash
/// property to get the current hash value.
///

///
[CLSCompliant(false)]
protected virtual uint CalculateRenderHash(ulong rcrcFlags)
{
var const_pointer = ConstPointer();
return UnsafeNativeMethods.Rdk_RenderContent_CallCalculateRenderCRCBase(const_pointer, rcrcFlags);
}

/// <summary>
/// Render hash for the content hierarchy. It iterates children and includes
/// a caching mechanism which means the hash value can be retrieved quickly
/// if it hasn't changed. The cache is invalidated when Changed() is called.
/// 
/// You can override the <see cref="CalculateRenderHash"/> method to provide
/// a custom hash value.
/// </summary>
[CLSCompliant(false)]
public uint RenderHash
{
  get
  {
    var const_pointer = ConstPointer();
    return UnsafeNativeMethods.Rdk_RenderContent_RenderCRC(const_pointer, 0);
  }
}
  • Andy

Thanks for that info @andy. However I get a compilation error “no suitable method found to override” if I add:

protected override uint CalculateRenderHash(ulong rcrcFlags)
{
    return myHashValue;
}

to my RenderMaterial. I cannot find any reference to CalculateRenderHash in the Visual Studio Object Browser either.

Paul

@andy any news on this pls?

Paul

It appears that this is not implemented in Rhino 5. I’m sorry about this. It is fixed in Rhino 6.

The only option is to ensure that the data inside the buffer field is the same for both of the materials.

Thanks Andy. Good to know.

Paul