Spline

A Vue wrapper component for the Spline 3D tool, providing events and auto-resizing.

Preview
Code

API

Prop NameTypeDefaultDescription
scenestringThe URL or path to the Spline scene file. Required.
onLoadFunctionundefinedCallback that fires when the Spline scene loads successfully.
renderOnDemandbooleantrueEnables or disables Spline's render-on-demand optimization.
styleobject{}Custom CSS style applied to the container of the canvas.

Emits

Event NamePayloadDescription
errorErrorEmits if there's an error while loading the Spline scene.
spline-mouse-downanyEmits when a mouseDown event is detected in the Spline scene.
spline-mouse-upanyEmits when a mouseUp event is detected in the Spline scene.
spline-mouse-hoveranyEmits when the mouseHover event is triggered.
spline-key-downanyEmits on keyDown within the Spline scene.
spline-key-upanyEmits on keyUp within the Spline scene.
spline-startanyEmits when the Spline scene starts.
spline-look-atanyEmits when a lookAt event occurs.
spline-followanyEmits when a follow event occurs.
spline-scrollanyEmits on scroll interactions.

Install using CLI

npm
pnpm
bun
yarn
npx shadcn-vue@latest add "https://inspira-ui.com/r/spline.json"

Install Manually

Install the dependencies

npm
pnpm
bun
yarn
npm install @splinetool/runtime

Component Code

You can copy and paste the following code to create this component:

Spline.vue
ParentSize.vue

Features

  • Responsive Canvas: Uses a ParentSize wrapper to adjust to the parent container size.
  • Event Bindings: Exposes Spline’s mouse, keyboard, and scrolling events via Vue emits.
  • Render-On-Demand: Optionally only re-renders when necessary, optimizing performance.
  • Easy Integration: Load a Spline 3D scene by simply passing the scene prop.
  • Cleanup & Disposal: Manages resource disposal on unmount to avoid memory leaks.

Credits

  • Utilizes Spline’s runtime behind the scenes.
  • Inspired by various 3D web experiences using Spline.