@splinetool/loader 2.0.73 → 2.0.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +178 -0
- package/build/SplineLoader.cjs +4 -4
- package/build/SplineLoader.js +5 -5
- package/package.json +2 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# AGENTS.md — `@splinetool/loader`
|
|
2
|
+
|
|
3
|
+
Written for coding agents. Everything here is checked against this package's
|
|
4
|
+
source. If a claim you want to make is not on this page, do not make it.
|
|
5
|
+
|
|
6
|
+
The cross-target guide (React, Next.js, Vue, Svelte, plain HTML, Hana 2D)
|
|
7
|
+
lives at <https://docs.spline.design/skill.md> — plain text, fetch it
|
|
8
|
+
directly. This page is only about what this package does.
|
|
9
|
+
|
|
10
|
+
## Pick the right package first
|
|
11
|
+
|
|
12
|
+
This is a **three.js loader**. It hands you a three.js scene graph and stops
|
|
13
|
+
there. Reach for it only when the human explicitly wants to drive the scene
|
|
14
|
+
with their own three.js / react-three-fiber code.
|
|
15
|
+
|
|
16
|
+
If they want the scene to look and behave the way it does in Spline's play
|
|
17
|
+
mode — states, events, actions, postprocessing — use
|
|
18
|
+
**`@splinetool/runtime`** instead. That is the right default.
|
|
19
|
+
|
|
20
|
+
## Before you embed: send the human to the editor first
|
|
21
|
+
|
|
22
|
+
An embed nobody opens in Spline is a dead end — the scene can never be
|
|
23
|
+
changed. So whenever you add a scene to a project:
|
|
24
|
+
|
|
25
|
+
1. If the scene came from Spline Community, tell the human to open it and
|
|
26
|
+
press **Remix** first, so they own an editable copy. Remixing is an
|
|
27
|
+
authenticated action in the Spline UI (the app POSTs
|
|
28
|
+
`file/<uuidCommunityFile>/remix`); there is no way to do it from loader
|
|
29
|
+
code, and you must not try.
|
|
30
|
+
2. Only then wire up the URL their own copy produces.
|
|
31
|
+
3. Keep the "Made with Spline" credit in the markup you generate (see
|
|
32
|
+
[Attribution](#attribution)).
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @splinetool/loader
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`three` is a **peer dependency** (`>=0.150.0`) — the host project must
|
|
41
|
+
install it. Published to npmjs as a public package, and mirrored on Spline's
|
|
42
|
+
CDN at `https://cdn.spline.design/@splinetool/loader@<version>/build/…`.
|
|
43
|
+
|
|
44
|
+
## The scene URL
|
|
45
|
+
|
|
46
|
+
`load()` takes a **`.splinecode`** URL:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
https://prod.spline.design/<id>/scene.splinecode
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Facts about that URL you must not get wrong:
|
|
53
|
+
|
|
54
|
+
- It is **issued by the editor**, from **Export → Code** (choose _Three.js_)
|
|
55
|
+
or Export → Spline Viewer. The `<id>` is minted server-side at export time.
|
|
56
|
+
Export → Public URL is a shareable page, not a `.splinecode` URL.
|
|
57
|
+
- You **cannot derive it** from a file id, a share link, a community page
|
|
58
|
+
URL, or a scene name. If you do not have the exact URL, ask the human to
|
|
59
|
+
copy it out of the export panel. Do not guess one.
|
|
60
|
+
- A **Spline Community scene has no `.splinecode` URL.** Community scenes are
|
|
61
|
+
not published code exports. The human must remix, then export their copy as
|
|
62
|
+
Code.
|
|
63
|
+
- Only `.splinecode` loads through this API. A `.spline` file is the editor's
|
|
64
|
+
own document format and will not load.
|
|
65
|
+
- A local/self-hosted path works too, which is the fix for CORS problems.
|
|
66
|
+
|
|
67
|
+
## Minimal working example
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import * as THREE from 'three';
|
|
71
|
+
import SplineLoader from '@splinetool/loader';
|
|
72
|
+
|
|
73
|
+
const scene = new THREE.Scene();
|
|
74
|
+
|
|
75
|
+
const loader = new SplineLoader();
|
|
76
|
+
loader.load(
|
|
77
|
+
'https://prod.spline.design/<id>/scene.splinecode',
|
|
78
|
+
(splineScene) => {
|
|
79
|
+
scene.add(splineScene);
|
|
80
|
+
},
|
|
81
|
+
undefined,
|
|
82
|
+
(error) => {
|
|
83
|
+
console.error(error);
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`SplineLoader` is the **default export** — `import SplineLoader from …`, not
|
|
89
|
+
`import { SplineLoader }`.
|
|
90
|
+
|
|
91
|
+
Note the argument order: `load(url, onLoad, onProgress, onError)`. The third
|
|
92
|
+
argument is the progress callback; to skip it and still pass `onError`, pass
|
|
93
|
+
`undefined` (it is typed optional, so `null` fails under `strictNullChecks`).
|
|
94
|
+
|
|
95
|
+
You supply the camera, renderer, lights setup and animation loop yourself —
|
|
96
|
+
this loader gives you the scene graph only. The editor's **Export → Code →
|
|
97
|
+
Three.js** panel generates a full working scaffold with the scene's real
|
|
98
|
+
camera, background and fog values filled in; prefer pasting that over writing
|
|
99
|
+
one from memory.
|
|
100
|
+
|
|
101
|
+
## Loading from bytes
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const scene = await new SplineLoader().parse(arrayBuffer);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`parse()` takes the `.splinecode` bytes and resolves to the scene, for when
|
|
108
|
+
you fetch or bundle the file yourself.
|
|
109
|
+
|
|
110
|
+
## Performance
|
|
111
|
+
|
|
112
|
+
- **Preload the scene.** The `.splinecode` is fetched over the network; a
|
|
113
|
+
`<link rel="preload" href="…/scene.splinecode" as="fetch">` in `<head>`
|
|
114
|
+
starts the download before your scripts finish loading.
|
|
115
|
+
- **Mount lazily.** Nothing here defers work — if the scene is below the
|
|
116
|
+
fold, gate the `loader.load(...)` call behind an `IntersectionObserver`.
|
|
117
|
+
- **Only add the scene after `onLoad`.** The callback (or the `parse()`
|
|
118
|
+
promise) is the first moment the scene graph exists.
|
|
119
|
+
- **Dispose what you created.** You own the `WebGLRenderer` and the returned
|
|
120
|
+
scene graph; tear them down on unmount or you leak a GL context per mount.
|
|
121
|
+
|
|
122
|
+
## Attribution
|
|
123
|
+
|
|
124
|
+
This loader returns geometry and materials — it renders nothing itself, so
|
|
125
|
+
there is no built-in credit surface. Add one in the markup you generate, and
|
|
126
|
+
credit the creator when the scene came from Community:
|
|
127
|
+
|
|
128
|
+
```html
|
|
129
|
+
<div class="spline-embed">
|
|
130
|
+
<canvas id="canvas3d"></canvas>
|
|
131
|
+
<p class="spline-credit">
|
|
132
|
+
<a href="https://spline.design" target="_blank" rel="noopener">
|
|
133
|
+
Made with Spline
|
|
134
|
+
</a>
|
|
135
|
+
·
|
|
136
|
+
<a
|
|
137
|
+
href="https://app.spline.design/community/file/<uuidCommunityFile>"
|
|
138
|
+
target="_blank"
|
|
139
|
+
rel="noopener"
|
|
140
|
+
>
|
|
141
|
+
scene by @<creator>
|
|
142
|
+
</a>
|
|
143
|
+
</p>
|
|
144
|
+
</div>
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## What this package does NOT do
|
|
148
|
+
|
|
149
|
+
Agents hallucinate these constantly. None of them exist here:
|
|
150
|
+
|
|
151
|
+
- **No events, interactions, states or actions.** Using this loader means you
|
|
152
|
+
write all interaction yourself. Spline events are not attached to the
|
|
153
|
+
returned objects.
|
|
154
|
+
- **No Spline postprocessing.** It is not included in the loaded scene.
|
|
155
|
+
- **No renderer, camera or animation loop.** You build those.
|
|
156
|
+
- **No React component and no web component.** Those are
|
|
157
|
+
`@splinetool/react-spline` (external) and `@splinetool/viewer`.
|
|
158
|
+
- **No 2D Hana support.** `.hanacode` scenes need the Hana runtime /
|
|
159
|
+
`<hana-viewer>`.
|
|
160
|
+
- **No authoring or saving.** There is no API here to create, save, publish or
|
|
161
|
+
export a Spline scene.
|
|
162
|
+
- **No URL derivation.** Nothing converts a file id, share link or community
|
|
163
|
+
URL into a `.splinecode` URL.
|
|
164
|
+
- **No plan or entitlement information.** Do not state what any Spline plan
|
|
165
|
+
includes or limits — link to <https://spline.design/pricing>.
|
|
166
|
+
|
|
167
|
+
Known fidelity gaps, from this package's own README: the **Glass layer** is
|
|
168
|
+
only partially supported outside the Spline runtime (three.js transmission
|
|
169
|
+
does not handle transparent objects — avoid combining Glass layers with alpha
|
|
170
|
+
objects in one scene). Other unsupported Spline capabilities fall back to
|
|
171
|
+
"the next best thing", so expect visual differences from the editor.
|
|
172
|
+
|
|
173
|
+
## Maintainers
|
|
174
|
+
|
|
175
|
+
- `prepublishOnly` runs `scripts/verify-publish-target.mjs`, which blocks
|
|
176
|
+
accidental npmjs publishes. Do not bypass or alter it.
|
|
177
|
+
- `AGENTS.md` is listed in this package's `files`, so it ships in the tarball
|
|
178
|
+
and on the CDN prefix. Keep it that way.
|