Interop Grasshopper Component C++ Display Conduit Odd Behavior

Hello. Can someone please help? I’m using a C++ CRhinoDisplayConduit in a Grasshopper component, and I’m getting this weird behavior with the clipping planes. This code is directly copied and pasted from another CPP file that works exactly as intended in a different component. I’m lost with how to fix it.

class RelativeElevationConduit : public CRhinoDisplayConduit {
	std::vector<const RelativeElevationData*> m_data;
	RenderMaterial m_material = RenderMaterial(L"Relative Elevation Material", RGB(0, 0, 0), 0);

public:
	RelativeElevationConduit() : CRhinoDisplayConduit(CSupportChannels::SC_CALCBOUNDINGBOX | CSupportChannels::SC_PREDRAWOBJECTS | CSupportChannels::SC_POSTDRAWOBJECTS) {
		Enable();
	}

	bool ExecConduit(CRhinoDisplayPipeline& dp, UINT nActiveChannel, bool& bTerminate) override {
		m_pDisplayAttrs->m_bShowMeshEdges = true;
		if (nActiveChannel == CSupportChannels::SC_CALCBOUNDINGBOX) {
			m_pChannelAttrs->m_BoundingBox = ON_BoundingBox::EmptyBoundingBox;
			for (const RelativeElevationData* d : m_data) {
				if (d->GetDisplayMode() != 0)
					m_pChannelAttrs->m_BoundingBox.Union(d->Mesh().BoundingBox());
			}
		}
		else if (nActiveChannel == CSupportChannels::SC_PREDRAWOBJECTS) {
			for (const RelativeElevationData* d : m_data) {
				if (d->GetDisplayMode() != 0) 
					dp.DrawShadedMesh(d->Mesh(), &m_material);
			}
		}
		return true;
	}

	void AddData(const RelativeElevationData* data) {
		for (const RelativeElevationData* d : m_data) {
			if (d == data)
				return;
		}
		m_data.push_back(data);
	}

	void RemoveData(const RelativeElevationData* data) {
		for (int i = (int)m_data.size() - 1; i >= 0; i--) {
			if (m_data[i] == data)
				m_data.erase(m_data.begin() + i);
		}
	}
};
RelativeElevationData::RelativeElevationData(const ON_Mesh* mesh, const MeshGrid* grid) {
	RConduit.AddData(this);
	m_mesh = *mesh;
	m_grid = grid;
	MeshUtil::MeshPoints(mesh, m_points);
	m_mesh.m_C.SetArray(new ON_Color[m_mesh.m_V.Count()], m_mesh.m_V.Count(), m_mesh.m_V.Count());
	Differences.SetArray(new double[m_mesh.FaceCount()], m_mesh.FaceCount(), m_mesh.FaceCount());
	Averages.SetArray(new double[m_mesh.FaceCount()], m_mesh.FaceCount(), m_mesh.FaceCount());
	Minimums.SetArray(new double[m_mesh.FaceCount()], m_mesh.FaceCount(), m_mesh.FaceCount());
	Maximums.SetArray(new double[m_mesh.FaceCount()], m_mesh.FaceCount(), m_mesh.FaceCount());
	m_shader.SetState(m_grid->FaceCount);
}

RelativeElevationData::~RelativeElevationData() {
	RConduit.RemoveData(this);
}

void RelativeElevationData::SetDisplayMode(int mode) {
	m_displayMode = mode;
	setColors();
}

I know it’s related to the frustum calculation mentioned on the linked page, but none of this seems to work. I’ve verified that the union is running and that the display conduit bounding box is being adjusted, but it seems to have no effect on the frustum calculations for the display.

Hi @dbitts960,

We’re probably going to need to have some way of reproducing this. That would include source to a project we can build and run.

Thanks,

– Dale