Skip to content

Commit

Permalink
bugfix for camera pick missing normal buffer crash, fixes #264 (#267)
Browse files Browse the repository at this point in the history
* test camera view pick

* add missing camera normals buffer
  • Loading branch information
nmwsharp authored Mar 24, 2024
1 parent 40ee3f2 commit b091398
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/camera_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ void CameraView::fillCameraWidgetGeometry(render::ShaderProgram* nodeProgram, re
addPolygon({triangleTop, triangleRight, triangleLeft});

pickFrameProgram->setAttribute("a_vertexPositions", positions);
// pickFrameProgram->setAttribute("a_vertexNormals", normals); // unused
if (pickFrameProgram->hasAttribute("a_vertexNormals")) {
// // this is not actually used, but it only gets optimized out on some platforms, not all
pickFrameProgram->setAttribute("a_vertexNormals", normals);
}
pickFrameProgram->setAttribute("a_barycoord", bcoord);

size_t nFaces = 7;
Expand Down
15 changes: 15 additions & 0 deletions test/src/camera_view_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ TEST_F(PolyscopeTest, CameraViewUpdate) {
polyscope::removeAllStructures();
}

TEST_F(PolyscopeTest, CameraViewPick) {

polyscope::CameraView* cam1 = polyscope::registerCameraView(
"cam1", polyscope::CameraParameters(polyscope::CameraIntrinsics::fromFoVDegVerticalAndAspect(60, 2.),
polyscope::CameraExtrinsics::fromVectors(
glm::vec3{2., 2., 2.}, glm::vec3{-1., -1., -1.}, glm::vec3{0., 1., 0.})));

// This probably doesn't actually click on anything, but it does populate the pick buffers and makes sure that nothing crashes
polyscope::pick::pickAtScreenCoords(glm::vec2{0.3, 0.8});

polyscope::show(3);

polyscope::removeAllStructures();
}

TEST_F(PolyscopeTest, AddCameraViewColorImage) {

polyscope::CameraView* cam1 = polyscope::registerCameraView(
Expand Down

0 comments on commit b091398

Please sign in to comment.