(C++) How to apply a texture to a Plane from an in-memory array

The title pretty much sais it all. I am trying to create a textured flat plane, however since I am computing the results I am trying to directly apply the texture from the array without the need for a bitmap.

Unfortunately I am not finding the examples I need. From what I understand the way to do it is to create a ON_Material, assign the texture via an ON_Texture object, and then add the material to a ON_Brep object.

Is it possible to create a texture without requiring a bitmap?
And how would I then assign that texture to the brep?
(I’m sure there’s an example that I missed somewhere, but most examples I could find are written in C#)

~robin

@andy, can you help with this?

hello @dale @andy

We found a temporary workaround by creating a mesh and assigning the colors to the vertices, but that solution clearly isn’t ideal.
Could you point me to some examples / documentation explaining how to assign a texture? And do you have some idea as to how we could assign that from an array?

~robin

I have added example code to the SampleRdkAddRdkMaterials sample. The code is in CSampleRdkAddRdkMaterials::RunCommand() as an optional block surrounded by {{{ }}}. The example uses a ‘Dib Texture’ which allows you to set up a texture from any pixels you want without using a bitmap file.

John

1 Like

As a side note, it’s possible to apply the Dib Texture directly into ON_Texture without going through RDK, see RhinoSdkDib.h

  /*
  Description:
    Inserts dib into Rhino's texure manager and returns an ON_FileReference
    for use in e.g. ON_Texture::m_image_file_reference. This way it's possible
    to use a dib with an ON_Texture without having to read the dib from file.
  Parameters:
    dib - [in] The dib which will be referenced by the ON_FileReference.
    crc - [in] The crc of the dib. This should be a unique number which
               changes if the contents of the dib changes.
               NOTE: if a different dib is provided using the same crc as
               a previous dib, then the previous dib will be overwritten
               in the texture manager and both previously returned
               ON_FileReferences will reference the newly provided dib.
  Returns:
    Returns an ON_FileReference which, when used together with e.g.
    ON_Texture::m_image_file_reference, is used by Rhino's display to find 
    the texture from the texture manager.
  */
RHINO_SDK_FUNCTION
ON_FileReference RhinoGetDibAsTextureFileReference(const CRhinoDib& dib, ON__UINT32 crc);

Pablo

1 Like