#include "stdafx.h" //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// // // BEGIN TestPablo command // const static UINT TEST_PABLO_CHANNELS = CSupportChannels::SC_SETUPFRUSTUM | CSupportChannels::SC_CALCBOUNDINGBOX | CSupportChannels::SC_POSTDRAWOBJECTS; class CTestPabloConduit : public CRhinoDisplayConduit { public: CTestPabloConduit(const ON_UUID& active_viewport_id, const ON_Mesh* mesh); bool ExecConduit(CRhinoDisplayPipeline& dp, UINT nChannel, bool& bTerminate) override; private: // channel event handlers void SetupFrustumHelper(CRhinoDisplayPipeline& dp); void CalcBoundingBoxHelper(CRhinoDisplayPipeline& dp); void PostObjectsDrawHelper(CRhinoDisplayPipeline& dp); private: const ON_Mesh* m_mesh; ON_UUID m_active_viewport_id; }; CTestPabloConduit::CTestPabloConduit(const ON_UUID& active_viewport_id, const ON_Mesh* mesh) : CRhinoDisplayConduit(TEST_PABLO_CHANNELS) , m_active_viewport_id(active_viewport_id) , m_mesh(mesh) { } bool CTestPabloConduit::ExecConduit(CRhinoDisplayPipeline& dp, UINT nChannel, bool& bTerminate) { UNREFERENCED_PARAMETER(bTerminate); if (CSupportChannels::SC_SETUPFRUSTUM == (nChannel & CSupportChannels::SC_SETUPFRUSTUM)) SetupFrustumHelper(dp); else if (CSupportChannels::SC_CALCBOUNDINGBOX == (nChannel & CSupportChannels::SC_CALCBOUNDINGBOX) ) CalcBoundingBoxHelper(dp); else if (CSupportChannels::SC_POSTDRAWOBJECTS == (nChannel & CSupportChannels::SC_POSTDRAWOBJECTS) ) PostObjectsDrawHelper(dp); return true; } void CTestPabloConduit::SetupFrustumHelper(CRhinoDisplayPipeline& dp) { CRhinoViewport* vp = dp.GetRhinoVP(); if (nullptr == vp || vp->ViewportId() != m_active_viewport_id) return; ON_ClippingPlaneInfo cpi; cpi.m_plane_equation = ON_Plane::World_xy.plane_equation; cpi.m_plane_id = ON_nil_uuid; cpi.m_bEnabled = true; m_pChannelAttrs->m_ClippingPlanes.Append(cpi); } void CTestPabloConduit::CalcBoundingBoxHelper(CRhinoDisplayPipeline& dp) { if (nullptr != m_mesh && m_mesh->IsValid()) { ON_BoundingBox bbox; if (m_mesh->GetBoundingBox(bbox, false)) m_pChannelAttrs->m_BoundingBox.Union(bbox); } } void CTestPabloConduit::PostObjectsDrawHelper(CRhinoDisplayPipeline& dp) { if (nullptr != m_mesh && m_mesh->IsValid()) { if (m_pDisplayAttrs->m_bShadeSurface) { CDisplayPipelineMaterial mat; dp.SetupDisplayMaterial(mat, ON_Color::Black); dp.DrawShadedMesh(*m_mesh, &mat); } dp.DrawWireframeMesh(*m_mesh, ON_Color::Black); } } //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// class CCommandTestPablo : public CRhinoCommand { public: CCommandTestPablo() = default; UUID CommandUUID() override { // {A8517865-7234-4D27-A3D1-C5671308B9D7} static const GUID TestPabloCommand_UUID = { 0xA8517865, 0x7234, 0x4D27,{ 0xA3, 0xD1, 0xC5, 0x67, 0x13, 0x08, 0xB9, 0xD7 } }; return TestPabloCommand_UUID; } const wchar_t* EnglishCommandName() override { return L"TestPablo"; } CRhinoCommand::result RunCommand(const CRhinoCommandContext& context) override; }; // The one and only CCommandTestPablo object static class CCommandTestPablo theTestPabloCommand; CRhinoCommand::result CCommandTestPablo::RunCommand(const CRhinoCommandContext& context) { CRhinoView* view = RhinoApp().ActiveView(); if (nullptr == view) return CRhinoCommand::failure; int face_count = 6; int vertex_count = 12; bool bVertexNormals = false; bool bTextureCoordinates = false; ON_Mesh mesh(face_count, vertex_count, bVertexNormals, bTextureCoordinates); mesh.SetVertex(0, ON_3fPoint(0.0f, 0.0f, -0.3f)); mesh.SetVertex(1, ON_3fPoint(1.0f, 0.0f, -0.3f)); mesh.SetVertex(2, ON_3fPoint(2.0f, 0.0f, -0.3f)); mesh.SetVertex(3, ON_3fPoint(3.0f, 0.0f, -1.3f)); mesh.SetVertex(4, ON_3fPoint(0.0f, 1.0f, -1.3f)); mesh.SetVertex(5, ON_3fPoint(1.0f, 1.0f, 0.6f)); mesh.SetVertex(6, ON_3fPoint(2.0f, 1.0f, -0.3f)); mesh.SetVertex(7, ON_3fPoint(3.0f, 1.0f, 0.0f)); mesh.SetVertex(8, ON_3fPoint(0.0f, 2.0f, -0.3f)); mesh.SetVertex(9, ON_3fPoint(1.0f, 2.0f, 0.6f)); mesh.SetVertex(10, ON_3fPoint(2.0f, 2.0f, 0.6f)); mesh.SetVertex(11, ON_3fPoint(3.0f, 2.0f, 0.6f)); mesh.SetQuad(0, 0, 1, 5, 4); mesh.SetQuad(1, 1, 2, 6, 5); mesh.SetQuad(2, 2, 3, 7, 6); mesh.SetQuad(3, 4, 5, 9, 8); mesh.SetQuad(4, 5, 6, 10, 9); mesh.SetQuad(5, 6, 7, 11, 10); mesh.UpdateDoublePrecisionVertices(); mesh.ComputeVertexNormals(); mesh.Compact(); CTestPabloConduit conduit(view->ActiveViewportID(), &mesh); conduit.Enable(context.m_doc.RuntimeSerialNumber()); context.m_doc.Regen(); CRhinoGetString gs; gs.SetCommandPrompt(L"Press to continue"); gs.AcceptNothing(); gs.GetString(); conduit.Disable(); context.m_doc.Regen(); return CRhinoCommand::success; } // // END TestPablo command // //////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////