Interactive 3D slides

Complete presentations

The previous examples place one demo in one slide. In a talk, the demos are mixed with the rest of the presentation: a title, an outline, sections, slides of text, and from time to time a slide with a demo next to its text. The two presentations below are the same talk of twelve slides, made once with reveal.js and once with lhtml-site, using the demos of the examples.

In both, go from slide to slide with the arrow keys; click in a demo to turn it, then the arrows still go to the next slide.

In reveal.js

Live: click in the presentation, then use the arrow keys. Open it in its own page.
Download: talk-reveal.zip, the presentation and its demos (demos/), ready to show (see its README.md).Show it: python3 -m http.server 8080 in its folder, then http://localhost:8080/

One HTML file holds the whole presentation, a <section> per slide. The demos are in demos/ next to it:

talk-reveal/
  README.md              how to show it
  index.html             the presentation, below
  demos/
    a1/ a2/ c3/ c6/ c7/  the web builds of the examples: index.html, project.js, project.wasm, project.data
    slide-controls.js    the buttons of the slides
  • A slide with a demo: a <div class="side"> with the text on the left and the frame on the right.
  • data-src loads a demo when its slide comes near, and unloads it after: the demos of the other slides do not run.
  • All the slides are in one page: the buttons of a slide name their demo (data-demo="#surface").

index.html

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Interactive 3D in a talk</title>
<!--
  An example talk of the tutorial "Create slides with interactive 3D", made with reveal.js: twelve
  slides, with titles, text, and interactive 3D models in some of them.

  The demos are in demos/<name>/ next to this file (the web builds of the examples: index.html,
  project.js, project.wasm, project.data), with slide-controls.js. Each one is a plain <iframe>;
  data-src loads it when its slide comes near and unloads it after. All the slides are in this page:
  the buttons of a slide name their demo (data-demo="#surface").

  Open it through a web server: python3 -m http.server 8080 in this folder, then http://localhost:8080/
  reveal.js comes from a CDN: for a talk without network, download it next to this file.
