Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect reprex::reprex() and arrange for a screenshot #186

Merged
merged 2 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: rgl
Version: 0.108.21
Version: 0.108.22
Title: 3D Visualization Using OpenGL
Authors@R: c(person("Duncan", "Murdoch", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
* `sprites3d()` now has the option of
`rotating = TRUE`, to allow 3D sprites to rotate with
the scene.

* Added `getShaders()` function to get shaders used in WebGL.

* Now detects if `rgl` is running within `reprex::reprex()`
and if so arranges that a screenshot will be included in the
output.

## Minor changes

* Added `as.mesh3d()` methods for `"rglsubscene"` and `"rglscene"`.
Expand Down
10 changes: 10 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@

if (!rgl.useNULL())
setGraphicsDelay(unixos = unixos)

# Are we running in reprex::reprex? If so, do
# the knitr setup so our output appears there.

if (in_reprex()) {
setupKnitr(autoprint = TRUE)
}
}

# Do we need a delay opening graphics?
Expand Down Expand Up @@ -191,3 +198,6 @@ rgl.init <- function(initValue = 0, onlyNULL = FALSE, debug = getOption("rgl.deb
.C( rgl_quit, success=FALSE )

}

in_reprex <- function()
!is.null(getOption("reprex.current_venue"))
13 changes: 5 additions & 8 deletions src/BBoxDeco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,25 +463,21 @@ struct BBoxDeco::BBoxDecoImpl {
}
}

AxisInfo* axis;
Edge* axisedge;
int nedges;

switch(coord)
{
case 0:
axis = &(bboxdeco.xaxis);
axisedge = xaxisedge;
nedges = 4;
break;
case 1:
axis = &(bboxdeco.yaxis);
axisedge = yaxisedge;
nedges = 8;
break;
case 2:
default:
axis = &(bboxdeco.zaxis);
axisedge = zaxisedge;
nedges = 4;
break;
Expand Down Expand Up @@ -520,13 +516,14 @@ struct BBoxDeco::BBoxDecoImpl {

static Edge* fixedEdge(Material* material)
{
Edge* axisedge;
int i,j, lim, coord = material->marginCoord;
Edge* axisedge = xaxisedge;
int i,j, lim = 4, coord = material->marginCoord;
bool match;
switch(coord) {
case 0:
axisedge = xaxisedge;
lim = 4;
// Initialized to this case to suppress "may be unused" message
// axisedge = xaxisedge;
// lim = 4;
break;
case 1:
axisedge = yaxisedge;
Expand Down
3 changes: 2 additions & 1 deletion src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ void rgl::rgl_attrib_count(int* id, int* attrib, int* count)
RGLView* rglview = device->getRGLView();
Scene* scene = rglview->getScene();
Subscene* subscene = scene->whichSubscene(*id);
AABox bbox = subscene->getBoundingBox();
SceneNode* scenenode = scene->get_scenenode(*id);
// getBoundingBox is called for the side effect of possibly calculating data_bbox.
subscene->getBoundingBox();
if ( scenenode )
*count = scenenode->getAttributeCount(subscene, *attrib);
else
Expand Down