Rendering 3D
note
3D support in Presenter.js is new as of v0.10.0 and this documentation is not yet complete.
Presenter also supports rendering 3D content (including custom 3D models) via Three.js. To render 3D content in Presenter.js, complete the following steps.
- Install
threein your presentation. Presenter.js doesn't come bundled withthreeas a dependency, so you must install it yourself:
npm install three
- Add the Presenter.js 3D object renderers to your presentation's
BrowserCanvasRenderer. You can do so by adding toobjectRenderersvia:
import { getThreeObjectRenderers } from "presenter/3d";
const renderer = new BrowserCanvasRenderer({
presentation,
objectRenderers: {
...(await getThreeObjectRenderers(presentation)),
},
});
- Create a
ThreeScenethat is added as an object to a slide. TheThreeSceneitself can include animatable objects like:
ThreeBox: a rectangular prismThreeSphere: a sphereThreeModel: a 3D model loaded from a file (e.g. a.glbfile)- Within the
ThreeModel, you can specify identifiers forThreeModelNodes andThreeModelMaterials that appear within the model, to give your presentation the ability to animate particular nodes or materials within the model.
- Within the
ThreePresenterGroup: acts as a Presenter.jsGroupthat exists in 3D space and can live in the same world as other 3D objects
Example
import { Anchor, Animate, Easing, Pause, Slide } from "presenter";import { ThreeModel, ThreeModelNode, ThreeScene } from "presenter/3d";import PresenterExample from "../components/PresenterExample";
const door = ThreeModelNode({ name: "Door",});
const house = ThreeModel({ src: "/models/house.glb", nodes: [door],});
const scene = ThreeScene([house], { anchor: Anchor.CENTER, cameraY: 0.8, height: 2160, width: 3840, ...position(0.5, 0.5),});
const slide = Slide({ objects: [scene], animations: [ Animate(house, { rotationY: 50, x: -1 }), Animate(house, { rotationY: -50, x: 1 }), Animate(door, { rotationY: -120 }), [ Animate(house, { rotationY: 0, x: 0 }), Pause(500), Animate(door, { rotationY: 0 }), ], ],});Notes
3D rendering relies on WebGL, which is only available in browser contexts. Node-based rendering (e.g. rendering to PDF or rendering to images) won't include 3D content.
To address this, Presenter.js offers two options:
- Add
THREE_FALLBACK_OBJECT_RENDERERSorTHREE_POWERPOINT_FALLBACK_OBJECT_RENDERERSto your presentation'sobjectRendererswhen exporting. These renderers will render a image placeholder of your choice for any 3D content.- You can use
installThreeSceneCaptureApito capture a 3D scene as an image and then use that image as the placeholder. -
- You can use
- Use
BrowserImageRendererto render your presentation to images in a browser context, which will include 3D content. This can be automated using tools like Puppeteer or Playwright.