sync3d: Connecting Discrete Geometry with Continuous Time-Waves

Katharina Maria Brecht (ORCID: 0009-0001-2176-7476)

Overview

sync3d solves a core performance bottleneck in interactive 3D scientific visualization in R: keeping dynamic topological wireframes synchronized with moving 3D particles across animation frames without blocking the browser’s main CPU thread.

In native plotly, animating both nodes and edges simultaneously forces the CPU to rebuild the full geometric mesh on every frame, causing visible lag or UI freezes. sync3d decouples vertex motion from edge connectivity so that topological lines update smoothly on the GPU.

Installation

You can install the released version of sync3d from CRAN:

install.packages("sync3d")
library(sync3d)

Dual-Layer Architecture

sync3d splits the rendering pipeline into two synchronized layers:

  1. Particle Layer (R / CPU): Computes frame-by-frame node coordinates (x, y, z) and passes them as Trace 0 to plotly::plot_ly(). Because only vertex trajectories are stored across \(T\) frames, memory overhead scales as \(O(T \cdot V)\) rather than \(O(T \cdot (V + E))\).
  2. Metadata Bridge (customEdgeIndices): add_synchronized_3d_edges() serializes the \(E \times 2\) adjacency matrix once (as.numeric(t(edge_indices))) into base_plot$x$customEdgeIndices.
  3. Wireframe Layer (Browser / WebGL GPU): Via htmlwidgets::onRender(), an embedded JavaScript hook converts 1-based R indices to 0-based JavaScript offsets, listens to the plotly_animated event, and updates the line trace (#666666, opacity 0.5) directly via Plotly.restyle().

Target Applications

Worked Example: Oscillating 3D Regular Octahedron

The following example constructs a symmetric regular octahedron (\(V = 6\) vertices, \(E = 12\) edges) undergoing continuous harmonic radial oscillation across \(T = 20\) frames:

library(plotly)
library(sync3d)

# 1. Canonical vertices of a regular 3D octahedron (V = 6)
base_vertices <- data.frame(
  id = 1:6,
  x0 = c( 1, -1,  0,  0,  0,  0),
  y0 = c( 0,  0,  1, -1,  0,  0),
  z0 = c( 0,  0,  0,  0,  1, -1)
)

# 2. Generate T = 20 frames with harmonic radial modulation
theta <- seq(0, 2 * pi, length.out = 20)
anim_df <- do.call(rbind, lapply(seq_along(theta), function(t_idx) {
  r_t <- 1 + 0.30 * sin(theta[t_idx])
  data.frame(
    frame = t_idx,
    x = base_vertices$x0 * r_t,
    y = base_vertices$y0 * r_t,
    z = base_vertices$z0 * r_t
  )
}))

# 3. Define the 12 structural edges of the octahedron (E = 12)
edge_indices <- matrix(c(
  1, 3,  1, 4,  1, 5,  1, 6,
  2, 3,  2, 4,  2, 5,  2, 6,
  3, 5,  3, 6,  4, 5,  4, 6
), ncol = 2, byrow = TRUE)

# 4. Build the animated 3D marker plot (Trace 0)
base_plot <- plot_ly(
  data = anim_df,
  x = ~x, y = ~y, z = ~z,
  frame = ~frame,
  type = "scatter3d",
  mode = "markers",
  marker = list(size = 7, color = "#005F73")
)

# 5. Inject synchronized WebGL edges across all animation frames
final_plot <- add_synchronized_3d_edges(base_plot, edge_indices)
final_plot

Summary

When executed in an interactive R session or browser environment, clicking Play smoothly expands and contracts the six octahedron vertices while all twelve WebGL edges stay locked onto their endpoints in real time—without camera resets or frame drops. By decoupling discrete topological structures from continuous temporal trajectories, sync3d enables responsive 3D scientific animations directly inside standard plotly workflows.