Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:mappingref [2015/09/14] (current)
Line 1: Line 1:
 +====== Detecting Custom Texture Mapping ======
 +====== C++, .NET ======
 +> **Version:​** //Rhino 4//
 +
 +=====Question=====
 +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?
 +
 +=====Answer=====
 +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:
 +
 +===== C++ =====
 +<code c++>
 +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"​ );
 +else
 +  RhinoApp().Print( L"​Object uses default texture mapping.\n"​ );
 +
 +</​code>​
 +===== C# =====
 +<code c#>
 +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"​ );
 +else
 +  RhUtil.RhinoApp().Print( "​Object uses default texture mapping.\n"​ );
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +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)
 +Else
 +  RhUtil.RhinoApp().Print("​Object uses default texture mapping."​ + vbCrLf)
 +End If
 +
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus dotnet}}
  
developer/sdksamples/mappingref.txt ยท Last modified: 2015/09/14 (external edit)