Site Tools

Detecting Custom Texture Mapping

C++, .NET

Version: Rhino 4


How can I tell when the user has applied custom texture mapping to an object using the Texture Mapping page in the Object Properties dialog?


Custom texture mappings are specific to each render plug-in. All texture mapping information is stored in an ON_ObjectRenderingAttributes object that is stored in the Rhino object's attributes.

You can test for the existance of a render plug-in specific mapping reference as follows:


CRhinoGetObject go;
go.SetCommandPrompt( L"Select object" );
go.GetObjects( 1, 1 );
if( go.CommandResult() != success )
  return go.CommandResult();
const CRhinoObject* object = go.Object(0).Object();
if( 0 == object )
  return failure;
const CRhinoObjectAttributes attributes = object->Attributes();
// See if the default renderer has a mapping reference
ON_UUID render_uuid = RhinoApp().GetDefaultRenderApp();
const ON_MappingRef* mapping_ref = attributes.m_rendering_attributes.MappingRef( render_uuid );
if( mapping_ref )
  RhinoApp().Print( L"Object uses custom texture mapping.\n" );
  RhinoApp().Print( L"Object uses default texture mapping.\n" );


MRhinoGetObject go = new MRhinoGetObject();
go.SetCommandPrompt( "Select object" );
go.GetObjects( 1, 1 );
if( go.CommandResult() != IRhinoCommand.result.success )
  return go.CommandResult();
IRhinoObject rhObj = go.Object(0).Object();
if( rhObj == null )
  return IRhinoCommand.result.failure;
IRhinoObjectAttributes attributes = rhObj.Attributes();
// See if the default renderer has a mapping reference
System.Guid render_uuid = RhUtil.RhinoApp().GetDefaultRenderApp();
IOnMappingRef mapping_ref = attributes.m_rendering_attributes.MappingRef(ref render_uuid);
if( mapping_ref != null )
  RhUtil.RhinoApp().Print( "Object uses custom texture mapping.\n" );
  RhUtil.RhinoApp().Print( "Object uses default texture mapping.\n" );


Dim go As New MRhinoGetObject()
go.SetCommandPrompt("Select object")
go.GetObjects(1, 1)
If (go.CommandResult() <> IRhinoCommand.result.success) Then
  Return go.CommandResult()
End If
Dim rhObj As IRhinoObject = go.Object(0).Object()
If (rhObj Is Nothing) Then Return IRhinoCommand.result.failure
Dim attributes As IRhinoObjectAttributes = rhObj.Attributes()
' See if the default renderer has a mapping reference
Dim render_uuid As System.Guid = RhUtil.RhinoApp().GetDefaultRenderApp()
Dim mapping_ref As IOnMappingRef = attributes.m_rendering_attributes.MappingRef(render_uuid)
If (mapping_ref IsNot Nothing) Then
  RhUtil.RhinoApp().Print("Object uses custom texture mapping." + vbCrLf)
  RhUtil.RhinoApp().Print("Object uses default texture mapping." + vbCrLf)
End If
developer/sdksamples/mappingref.txt ยท Last modified: 2020/08/14 (external edit)