-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reveal.js@5.1.0/dist/reveal.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reveal.js@5.1.0/dist/theme/white.css">
<style>
  /* the text on the left, the demo on the right */
  .reveal .side { display: grid; grid-template-columns: 40% 60%; gap: 30px; align-items: center; text-align: left; }
  .reveal .side ul { font-size: 0.75em; margin: 0; }
  .reveal .side p { font-size: 0.75em; }
  .reveal iframe.demo { width: 100%; height: 520px; border: 0; }
  .reveal code { font-size: 0.85em; }
  .reveal .muted { color: #888; font-size: 0.6em; }
  /* the buttons of the slides, and the current state of the demo (class on) */
  .reveal .controls-row button { font: inherit; font-size: 0.7em; padding: 4px 14px; margin: 0 6px 8px 0;
                                 border-radius: 8px; border: 2px solid #999; background: white; cursor: pointer; }
  .reveal .controls-row button.on { background: #333; color: white; border-color: #333; }
  .reveal .value { font-weight: bold; color: #c0392b; }
</style>
</head>
<body>
<div class="reveal"><div class="slides">

<section>
  <h2>Interactive 3D in a talk</h2>
  <p>An example presentation, made with reveal.js</p>
  <p class="muted">Tutorial: Create slides with interactive 3D</p>
</section>

<section>
  <h3>Outline</h3>
  <p style="font-size: 0.7em">The demos of this talk are C++ programs (OpenGL 3.3), compiled to WebAssembly:
  each one runs in a frame of the slide, next to the text.</p>
  <ol>
    <li>A demo in the slide</li>
    <li>Settings and controls</li>
    <li>Values from the program</li>
  </ol>
  <p class="muted">Click in a demo to turn it with the mouse; the arrow keys still go to the next slide.</p>
</section>

<section><h2>1. A demo in the slide</h2></section>

<section>
  <h3>A C++ program in the slide</h3>
  <div class="side">
    <ul>
      <li>A program in raw OpenGL 3.3, about 200 lines</li>
      <li>Compiled to WebAssembly with Emscripten</li>
      <li>Shown by the slide in an <code>&lt;iframe&gt;</code></li>
      <li>Set by the address of the frame: <code>?speed=0.2&amp;tilt=25</code></li>
    </ul>
    <iframe class="demo" data-src="demos/a1/index.html?speed=0.2&tilt=25"></iframe>
  </div>
</section>

<section>
  <h3>The same program, another preset</h3>
  <div class="side">
    <ul>
      <li>The same build as the previous slide</li>
      <li>Another address: <code>?speed=0.5&amp;tilt=-30&amp;background=dark</code></li>
      <li>One build serves all the slides that show this demo</li>
    </ul>
    <iframe class="demo" data-src="demos/a1/index.html?speed=0.5&tilt=-30&background=dark"></iframe>
  </div>
</section>

<section><h2>2. Settings and controls</h2></section>

<section>
  <h3>A panel built from the program</h3>
  <div class="side">
    <ul>
      <li>The program declares its parameters, with their ranges</li>
      <li>The page of the demo builds the panel from them</li>
      <li>Each slider changes a uniform while the demo turns</li>
    </ul>
    <iframe class="demo" data-src="demos/a2/index.html?twist=0.8&controls=twist,hue,speed,light,reset"></iframe>
  </div>
</section>

<section>
  <h3>Buttons in the slide</h3>
  <div class="side">
    <div>
      <p>The buttons below are in the text of the slide, outside the frame.</p>
      <div class="controls-row">
        <button data-demo="#surface" data-demo-set="shape=ripple">Ripple</button>
        <button data-demo="#surface" data-demo-set="shape=waves">Waves</button>
        <button data-demo="#surface" data-demo-set="drop">Drop</button>
        <button data-demo="#surface" data-demo-set="ampl=0.25&amp;k=14">Strong</button>
      </div>
      <p>Amplitude: <span class="value" data-demo="#surface" data-demo-value="ampl" data-digits="2"></span></p>
    </div>
    <iframe class="demo" id="surface" data-src="demos/c3/index.html?controls=ampl,k,speed&panel=bl"></iframe>
  </div>
</section>

<section>
  <h3>An ImGui window</h3>
  <div class="side">
    <div>
      <ul>
        <li>Marching cubes on a scalar field, recomputed at each change</li>
        <li>The interface is the ImGui window of the program</li>
        <li>Its text is enlarged by the address: <code>?gui_scale=1.4</code></li>
      </ul>
      <div class="controls-row">
        <button data-demo="#marching" data-demo-set="power_c=1.2">Third blob</button>
        <button data-demo="#marching" data-demo-set="isovalue=0.3">Larger</button>
        <button data-demo="#marching" data-demo-set="power_c=0&amp;isovalue=0.5">Back</button>
      </div>
    </div>
    <iframe class="demo" id="marching" data-src="demos/c6/index.html?gui_scale=1.4"></iframe>
  </div>
</section>

<section><h2>3. Values from the program</h2></section>

<section>
  <h3>The slide shows a value of the program</h3>
  <div class="side">
    <div>
      <p>Drag a blue point: the program computes the length of the curve, and the slide shows it.</p>
      <p>Length of the curve: <span class="value" data-demo="#curve" data-demo-value="length" data-digits="2"></span></p>
      <div class="controls-row">
        <button data-demo="#curve" data-demo-set="curve=bezier">B&eacute;zier</button>
        <button data-demo="#curve" data-demo-set="curve=spline">Spline</button>
      </div>
    </div>
    <iframe class="demo" id="curve" data-src="demos/c7/index.html?controls=points,polygon,reset&panel=br"></iframe>
  </div>
</section>

<section>
  <h3>Conclusion</h3>
  <ul style="font-size: 0.75em">
    <li>A 3D demo in a slide is a web page in a frame</li>
    <li>The address of the frame sets it, slide by slide</li>
    <li>A panel, buttons in the slide or ImGui drive it during the talk</li>
    <li>The program can send values back to the slide</li>
  </ul>
  <p style="font-size: 0.7em">The method, the code of these demos and of this talk: the tutorial
  <a href="https://scholartools.fr/interactive-3d-slides/">Create slides with interactive 3D</a>.</p>
</section>

</div></div>
<script src="https://cdn.jsdelivr.net/npm/reveal.js@5.1.0/dist/reveal.js"></script>
<script src="demos/slide-controls.js"></script>
<script>
  Reveal.initialize({hash: true});
  // After a click in a demo, the keyboard stays in its frame. When the slide changes, reveal.js
  // unloads that demo (data-src): the frame keeps the keyboard but becomes an empty page, which
  // sends no key back, and the next arrow would be lost. The presentation takes the keyboard back.
  Reveal.on('slidechanged', () => {
    if (document.activeElement && document.activeElement.tagName === 'IFRAME') document.activeElement.blur();
  });
</script>
</body>
</html>

In lhtml-site

Live: click in the presentation, then use the arrow keys. Open it in its own page, or its PDF.
Download: talk-lhtml-site.zip, the sources of the presentation and its demos (src/_demo/)Build it: lhtml-site in its folder, then lhtml-site --serve

A folder per slide, in the order of their names. The demos are in src/_demo/; a folder whose name starts with an underscore is not a slide, it is copied as it is.

talk-lhtml-site/
  README.md                    how to build and show it
  configure.yaml               the build: the slides in the browser, and a PDF
  src/
    01_title/index.html.j2     a slide: its title (=), its text, its demo (demo::)
    02_outline/index.html.j2
    ...
    12_conclusion/index.html.j2
    _style/talk.css            the buttons of the slides, and the image of a demo in the PDF
    _demo/a1/ ... _demo/c7/    the web builds of the examples, with their poster
    _demo/slide-controls.js
  • A slide with a demo: the layout side puts the text on the left and the media:: block on the right.
  • demo:: writes the frame; img:: gives the image of the demo in the PDF (the classes .live and .still, and _style/talk.css).
  • A slide shows one page: the buttons of a slide drive its demo without naming it.
  • configure.yaml loads the stylesheet and slide-controls.js in every slide (cssAbs, jsAbs).

configure.yaml

# An example talk of the tutorial "Create slides with interactive 3D", made with lhtml-site:
# twelve slides, with titles, text, and interactive 3D models in some of them.
#
#   lhtml-site                   build into .site/: html/ in the browser, slides.pdf
#   lhtml-site --serve --watch   preview on http://127.0.0.1:8000/
#
# The demos are in src/_demo/<name>/ (the web builds of the examples: index.html, project.js,
# project.wasm, project.data, poster.png), with slide-controls.js; a folder whose name starts with an
# underscore is not a slide, it is copied as it is.
source_directory: 'src/'
site_directory: '.site/'
targets:
  html: {theme: slides}
  pdf: {theme: slides-pdf}
keywords:
  cssAbs: [_style/talk.css]              # the buttons of the slides, and the image of a demo in the PDF
  jsAbs: [_demo/slide-controls.js]       # the buttons of the slides drive their demo

src/_style/talk.css

/* The buttons written in the slides (data-demo-set), and the current state of the demo (class on) */
.controls button { font: inherit; font-size: 80%; padding: 4px 16px; margin: 0 8px 8px 0; cursor: pointer;
                   border: 2px solid #999; border-radius: 8px; background: white; }
.controls button.on { background: #333; color: white; border-color: #333; }
.value { font-weight: bold; color: #c0392b; }

/* On screen the demo, in the PDF its image (the PDF is printed by the browser) */
@media screen { .still { display: none; } }
@media print { .live, .controls { display: none; } }

The twelve slides

src/01_title/index.html.j2

{% set layout = 'section' %}

= Interactive 3D in a talk

An example presentation, made with lhtml-site

muted:: Tutorial: Create slides with interactive 3D ::

src/02_outline/index.html.j2

= Outline

The models of this talk are C++ programs (OpenGL 3.3), compiled to WebAssembly: each one runs in a
frame of the slide, next to the text.

<ol>
<li>A model in the slide</li>
<li>Settings and controls</li>
<li>Values from the program</li>
</ol>

gap::

small:: Click in a model to turn it with the mouse; the arrow keys still go to the next slide. ::

src/03_part-model/index.html.j2

{% set layout = 'section' %}

= 1. A model in the slide

src/04_program/index.html.j2

{% set layout = 'side' %}

= A C++ program in the slide

* A program in raw OpenGL 3.3, about 200 lines
* Compiled to WebAssembly with Emscripten
* Shown by the slide in a frame (`demo::`)
* Set by the address of the frame: `?speed=0.2&tilt=25`

media::
demo::../_demo/a1/index.html?speed=0.2&tilt=25(.live)
img::../_demo/a1/poster.png(.still)
::

src/05_preset/index.html.j2

{% set layout = 'side' %}

= The same program, another preset

* The same build as the previous slide
* Another address: `?speed=0.5&tilt=-30&background=dark`
* One build serves all the slides that show this model

media::
demo::../_demo/a1/index.html?speed=0.5&tilt=-30&background=dark(.live)
img::../_demo/a1/poster.png(.still)
::

src/06_part-controls/index.html.j2

{% set layout = 'section' %}

= 2. Settings and controls

src/07_panel/index.html.j2

{% set layout = 'side' %}

= A panel built from the program

* The program declares its parameters, with their ranges
* The page of the demo builds the panel from them
* Each slider changes a uniform while the model turns

small:: Address of the frame: `?twist=0.8&controls=twist,hue,speed,light,reset` ::

media::
demo::../_demo/a2/index.html?twist=0.8&controls=twist,hue,speed,light,reset(.live)
img::../_demo/a2/poster.png(.still)
::

src/08_buttons/index.html.j2

{% set layout = 'side' %}

= Buttons in the slide

The buttons below are in the text of the slide, outside the frame.

<div class="controls">
<p>
<button data-demo-set="shape=ripple">Ripple</button>
<button data-demo-set="shape=waves">Waves</button>
<button data-demo-set="drop">Drop</button>
<button data-demo-set="ampl=0.25&amp;k=14">Strong</button>
</p>
<p>Amplitude: <span class="value" data-demo-value="ampl" data-digits="2"></span></p>
</div>

media::
demo::../_demo/c3/index.html?controls=ampl,k,speed&panel=bl(.live)
img::../_demo/c3/poster.png(.still)
::

src/09_imgui/index.html.j2

{% set layout = 'side' %}

= An ImGui window

* Marching cubes on a scalar field, recomputed at each change
* The interface is the ImGui window of the program
* Its text is enlarged by the address: `?gui_scale=1.4`

<div class="controls">
<p>
<button data-demo-set="power_c=1.2">Third blob</button>
<button data-demo-set="isovalue=0.3">Larger</button>
<button data-demo-set="power_c=0&amp;isovalue=0.5">Back</button>
</p>
</div>

media::
demo::../_demo/c6/index.html?gui_scale=1.4(.live)
img::../_demo/c6/poster.png(.still)
::

src/10_part-values/index.html.j2

{% set layout = 'section' %}

= 3. Values from the program

src/11_readout/index.html.j2

{% set layout = 'side' %}

= The slide shows a value of the program

Drag a blue point: the program computes the length of the curve, and the slide shows it.

<div class="controls">
<p>Length of the curve: <span class="value" data-demo-value="length" data-digits="2"></span></p>
<p>
<button data-demo-set="curve=bezier">B&eacute;zier</button>
<button data-demo-set="curve=spline">Spline</button>
</p>
</div>

media::
demo::../_demo/c7/index.html?controls=points,polygon,reset&panel=br(.live)
img::../_demo/c7/poster.png(.still)
::

src/12_conclusion/index.html.j2

= Conclusion

* A 3D model in a slide is a web page in a frame
* The address of the frame sets it, slide by slide
* A panel, buttons in the slide or ImGui drive it during the talk
* The program can send values back to the slide
* In the PDF of the talk, an image of each model

gap::

The method, the code of these models and of this talk: the tutorial
link::https://scholartools.fr/interactive-3d-slides/[Create slides with interactive 3D].

The same talk in both

reveal.js lhtml-site
The slides one HTML file, a <section> per slide a folder per slide, index.html.j2
A demo <iframe class="demo" data-src="demos/c3/index.html?..."> demo::../_demo/c3/index.html?...
Text and demo side by side a grid in the style of the page the layout side
Buttons in a slide name their demo: data-demo="#surface" drive the demo of the slide
The PDF the printing of reveal.js slides-pdf, with an image of each demo

Next: Your own program in a slide, then On the day of the talk.