Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@splinetool/vue-spline

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@splinetool/vue-spline

**vue-spline** allows you to export and use spline scenes directly in your vue websites.

  • 1.0.1
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
4
Weekly downloads
 
Created
Source

vue-spline

vue-spline allows you to export and use spline scenes directly in your vue websites.

🌈 Spline is a friendly 3d collaborative design tool for the web.

WebsiteTwitterDiscordDocumentation

Table of Contents

Install

yarn add @splinetool/vue-spline @splinetool/runtime

or

npm install @splinetool/vue-spline @splinetool/runtime

Usage

To use vue-spline, first you have to go to the Spline editor, click on the Export button and select "Vue.js".

Spline generates links for Development (Drafts) and Production.

Drafts are generated each time you press on "Generate Draft". This will create a new link with the current content of the scene. All previous drafts are stored under the "Drafts" tab.

You can use the drafts to try ideas, and once you are ready, you can promote your drafts to production.

Once you have a draft or production URL, you can start using the vue-spline component in vue.

<template>
  <Spline scene="[DRAFT OR PROD URL]" />
</template>

<script>
import Spline from '@splinetool/vue-spline';
export default {
  name: 'App',
  components: {
    Spline,
  },
};
</script>

Read and modify Spline objects

You can query any Spline object via findObjectById or findObjectByName.

(You can get the ID of the object in the Develop pane of the right sidebar).

<template>
  <Spline scene="/scene.spline" @spline-loaded="onSplineLoaded" />
  <button @click="onClick">Move</button>
</template>

<script>
import Spline from '@splinetool/vue-spline';
export default {
  name: 'App',
  components: {
    Spline,
  },
  data() {
    return {
      obj: null,
    };
  },
  methods: {
    onSplineLoaded(spline) {
      this.obj = spline.findObjectById('8E8C2DDD-18B6-4C54-861D-7ED2519DE20E');
    },
    onClick() {
      if (this.obj) {
        console.log(this.obj); // Spline Object => { name: 'my object', id:'8E8C2DDD-18B6-4C54-861D-7ED2519DE20E', position: {}, ... }
        // move the object in 3D space
        this.obj.position.x += 10;
      }
    },
  },
};
</script>

Listen to events

You can listen to any Spline Event you set in the Events panel of the editor by attaching a listener to the Spline component.

<template>
  <Spline scene="/scene.spline" @spline-mousedown="onMouseDown" />
</template>

<script>
import Spline from '@splinetool/vue-spline';
export default {
  name: 'App',
  components: {
    Spline,
  },
  data() {
    return {
      obj: null,
    };
  },
  methods: {
    onMouseDown(e) {
      if (e.target.id === '8E8C2DDD-18B6-4C54-861D-7ED2519DE20E') {
        // doSomething();
      }
    },
  },
};
</script>

You can find a list of all of the Spline Event listeners in the Spline Component Props section.

Trigger Spline events from outside

You can trigger any animation Event you set in the Events panel in the Spline Editor.

You can use the emitEvent function via the spline ref, passing the event type and the ID of your object.

(You can get the ID of the object in the Develop pane of the right sidebar).

<template>
  <Spline scene="/scene.spline" @spline-loaded="onSplineLoaded" />
  <button @onClick="triggerAnimation">Trigger Spline Animation</button>
</template>

<script>
import Spline from '@splinetool/vue-spline';
export default {
  name: 'App',
  components: {
    Spline,
  },
  data() {
    return {
      spline: null,
    };
  },
  methods: {
    onSplineLoaded(spline) {
      this.spline = spline;
    },
    triggerAnimation({ target }) {
      this.spline.emitEvent(
        'mouseHover',
        '8E8C2DDD-18B6-4C54-861D-7ED2519DE20E'
      );
    },
  },
};
</script>

Or you can query the spline object first, and then trigger the event:

<template>
  <Spline scene="/scene.spline" @spline-loaded="onSplineLoaded" />
  <button @onClick="triggerAnimation">Trigger Spline Animation</button>
</template>

<script>
import Spline from '@splinetool/vue-spline';
export default {
  name: 'App',
  components: {
    Spline,
  },
  data() {
    return {
      obj: null,
    };
  },
  methods: {
    onSplineLoaded(spline) {
      this.obj = spline.findObjectById('8E8C2DDD-18B6-4C54-861D-7ED2519DE20E');
    },
    triggerAnimation({ target }) {
      this.obj.emitEvent('mouseHover');
    },
  },
};
</script>

You can find a list of all of the Spline Events you can pass to the emitEvent function in the Spline Events section.

API

Spline Component Props

These are all the props you can pass to the <Spline /> component.

NameTypeDescription
scenestringScene file
id?stringCanvas id
auto-render?booleanAuto render canvas

Spline Component events

These are all the props you can pass to the <Spline /> component.

NameTypeDescription
@spline-loaded(spline: Application) => voidGets called once the scene has loaded. The spline parameter is an instance of the Spline Application
@spline-wheel(e: SplineEvent) => voidGets called on the wheel event on the canvas
@spline-mousedown(e: SplineEvent) => voidGets called once a Spline Mouse Down event is fired
@spline-mousehover(e: SplineEvent) => voidGets called once a Spline Mouse Hover event is fired
@spline-mouseup(e: SplineEvent) => voidGets called once a Spline Mouse Up event is fired
@spline-keydown(e: SplineEvent) => voidGets called once a Spline Key Down event is fired
@spline-keyup(e: SplineEvent) => voidGets called once a Spline Key Up event is fired
@spline-start(e: SplineEvent) => voidGets called once a Spline Start event is fired
@spline-lookat(e: SplineEvent) => voidGets called once a Spline Look At event is fired
@spline-follow(e: SplineEvent) => voidGets called once a Spline Mouse Up event is fired

Spline App Methods

The object exposed as a first argument of the onLoad function, is a Spline Application. You can call all these different methods on it.

NameTypeDescription
emitEvent(eventName: SplineEventName, uuid: string) => voidTriggers a Spline event associated to an object with provided uuid in reverse order. Starts from first state to last state.
emitEventReverse(eventName: SplineEventName, uuid: string) => voidTriggers a Spline event associated to an object with provided uuid in reverse order. Starts from last state to first state.
findObjectById(uuid: string) => SPEObjectSearches through scene's children and returns the object with that uuid.
findObjectByName(name: string) => SPEObjectSearches through scene's children and returns the first object with that name
setZoom(zoom: number) => voidSets the initial zoom of the scene.

Spline Events

These are all the Spline event types that you can pass to the emitEvent or emitEventReverse function.

NameDescription
mouseDownRefers to the Spline Mouse Down event type
mouseHoverRefers to the Spline Mouse Hover event type
mouseUpRefers to the Spline Mouse Up event type
keyDownRefers to the Spline Key Down event type
keyUpRefers to the Spline Key Up event type
startRefers to the Spline Start event type
lookAtRefers to the Spline Look At event type
followRefers to the Spline Mouse Up event type

Contributing

We use yarn, install the dependencies like this:

yarn

Development

Serve the example folder at localhost:3000

yarn dev

Build Library

yarn build

Publish on npm

yarn deploy

FAQs

Package last updated on 13 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc