@splinetool/runtime 0.9.461 → 0.9.462
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 +34 -6
- package/build/runtime.cjs +74 -74
- package/build/runtime.js +74 -74
- package/package.json +1 -1
- package/runtime.d.ts +28 -2
package/README.md
CHANGED
|
@@ -138,14 +138,40 @@ You might want to start the loading of `.splinecode` file before your code is lo
|
|
|
138
138
|
|
|
139
139
|
```js
|
|
140
140
|
/*
|
|
141
|
-
When loading the Application, use the
|
|
141
|
+
When loading the Application, use the third
|
|
142
142
|
param of the load function to make sure the browser
|
|
143
143
|
will use the preloaded file and not make another request
|
|
144
144
|
*/
|
|
145
|
-
spline.load(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
spline.load(
|
|
146
|
+
'https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode',
|
|
147
|
+
undefined,
|
|
148
|
+
{
|
|
149
|
+
credentials: 'include',
|
|
150
|
+
mode: 'no-cors',
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Updating scene variables
|
|
156
|
+
|
|
157
|
+
If you setup variables in your Spline scene from the editor, you can change them from code either while loading the scene, of after it's loaded.
|
|
158
|
+
Note that if in Spline editor you have multiple variables with the same name, only the first one will be updated, so make sure to give unique names to the variables you want to update.
|
|
159
|
+
Also note that the values you pass to your variables will be casted into their original type (number, boolean or string).
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
const spline = new Application(canvas);
|
|
163
|
+
|
|
164
|
+
// Create an object describing the variables you want to update during load
|
|
165
|
+
const myVariables = { myName: 'John', mySize: 350 };
|
|
166
|
+
|
|
167
|
+
// And pass them as second parameter for the load function
|
|
168
|
+
spline.load('.../scene.splinecode', myVariables);
|
|
169
|
+
|
|
170
|
+
// Later you can update your variables again
|
|
171
|
+
spline.setVariables({ myName: 'Paul', mySize: 100 });
|
|
172
|
+
|
|
173
|
+
// Or change only one variable
|
|
174
|
+
spline.setVariable('myName', 'Ringo');
|
|
149
175
|
```
|
|
150
176
|
|
|
151
177
|
## API
|
|
@@ -155,7 +181,7 @@ spline.load('https://prod.spline.design/6Wq1Q7YGyM-iab9i/scene.splinecode', {
|
|
|
155
181
|
You can call all these different methods on the Spline `Application` instance.
|
|
156
182
|
|
|
157
183
|
| Name | Type | Description |
|
|
158
|
-
| --------------------- | -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
184
|
+
| --------------------- | -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------------------------------------------- |
|
|
159
185
|
| `addEventListener` | `(eventName: SplineEventName, cb: (e: SplineEvent) => void) => void` | Add an event listener for Spline events |
|
|
160
186
|
| `removeEventListener` | `(eventName: SplineEventName, cb: (e: SplineEvent) => void) => void` | Remove an event listener for Spline events |
|
|
161
187
|
| `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. |
|
|
@@ -164,6 +190,8 @@ You can call all these different methods on the Spline `Application` instance.
|
|
|
164
190
|
| `findObjectByName` | `(name: string) => SPEObject` | Searches through scene's children and returns the first object with that name. |
|
|
165
191
|
| `setZoom` | `(zoom: number) => void` | Sets the initial zoom of the scene. |
|
|
166
192
|
| `setSize` | `(width: number, height:number) => void` | Sets the size of the application and canvas. When called, Spline will stop automatic size updates. |
|
|
193
|
+
| `setVariables` | `(variables:Record<string, string | number | boolean>) => void` | Updates values for passed variables by name |
|
|
194
|
+
| `setVariable` | `(name:string, value: string | number | boolean) => void` | Updates value for passed variable by name |
|
|
167
195
|
|
|
168
196
|
### Spline Events
|
|
169
197
|
|