Hi
I recently migrated from Rhino5 to Rhino7. I have code that draws objects with display conduit, and uses back face culling in the conduit. This code was drawing with culled back faces in Rhino5, but it does not work in Rhino7. In Rhino7 it draws without culled back faces. What can be the problem. This is my code :
class CConduitTestBackFaceCulling : public CRhinoDisplayConduit
{
public:
CConduitTestBackFaceCulling(const ON_Brep* brep, const CRhinoObject* obj);
~CConduitTestBackFaceCulling() = default;
bool ExecConduit(
CRhinoDisplayPipeline& dp, // pipeline executing this conduit
UINT nChannel, // current channel within the pipeline
bool& bTerminate // channel termination flag
);
private:
const ON_Brep * m_Brep;
const CRhinoObject* mObject;
};
CConduitTestBackFaceCulling::CConduitTestBackFaceCulling(const ON_Brep* brep, const CRhinoObject* obj)
: CRhinoDisplayConduit(CSupportChannels::SC_CALCBOUNDINGBOX | CSupportChannels::SC_PREDRAWOBJECTS | CSupportChannels::SC_DRAWOBJECT),
m_Brep(brep), mObject(obj)
{
}
bool CConduitTestBackFaceCulling::ExecConduit(CRhinoDisplayPipeline& dp, UINT nChannel, bool& bTerminate)
{
UNREFERENCED_PARAMETER(bTerminate);
// Determine which channel we're currently executing in...
switch (nChannel)
{
case CSupportChannels::SC_CALCBOUNDINGBOX:
{
ON_BoundingBox bbox;
m_Brep->GetTightBoundingBox(bbox, false);
// Now adjust the channel attribute's bounding box with the accumulated one...
m_pChannelAttrs->m_BoundingBox.Union(bbox);
}
break;
case CSupportChannels::SC_DRAWOBJECT:
{
if (m_pChannelAttrs->m_pObject == mObject)
{
m_pChannelAttrs->m_bDrawObject = false;
}
}
break;
case CSupportChannels::SC_PREDRAWOBJECTS:
{
dp.PushDepthTesting(false);
m_pDisplayAttrs->m_bShowIsocurves = false;
m_pDisplayAttrs->m_bCullBackfaces = true;
ON_Brep* brep = const_cast<ON_Brep*>(m_Brep);
CDisplayPipelineMaterial material;
material.m_FrontMaterial.m_diffuse = ON_Color(0, 0, 255);
material.m_BackMaterial.m_diffuse = ON_Color(0, 0, 255);
dp.DrawShadedBrep(brep, &material, 0);
//dp.DrawShadedBrep(*brep, &material); //in Rhino5
m_pDisplayAttrs->m_bShowIsocurves = true;
m_pDisplayAttrs->m_bCullBackfaces = false;
dp.PopDepthTesting();
}
break;
}
return true;
}
CRhinoCommand::result CCommandTestBackFaceCullingCmd::RunCommand(const CRhinoCommandContext& context)
{
CRhinoGetObject go;
go.SetCommandPrompt(L"Select brep");
go.SetGeometryFilter(ON::brep_object);
go.GetObjects(1, 1);
if (go.CommandResult() != success)
return go.CommandResult();
CRhinoObjRef ref = go.Object(0);
const ON_Brep * brep = ref.Brep();
const CRhinoObject * obj = ref.Object();
CConduitTestBackFaceCulling conduit(brep, obj);
conduit.Enable();
RhinoApp().ActiveDoc()->Regen();
CRhinoGetPoint gp;
gp.SetCommandPrompt(L"Select point to stop conduit");
gp.GetPoint();
conduit.Disable();
context.m_doc.Regen();
return CRhinoCommand::success;
}
I uploaded minimal test example and model , to be tested both in Rhino5 and Rhino7.
Thank you for your help
TestBackFaceCullingCmd.txt (3.9 KB)
Model_BackfaceCull.3dm (25.9 KB)