Skip to content

Commit

Permalink
Added SubD drawing samples
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Sep 3, 2024
1 parent 994269a commit 4a3f456
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cpp/SampleCommands/SampleCommands.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
<ClCompile Include="cmdSampleComputeVertexColors.cpp" />
<ClCompile Include="cmdSampleCopyInPlace.cpp" />
<ClCompile Include="cmdSampleCPlaneWorld.cpp" />
<ClCompile Include="cmdSampleCsCachedTextureCoordinates.cpp" />
<ClCompile Include="cmdSampleDeleteFaces.cpp" />
<ClCompile Include="cmdSampleDrawSubD.cpp" />
<ClCompile Include="cmdSampleDrawSubDWires.cpp" />
<ClCompile Include="cmdSampleDrawZebraPreview.cpp" />
<ClCompile Include="cmdSampleDump3dmMaterialTextures.cpp" />
<ClCompile Include="cmdSampleDumpMeshCachedTextureCoordinates.cpp" />
Expand Down
5 changes: 4 additions & 1 deletion cpp/SampleCommands/SampleCommands.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,10 @@
<ClCompile Include="cmdSampleDumpMeshCachedTextureCoordinates.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cmdSampleCsCachedTextureCoordinates.cpp">
<ClCompile Include="cmdSampleDrawSubDWires.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="cmdSampleDrawSubD.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down
116 changes: 116 additions & 0 deletions cpp/SampleCommands/cmdSampleDrawSubD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "stdafx.h"

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN SampleDrawSubD command
//

class CSampleDrawSubDConduit : public CRhinoDisplayConduit
{
public:
CSampleDrawSubDConduit(const ON_SubD& subd, ON_Color color);
bool ExecConduit(CRhinoDisplayPipeline& dp, UINT nActiveChannel, bool& bTerminateChannel) override;

private:
const ON_SubD& m_subd;
ON_Color m_color;
};

CSampleDrawSubDConduit::CSampleDrawSubDConduit(const ON_SubD& subd, ON_Color color)
: CRhinoDisplayConduit(CSupportChannels::SC_CALCBOUNDINGBOX | CSupportChannels::SC_PREDRAWOBJECTS)
, m_subd(subd)
, m_color(color)
{
}

