# ==========================================================================
# ++ [ sync3d ] :  Quantum Geometric Alignment Engine
# --------------------------------------------------------------------------
# > Hardware-Accelerated Multi-Trace 3D Animations via WebGL Injections
# --------------------------------------------------------------------------
#                     Katharina Maria Brecht (2026)
#                      ORCID: 0009-0001-2176-7476
# ==========================================================================

sync3d | Quantum Geometric Alignment Engine

Synchronized 3D Vector and Marker Animations in 'plotly' via 'WebGL'

Author: Katharina Maria Brecht | ORCID: 0009-0001-2176-7476 | License: GPL-3

sync3d is a lightweight, high-performance R package that bypasses structural rendering bottlenecks in multi-trace 3D animations in plotly. By decoupling vertex computation from wireframe rendering, it enables smooth, hardware-accelerated 3D animations without UI degradation or camera controller resets.


Installation

Install the released version from CRAN:

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

Dual-Layer Architecture

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 resolves this through a dual-layer pipeline:

  1. Particle Layer (R / CPU): Computes frame-by-frame node coordinates (x, y, z) in R and passes them as Trace 0 to plotly::plot_ly().
  2. Metadata Bridge (customEdgeIndices): add_synchronized_3d_edges() serializes the \(E \times 2\) vertex index matrix once (as.numeric(t(edge_indices))) into base_plot$x$customEdgeIndices.
  3. WebGL Wireframe Layer (Browser / GPU): An injected JavaScript hook via htmlwidgets::onRender() listens to the plotly_animated event and updates the topological line trace in real time via Plotly.restyle().

Quick Start: Animated 3D Regular Octahedron

library(plotly)
library(sync3d)

# 1. Canonical vertices of a regular 3D octahedron (V = 6)
base_vertices <- data.frame(
  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 oscillation
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 base and inject WebGL edge synchronization
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")
)

final_plot <- add_synchronized_3d_edges(base_plot, edge_indices)
final_plot

Target Applications


Intention & Scientific Context

sync3d was originally conceptualized during the development of octawave (Spatial Octahedral Quantum Wave Functions) to animate time-evolving 3D polyhedral wave interference models without breaking interactive camera controls.


Companion Ecosystem

sync3d forms the temporal animation layer within a four-package R ecosystem connecting 3D spatial wave physics to 2D boundary projections and discrete matrix quantization:


License

This package is licensed under the GPL-3 License.