spline-selfhosted

demo repository to show selfhosting of spline 3D scene (exports)

Stars
6
Committers
1

spline-selfhosted

  • demo repository to show selfhosting of spline 3D scene (exports)

Two approaches used:

Demo:

Goals

Local setup

npm install 
npm run dev

How was this created?

Spline offers several ways to export code, see: Exporting as Code . There is also a Web Component available: spline-viewer.

First, we scaffold a new vite project with vanillajs:

# https://vitejs.dev/guide/#scaffolding-your-first-vite-project
npm create vite@latest . -- --template vanilla

spline runtime (vanillajs)

  1. Install it:
# https://www.npmjs.com/package/@splinetool/runtime
npm install @splinetool/runtime
  1. Export spline scene

Use "Download bundled zip (Web content)" here:

Unzip it and place the scene.splinecode file into public/3d-models.

  1. Add <canvas> to index.html, add spline JS code to main.js

Instead of loading the scene from the spline server, we use the local file:

spline.load('/3d-models/planet/scene.splinecode');

spline-viewer web component

  1. Install it:
# https://www.npmjs.com/package/@splinetool/viewer
npm install @splinetool/viewer
  1. Import it in main.js:
// import spline-viewer web component
import { SplineViewer } from '@splinetool/viewer';
  1. Just use the exported spline scene (see above) in HTML:
<spline-viewer width="500" height="500" url="/3d-models/planet/scene.splinecode"></spline-viewer>

Credits

Resources