@splinetool/runtime 1.10.68 → 1.10.70

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/README.md CHANGED
@@ -215,33 +215,55 @@ transition.reset()
215
215
  transition.seek(1000)
216
216
  ```
217
217
 
218
+ ### Swapping Geometries
219
+
220
+ It's possible to replace a geometry using the `app.swapGeometry(objectName, 'path/to/new.splinegeometry)` function. You first need to generate a `.splinegeometry` file from the editor by right clicking on a mesh object and selecting `Export Geometry`. This is useful if you have optional geometries / objects in your scene that you don't want to load at first. This will help make initial `.spline` file smaller and faster to load. First parameter can either object name or object UUID. Second parameter can either be the url to a `.splinegeometry` file or a Uint8Array wrapping the content of a `.splinegeometry` file.
221
+
222
+ ```js
223
+ app.load('scene.spline').then(() => {
224
+ catButton.addEventListener('click', async () => {
225
+ // By default second parameter is an url to a .splinegeometry file
226
+ await app.swapGeometry('Animal', 'url/to/cat.splinegeometry');
227
+ });
228
+
229
+ dogButton.addEventListener('click', async () => {
230
+ // It's also possible to load the .splinegeometry file yourself if you want to manage some kind of cache or reuse one geometry for multiple objects / file
231
+ const res = await fetch('url/to/dog.splinegeometry');
232
+ const buffer = await res.arrayBuffer();
233
+ const dogGeometry = new Uint8Array(buffer);
234
+ await app.swapGeometry('Animal', dogGeometry);
235
+ });
236
+ });
237
+ ```
238
+
218
239
  ## API
219
240
 
220
241
  ### Spline Application Methods
221
242
 
222
243
  You can call all these different methods on the Spline `Application` instance.
223
244
 
224
- | Name | Type | Description |
225
- | --------------------- | -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
226
- | `addEventListener` | `(eventName: SplineEventName, cb: (e: SplineEvent) => void) => void` | Add an event listener for Spline events |
227
- | `removeEventListener` | `(eventName: SplineEventName, cb: (e: SplineEvent) => void) => void` | Remove an event listener for Spline events |
228
- | `emitEvent` | `(eventName: SplineEventName, nameOrUuid: string) => void` | Triggers a Spline event associated to an object with provided name or uuid in reverse order. Starts from first state to last state. |
229
- | `emitEventReverse` | `(eventName: SplineEventName, nameOrUuid: string) => void` | Triggers a Spline event associated to an object with provided name or uuid in reverse order. Starts from last state to first state. |
230
- | `findObjectById` | `(uuid: string) => SPEObject` | Searches through scene's children and returns the object with that uuid. |
231
- | `findObjectByName` | `(name: string) => SPEObject` | Searches through scene's children and returns the first object with that name. |
232
- | `setZoom` | `(zoom: number) => void` | Sets the camera zoom, expects a number value > 0 where 1 is base zoom. |
233
- | `setSize` | `(width: number, height: number) => void` | Sets the size of the application and canvas. When called, Spline will stop automatic size updates. |
234
- | `setVariables` | `(variables: Record<string, string \| number \| boolean>) => void` | Updates values for passed variables by name. |
235
- | `setVariable` | `(name: string, value: string \| number \| boolean) => void` | Updates value for passed variable by name. |
236
- | `getVariables` | `() => Record<string, string \| number \| boolean>` | Returns a record mapping variable names to their respective current values. |
237
- | `getVariable` | `(name: string, value: string \| number \| boolean) => void` | Get current value for a specific variable from its name |
238
- | `stop` | `() => void` | Stop/Pause all rendering controls and events. |
239
- | `play` | `() => void` | Play/Resume rendering, controls and events. |
240
- | `pauseGameControls`. | `() => void` | Stop/Pause Game Controls if any. |
241
- | `resumeGameControls`. | `() => void` | Play/Resume Game Controls if any. |
242
- | `setBackgroundColor` | `(color:string) => void` | Manually sets the scene/canvas background color with a css color value. |
243
- | `getAllObjects` | `() => SPEObject[]` | Returns a flat list of all the objects present in the scene. |
244
- | `getSplineEvents` | `() => Object[]` | Returns an array listing all the Spline events used in the scene. |
245
+ | Name | Type | Description |
246
+ | --------------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
247
+ | `addEventListener` | `(eventName: SplineEventName, cb: (e: SplineEvent) => void) => void` | Add an event listener for Spline events. |
248
+ | `removeEventListener` | `(eventName: SplineEventName, cb: (e: SplineEvent) => void) => void` | Remove an event listener for Spline events. |
249
+ | `emitEvent` | `(eventName: SplineEventName, nameOrUuid: string) => void` | Triggers a Spline event associated to an object with provided name or uuid in reverse order. Starts from first state to last state. |
250
+ | `emitEventReverse` | `(eventName: SplineEventName, nameOrUuid: string) => void` | Triggers a Spline event associated to an object with provided name or uuid in reverse order. Starts from last state to first state. |
251
+ | `findObjectById` | `(uuid: string) => SPEObject` | Searches through scene's children and returns the object with that uuid. |
252
+ | `findObjectByName` | `(name: string) => SPEObject` | Searches through scene's children and returns the first object with that name. |
253
+ | `setZoom` | `(zoom: number) => void` | Sets the camera zoom, expects a number value > 0 where 1 is base zoom. |
254
+ | `setSize` | `(width: number, height: number) => void` | Sets the size of the application and canvas. When called, Spline will stop automatic size updates. |
255
+ | `setVariables` | `(variables: Record<string, string \| number \| boolean>) => void` | Updates values for passed variables by name. |
256
+ | `setVariable` | `(name: string, value: string \| number \| boolean) => void` | Updates value for passed variable by name. |
257
+ | `getVariables` | `() => Record<string, string \| number \| boolean>` | Returns a record mapping variable names to their respective current values. |
258
+ | `getVariable` | `(name: string, value: string \| number \| boolean) => void` | Get current value for a specific variable from its name. |
259
+ | `stop` | `() => void` | Stop/Pause all rendering controls and events. |
260
+ | `play` | `() => void` | Play/Resume rendering, controls and events. |
261
+ | `pauseGameControls` | `() => void` | Stop/Pause Game Controls if any. |
262
+ | `resumeGameControls` | `() => void` | Play/Resume Game Controls if any. |
263
+ | `setBackgroundColor` | `(color:string) => void` | Manually sets the scene/canvas background color with a css color value. |
264
+ | `getAllObjects` | `() => SPEObject[]` | Returns a flat list of all the objects present in the scene. |
265
+ | `getSplineEvents` | `() => Object[]` | Returns an array listing all the Spline events used in the scene. |
266
+ | `swapGeometry` | `(target: string, content: string \| Uint8Array) => Promise<void>` | Replace the geometry from target if it is a mesh. Target parameter can be object name or uuid. Content parameter is url to `.splinegeometry` file. |
245
267
 
246
268
  ### Spline Objects Methods and Properties
247
269
 
@@ -280,4 +302,4 @@ These are all the Spline event types that you can pass to the `addEventListener`
280
302
  | `follow` | Refers to the Spline `Mouse Up` event type |
281
303
  | `scroll` | Refers to the Spline `Scroll` event type |
282
304
 
283
- © 2024 Spline, Inc.
305
+ © 2025 Spline, Inc.