RhinoCommon: How to know if a Texture uses WCS mapping?

Hi,

I’m trying to figure out how to determine if a Rhino.DocObjects.Texture instance is using WCS mapping in RhinoCommon. However, there doesn’t seem to be anything in the Texture object interface to indicate which type of mapping the texture is using.

I noticed that the Texture.MappingChannelId property seems to be -13 for WCS mapping and -14 for WCS/Box mapping but I couldn’t find any documentation confirming if that is intended or reliable behaviour. Although, this post seems to confirm the existence of hard-coded ChannelId values for certain types of mapping.

I’ve also tried to use the Rhino.Render.RenderTexture.GetProjectionMode(), but I’m having issues matching Texture instances to their RenderTexture counter-part. I’ve tried to use RenderContent.FromId() but it doesn’t seem to work with “generated” textures like “Tile Textures” or “Noise Textures”, passing the ID of those Texture instances fails to return a RenderContent object. I’ve tried matching generated texture manually by comparing some other property than the Id, but somehow the names of those RenderTextures are all “??? 005”, and comparing the file name hidden in the Xml property didn’t give me any match with the Texture.FileName either.

At that point, my only option seems to rely on the undocumented behaviour of Texture.MappingChannelId but I’m reluctant to do so since I could be wrong here. Could someone explain to me what is the proper way to determine the type of mapping used by a Texture object?

Thanks!

Just replying to let you know I’ve seen the question. About to head off to bed, but I’ll reply in more useful detail tomorrow.

1 Like

If at all possible you should stick to the RenderTexture type as much as possible. It is part of the RenderContent API that is provided by the Renderer Development Kit RDK, and essentially the moderner sibling of Texture.

Texture will always be a bitmap-based texture, RenderTexture can be a Rhino procedural texture.

Anyway, from a RenderTexture you can use RenderTexture.GetMappingChannel to get the mapping channel it is set to be used in.

To get to a Texture from the RenderTexture you can use SimulatedTexture:

RenderTexture rtex = GetRtFromSomewhere();
SimulatedTexture simtex = rtex.SimulatedTexture(RenderTexture.TextureGeneration.Allow);
Texture tex = simtex.Texture();

To create a RenderTexture from a Texture you will first have to construct a SimulatedTexture from it, then from that you can create the RenderTexture.

Texture tex = GetTexFromSomewhere();
SimulatedTexture simtex = new SimulatedTexture(doc, tex);
RenderTexture rtex = RenderTexture.NewBitmapTexture(simtex, doc);

The values you otherwise see for the channels are correct I think, but to be sure you should, assuming you start with the RenderTexture get the SimulatedTexture for it, then ask for its ProjectionMode, which will give you a value from the SimulatedTexture.ProjectionModes enum, which will be much easier to understand. This part of the SDK is a bit wieldy to use, unfortunately. But I hope this will give you all the info you need to get your code working.