Callback behavior for objects with the same scene ID

28 views Asked by At

I can't quite explain it, but the callback function doesn't seem to be working properly with the same scene ID. Only callbacks prepared later seem to be processed.

I don't think it will be a problem in most cases, and since callbacks are not set very often, it may be difficult to notice. However, there is a possibility that callbacks are not being processed correctly even in simple examples that do not use subscenes, so I just wanted to ask to be sure.

% R -e rmarkdown::render"('ex06.Rmd',output_file='index.html')"
---
title: "cb06.Rmd"
output: html_document
vignette: >
  %\VignetteIndexEntry{Callback implementation}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
library(knitr)
library(rgl)
options(rgl.useNULL = TRUE)
setupKnitr(autoprint = FALSE)
opts_chunk$set(echo=FALSE, error=FALSE, warning=FALSE, message=FALSE)
knit_hooks$set(webgl = hook_webgl)
setupKnitr(autoprint = FALSE)
```

```{r}
sys.source("ex06.R", envir = knit_global())
```

<div style="display: flex; justify-content: space-around; margin: none;">
```{r}
func1()
id1 <- subsceneInfo()$id

js1 <- readLines("cb06.txt")
js1 <- sub("%subid%", id1, js1)
js1 <- sub(".begin", ".begin1", js1)
js1 <- sub(".update", ".update1", js1)

scene <- setUserCallbacks("left", 
      begin = "begin1",
      update = "update1",
      subscene = id1,
      applyToScene = TRUE,
      applyToDev = FALSE,
      javascript = js1)

rglwidget(scene, width = 0.4 * figWidth(), height = 0.4 * figWidth())
```
   
```{r}
func1()
id2 <- subsceneInfo()$id

js2 <- readLines("cb06.txt")
js2 <- sub("%subid%", id2, js2)
js2 <- sub(".begin", ".begin2", js2)
js2 <- sub(".update", ".update2", js2)

scene <- setUserCallbacks("left", 
      begin = "begin2",
      update = "update2",
      subscene = id2,
      applyToScene = TRUE,
      applyToDev = FALSE,
      javascript = js2)

rglwidget(scene, width = 0.4 * figWidth(), height = 0.4 * figWidth())
```
</div>
## ex06.R
func1 <- function() {
  open3d()
  subscene <- newSubscene3d(newviewport = c(0, 0, 500, 500))
  par3d(windowRect = c(0, 0, 500, 500))
  view3d(theta=0, phi=0, zoom=1, fov=0)
  bg3d(color = "grey")
  spheres3d(0,0,0, r=10)
  spheres3d(500,500,0, r=10)
}
// cb06.txt
window.subid = %subid%;

window.begin = function(x, y) {
    let activeSub = this.getObj(subid);
    activeSub.userSaveMat = new CanvasMatrix4(activeSub.par3d.userMatrix);
    this.canvas.style.cursor = "grabbing";
};

window.update = function(x, y) { 
    let objects = this.scene.objects,
        activeSub = this.getObj(subid);

    activeSub = this.scene.objects[subid];
//  alert(subid)
    activeSub.par3d.userMatrix.load(objects[subid].userSaveMat);
    activeSub.par3d.userMatrix.rotate(x, 0, 1, 0);
    activeSub.par3d.userMatrix.rotate(y, -1, 0, 0);
    this.drawScene();
};
0

There are 0 answers