Hi,
I need to draw textures from memory in a display conduit in Rhinocommon, like in this thread. I’d like to ask whether a particular set of methods from C++ SDK can be exposed in Rhinocommon to make this happen.
Here there’s a simple sample drawing a texture from memory on a sphere inside a conduit:
cmdSampleShadingDibTexture.cpp (4.8 KB)
I would like to have the Rhinocommon equivalent of it.
The following elements are crucial:
- The multi-threaded pixel shader that evaluates the texture, which in C++ is carried by
CRhinoDib
and
CRhinoDib::ProcessPixels(bool(*f)(Pixel&, void* pvData), void* pvData = nullptr);
It’s important that some data may be passed through void*
member.
An example:
const int width = 1000, height = 1000, depth = 32;
CRhinoDib dib(width, height, depth);
auto func = [](CRhinoDib::Pixel& pixel, void*)
{
pixel.Set(rand() & 255, rand() & 255, rand() & 255, 255);
return true;
};
dib.ProcessPixels(func);
- The method that transfers CRhinoDib into ON_Texture (its field
ON_Reference m_image_file_reference
) through
ON_FileReference RhinoGetDibAsTextureFileReference(const CRhinoDib& dib, ON__UINT32 crc);
- The method to pass
ON_Texture
intoON_Material
ON_Material::AddTexture(const ON_Texture& tx);
I believe point 3 is already in C# but couldn’t find points 1/2. From what @stevebaer said in the linked thread I know that maybe this is not yet exposed or developed at this level, in which case I add my vote for it to be there at some point.
Question for @nathanletwory: I was close to translate my sample to C# using your TestNathanMemoryTexture, but I was stuck when having to dynamically update the texture in a conduit. It seems like once the texture is created it can’t be further changed unless the Guid is modified, but this is tricky when it needs to be done very often. Maybe there’s a way to fix this and make your code run inside a conduit?
Other than that, it looks very promising, for example I can see that TextureEvaluator.GetColor(Point3d uvw, Vector3d duvwdx, Vector3d duvwdy)
is similar to the shader function I show in point 1 and is multi-threaded. Is it possible to pass in some custom user data as well?
Thank you,
Pablo