npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

threlte-spline

v0.5.1

Published

Helper function to load Spline scenes into threlte

Downloads

101

Readme

threlte-spline

threlte-spline is a simple utility that lets you use your Spline scene with Threlte, via the Spline react-three-fiber code export.

This library is heavily inspired by r3f-spline

While this library is written to be used in Threlte, it can be used in applications that aren't powered by Threlte. That's because this library simply loads, and returns the Spline scene as Three.js objects.

Install

yarn add threlte-spline @splinetool/loader

or

npm install threlte-spline @splinetool/loader

or

pnpm add threlte-spline @splinetool/loader

@types/three is required for Typescript support

Please be aware that this library is simply an extension of @splinetool/loader, and is intended to be used with @threlte/core. Both of these libraries were built with a specific version of three in mind. So please be mindful that your installed version of three may need to be very specific in order for these libraries to work harmoniously together.

A common error that you may encounter if your version of three is not compatible with your version of @splinetool/loader is: Uncaught TypeError: Cannot read property 'x' of undefined

Typically, you can use the latest version of @splinetool/loader that is available at the time of exporting the Spline scene, you can then find roughly the version of three required here. These are scraped from @splinetool/loader package.json files.

Usage

<script lang="ts">
  import { Canvas, T, OrbitControls } from '@threlte/core';
  import { loadSpline } from 'threlte-spline';

  let scene;
  loadSpline('https://prod.spline.design/HwAUoybfBaBCLzwO/scene.spline').then((_scene) => {
    scene = _scene;
  });
</script>

{#if scene}
  <Canvas>
    <T.PerspectiveCamera
      makeDefault
      position={scene.nodes['Camera 1'].position}
      fov={scene.nodes['Camera 1'].fov}
      zoom={scene.nodes['Camera 1'].zoom}
    >
      <OrbitControls />
    </T.PerspectiveCamera>

    <T.Group>
      <T.Mesh
        name="Rectangle"
        geometry={scene.nodes.Rectangle.geometry}
        material={scene.materials['Rectangle Material']}
      />
    </T.Group>
  </Canvas>
{/if}

Typescript

Type information should be fairly complete as this package extends @types/three, however there may be certain properties which are missing. Feel free to contribute any missing types if you find any.

In the interim, you can extend the types by doing the following

<script lang="ts">
  import { Canvas, T, OrbitControls } from '@threlte/core';
  import { loadSpline } from 'threlte-spline';

  type MissingProperties = {
    prop1: number;
  }
  let scene: ObjectMap<MissingProperties>;
  loadSpline<MissingProperties>('https://prod.spline.design/HwAUoybfBaBCLzwO/scene.spline').then((_scene) => {
    scene = _scene;
  });
</script>

{#if scene}
  <Canvas>
    ...
  </Canvas>
{/if}

This will add the missing props to SceneNode

types-plugin

Register this Vite plugin to fetch more accurate types for your Spline scene

e.g.

import { threlteSplineTypesPlugin } from 'threlte-spline/dist/types-plugin';

const viteConfig = {
  ...,
  plugins: [..., threlteSplineTypesPlugin()],
};

Without plugin

scene.nodes
//      ^= { [x: string]: SceneNode }

With plugin

scene.nodes
//      ^= { rectangle: SceneNode, camera: SceneNode }

Examples