Texture doesn't map correctly using rglWidget in Shiny
can-taslicukur opened this issue · 4 comments
- rgl Version: 1.1.12
- R Version: 4.2.2
- Platform: Darwin Ege-MBP 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:41 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8103 arm64
Hi, thank you for this amazing package! I am trying to visualize a sphere with a texture in a shiny app. However, I've realized that texture isn't mapped correctly in the shiny output compared to RGL Device.
Here is an example:
RGL Device
library(rgl)
spheres3d(
x = 0,
y = 0,
z = 0,
radius = 1,
texture = system.file("textures/sunsleep.png", package = "rgl"),
alpha = 1,
texmode = "replace",
textype = "rgb",
col = "white"
)
You can see that texture was mapped nicely, there is no overlap between the left and the right of the image.
Shiny
library(shiny)
library(rgl)
shinyApp(
ui = bootstrapPage(
rglwidgetOutput("widget")
),
server = function(input, output, session) {
output$widget <- renderRglwidget({
try(close3d(), silent = TRUE)
open3d(useNULL = TRUE)
spheres3d(
x = 0,
y = 0,
z = 0,
radius = 1,
texture = system.file("textures/sunsleep.png", package = "rgl"),
alpha = 1,
texmode = "replace",
textype = "rgb",
col = "white"
)
rglwidget()
})
}
)
In this case, the left and right edges of the image overlap and create a deformed texture.
Same issue also happening using the bg3d
function when the sphere = TRUE
and you can see it in the example here:
https://dmurdoch.github.io/rgl/reference/bg.html
Thanks, I'll look into it. (I don't think Shiny is involved at all; just calling rglwidget()
after your first example is sufficient to illustrate the problem.)
The problem is that in the rglwidget() display, the texture coordinates don't go all the way from 0 to 1, they run over a slightly smaller range, horizontally from 0 to 0.94 and vertically from 0.06 to 0.94. What you see that looks like overlap is really the texture in reverse, going from 0.94 to 0.06. This should be fairly easy to fix, but I don't think I'll have time to get to it today.
Good to hear that it's an easy fix, I cant open a PR because I don't know how GL works :) Thank you so much!
Thanks for the report, should be all fixed now (though Github isn't running R properly, so the website may take a while to be updated).