Site Tools


Differences

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

Link to this comparison view

Both sides previous revision Previous revision
developer:displayconduit [2015/11/10]
sandy
developer:displayconduit [2016/01/22] (current)
sandy
Line 3: Line 3:
 > **Notice:** //The Rhino.NET SDK is deprecated in Rhino 5.  This example is adapted for the new RhinoCommon SDK is [[developer:​rhinocommonsamples:​displayconduit|here]]//​. > **Notice:** //The Rhino.NET SDK is deprecated in Rhino 5.  This example is adapted for the new RhinoCommon SDK is [[developer:​rhinocommonsamples:​displayconduit|here]]//​.
  
-Rhino 4 lets you define your own display conduits, which provide access to many levels of the display pipeline. In contrast, in Rhino 3 it was only possible to implement a DrawCallBack which allowed ​you to draw geometry in the back, middle, or foreground. DrawCallBacks did not expose any methods to adjust the clipping of the viewports, the lighting setup, or a lot of other properties ​that would be usefulHowever, ​they were straightforward to implement. DisplayConduits are a bit trickier, hence this Wiki page.+Rhino 4 lets you define your own display conduits, which provide access to many levels of the display pipeline. In contrast, in Rhino 3 it was only possible to implement a DrawCallBack which let you draw geometry in the back, middle, or foreground. DrawCallBacks did not expose any methods to adjust the clipping of the viewports, the lighting setup, or a lot of other useful ​properties. ​But they were straightforward to implement. DisplayConduits are a bit trickier, hence this Wiki page.
  
 The DisplayPipeline in Rhino 4 is a big and complicated class and we do not recommend you derive your own pipeline. Instead, we've exposed something called a //conduit// for easy access. The pipeline itself is structured like this (except in reality there are many more channels): The DisplayPipeline in Rhino 4 is a big and complicated class and we do not recommend you derive your own pipeline. Instead, we've exposed something called a //conduit// for easy access. The pipeline itself is structured like this (except in reality there are many more channels):
Line 9: Line 9:
 {{:​legacy:​en:​PipeLineImageA.jpg}} {{:​legacy:​en:​PipeLineImageA.jpg}}
  
-At one end is the Rhino model, a collection of 3D geometry and data. At the other end is the image we want to display on the screen, a collection of 2D pixels. To get from model to image, the pipeline has to process a lot of information. These steps have been put into things we call Channels. Whenever you implement a new conduit, you have to implement at least one of these channels, like so:+At one end is the Rhino model, a collection of 3-D geometry and data. At the other end is the image we want to display on the screen, a collection of 2-D pixels. To get from model to image, the pipeline has to process a lot of information. These steps have been put into things we call Channels. Whenever you implement a new conduit, you have to implement at least one of these channels, like so:
  
 {{:​legacy:​en:​PipeLineImageB.jpg}} {{:​legacy:​en:​PipeLineImageB.jpg}}
Line 50: Line 50:
    End Class    End Class
 </​code>​ </​code>​
-As you can see we have to supply the channels we're going to use in the constructor. This means we cannot change which channels we want to tinker with at runtime. By default, conduits are not enabled. You have to specifically do that. But it can be done easily by setting the second constructor argument to True. Once our conduit is constructed and enabled, the ExecConduit() function ​will be called whenever the Rhino pipeline has reached a channel we're interested in. In our case, this function will always be called once with the current_channel flag set to SC_CALCBOUNDINGBOX and then once with the flag set to SC_POSTDRAWOBJECTS. Thus, inside the ExecConduit() function we have to evaluate which channel we're in and then take appropriate action:+As you can see we have to supply the channels we're going to use in the constructor. This means we cannot change which channels we want to tinker with at runtime. By default, conduits are not enabled. You have to specifically do that. But it can be done easily by setting the second constructor argument to True. Once our conduit is constructed and enabled, the ExecConduit() function ​is called whenever the Rhino pipeline has reached a channel we're interested in. In our case, this function will always be called once with the current_channel flag set to SC_CALCBOUNDINGBOX and then once with the flag set to SC_POSTDRAWOBJECTS. Thus, inside the ExecConduit() function we have to evaluate which channel we're in and then take appropriate action:
 <code vb> <code vb>
    ​Public Overrides Function ExecConduit(ByRef dp As RMA.Rhino.MRhinoDisplayPipeline,​ _    ​Public Overrides Function ExecConduit(ByRef dp As RMA.Rhino.MRhinoDisplayPipeline,​ _
Line 66: Line 66:
    End Function    End Function
 </​code>​ </​code>​
-Note that you have to return True to keep the pipeline alive. Only return False in an emergency. The code above simply draws a single point at the world origin. Since a point is 3D geometry, it is subject to z-depth clipping. This means that if the point resides outside the z-buffer region, it will not be visible. (It will get //​clipped//​.) By default, the clipping planes are set up to encompass the boundingbox of the entire Rhino model. If you're drawing stuff which is potentially outside this box, you should override SC_CALCBOUNDINGBOX to make sure your objects are not clipped.+Note that you have to return True to keep the pipeline alive. Only return False in an emergency. The code above simply draws a single point at the world origin. Since a point is 3-D geometry, it is subject to z-depth clipping. This means that if the point resides outside the z-buffer region, it will not be visible. (It will get //​clipped//​.) By default, the clipping planes are set up to encompass the boundingbox of the entire Rhino model. If you're drawing stuff which is potentially outside this box, you should override SC_CALCBOUNDINGBOX to make sure your objects are not clipped.
  
 Let's look at a more complex drawing routine: Let's look at a more complex drawing routine:
developer/displayconduit.txt ยท Last modified: 2016/01/22 by sandy