bool CSampleDrawSubDConduit::ExecConduit(CRhinoDisplayPipeline& dp, UINT nActiveChannel, bool& bTerminateChannel)
{
if (nActiveChannel == CSupportChannels::SC_CALCBOUNDINGBOX)
{
ON_BoundingBox bbox;
if (m_subd.GetTightBoundingBox(bbox, false))
m_pChannelAttrs->m_BoundingBox.Union(bbox);
}
else if (nActiveChannel == CSupportChannels::SC_PREDRAWOBJECTS)
{
CDisplayPipelineAttributes* pDA = const_cast<CDisplayPipelineAttributes*>(dp.DisplayAttrs());
if (nullptr != pDA)
{
CRhinoSubDDisplay subd_display = CRhinoSubDDisplay::Create(m_subd);
CRhinoSubDDisplayAttributes subd_display_attrs;
subd_display_attrs.m_bDrawControlNet = false;
subd_display_attrs.m_bDrawSurfaceNet = false;
subd_display_attrs.m_bDrawEdges = false;
subd_display_attrs.m_bDrawSurface = true;

ON_Material mat;
mat.m_diffuse = m_color;
CDisplayPipelineMaterial material(mat);

CDisplayPipelineMaterial* pOldMaterial = pDA->m_pMaterial;
pDA->m_pMaterial = &material;

dp.DrawSubD(subd_display, subd_display_attrs);

pDA->m_pMaterial = pOldMaterial;
}
}

return true;
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

#pragma region SampleDrawSubD command

class CCommandSampleDrawSubD : public CRhinoCommand
{
public:
CCommandSampleDrawSubD() = default;
UUID CommandUUID() override
{
// {EA9A6A06-2CAA-4971-9E89-6DD97177CE2F}
static const GUID SampleDrawSubDCommand_UUID =
{ 0xEA9A6A06, 0x2CAA, 0x4971, { 0x9E, 0x89, 0x6D, 0xD9, 0x71, 0x77, 0xCE, 0x2F } };
return SampleDrawSubDCommand_UUID;
}
const wchar_t* EnglishCommandName() override { return L"SampleDrawSubD"; }
CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
};

// The one and only CCommandSampleDrawSubD object
static class CCommandSampleDrawSubD theSampleDrawSubDCommand;

CRhinoCommand::result CCommandSampleDrawSubD::RunCommand(const CRhinoCommandContext& context)
{
ON_Sphere sphere(ON_3dPoint::Origin, 4.0);

ON_SubD subd_sphere;
ON_SubDComponentLocation subd_location = ON_SubDComponentLocation::Surface;
if (nullptr == ON_SubD::CreateSubDQuadSphere(sphere, subd_location, 2, &subd_sphere))
return CRhinoCommand::failure;

CSampleDrawSubDConduit conduit(subd_sphere, ON_Color::SaturatedMagenta);
conduit.Enable(context.m_rhino_doc_sn);
context.m_doc.Regen();

CRhinoGetString gs;
gs.SetCommandPrompt(L"Press <Enter> to continue");
gs.AcceptNothing();
gs.GetString();

conduit.Disable();
context.m_doc.Regen();

return CRhinoCommand::success;
}

#pragma endregion

//
// END SampleDrawSubD command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
120 changes: 120 additions & 0 deletions cpp/SampleCommands/cmdSampleDrawSubDWires.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include "stdafx.h"

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// BEGIN SampleDrawSubDWires command
//

class CSampleDrawSubDWiresConduit : public CRhinoDisplayConduit
{
public:
CSampleDrawSubDWiresConduit(const ON_SubD& subd, ON_Color wire_color);
bool ExecConduit(CRhinoDisplayPipeline& dp, UINT nActiveChannel, bool& bTerminateChannel) override;

private:
const ON_SubD& m_subd;
ON_Color m_wire_color;
};

CSampleDrawSubDWiresConduit::CSampleDrawSubDWiresConduit(const ON_SubD& subd, ON_Color wire_color)
: CRhinoDisplayConduit(CSupportChannels::SC_CALCBOUNDINGBOX | CSupportChannels::SC_DRAWOVERLAY)
, m_subd(subd)
, m_wire_color(wire_color)
{
}

bool CSampleDrawSubDWiresConduit::ExecConduit(CRhinoDisplayPipeline& dp, UINT nActiveChannel, bool& bTerminateChannel)
{
if (nActiveChannel == CSupportChannels::SC_CALCBOUNDINGBOX)
{
ON_BoundingBox bbox;
if (m_subd.GetTightBoundingBox(bbox, false))
m_pChannelAttrs->m_BoundingBox.Union(bbox);
}
else if (nActiveChannel == CSupportChannels::SC_DRAWOVERLAY)
{
CDisplayPipelineAttributes* pDA = const_cast<CDisplayPipelineAttributes*>(dp.DisplayAttrs());
if (nullptr != pDA)
{
CRhinoSubDDisplay subd_display = CRhinoSubDDisplay::Create(m_subd);
CRhinoSubDDisplayAttributes subd_display_attrs;
subd_display_attrs.m_bDrawControlNet = false;
subd_display_attrs.m_bDrawSurfaceNet = false;
subd_display_attrs.m_bDrawEdges = true;
subd_display_attrs.m_bDrawSurface = false;

ON_Color oldColors[4];
float oldThicknesses[4];
pDA->m_ObjectColor = m_wire_color;
pDA->GetSubDWireAttributes(oldColors, oldThicknesses);

// Set color
for (int i = 0; i < 4; i++)
pDA->SetSubDEdgeColor((CDisplayPipelineAttributes::SubDEdgeType)i, m_wire_color);

dp.DrawSubD(subd_display, subd_display_attrs);

// Reset color
for (int i = 0; i < 4; i++)
pDA->SetSubDEdgeColor((CDisplayPipelineAttributes::SubDEdgeType)i, oldColors[i]);
}
}

return true;
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

#pragma region SampleDrawSubDWires command

class CCommandSampleDrawSubDWires : public CRhinoCommand
{
public:
CCommandSampleDrawSubDWires() = default;
UUID CommandUUID() override
{
// {8A5A2555-3656-4144-B096-BE2876CF4030}
static const GUID SampleDrawSubDWiresCommand_UUID =
{ 0x8A5A2555, 0x3656, 0x4144, { 0xB0, 0x96, 0xBE, 0x28, 0x76, 0xCF, 0x40, 0x30 } };
return SampleDrawSubDWiresCommand_UUID;
}
const wchar_t* EnglishCommandName() override { return L"SampleDrawSubDWires"; }
CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override;
};

// The one and only CCommandSampleDrawSubDWires object
static class CCommandSampleDrawSubDWires theSampleDrawSubDWiresCommand;

CRhinoCommand::result CCommandSampleDrawSubDWires::RunCommand(const CRhinoCommandContext& context)
{
ON_Sphere sphere(ON_3dPoint::Origin, 4.0);

ON_SubD subd_sphere;
ON_SubDComponentLocation subd_location = ON_SubDComponentLocation::Surface;
if (nullptr == ON_SubD::CreateSubDQuadSphere(sphere, subd_location, 2, &subd_sphere))
return CRhinoCommand::failure;

CSampleDrawSubDWiresConduit conduit(subd_sphere, ON_Color::SaturatedGold);
conduit.Enable(context.m_rhino_doc_sn);
context.m_doc.Redraw();

CRhinoGetString gs;
gs.SetCommandPrompt(L"Press <Enter> to continue");
gs.AcceptNothing();
gs.GetString();

conduit.Disable();
context.m_doc.Redraw();

return CRhinoCommand::success;
}

#pragma endregion

//
// END SampleDrawSubDWires command
//
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////

0 comments on commit 4a3f456

Please sign in to comment.