Important: The Code API allows your native interface to control properties in the Spline scene, and vice versa. However, itโs important to note that this is different from the Real-time APIs feature. For information about APIs used for server communication and integrating your scenes with other apps, please refer to the specific API documentation: Real-time API
Key capabilities
- Event Listeners: React to real-time events within your 3D scenes.
- Adjust Properties: Dynamically update position, scale, rotation, and more.
- Trigger Transitions: Create transitions and animations based on events.
- Adjust variables: Retrieve and update variables in a Spline scene.
Usage
Getting started
First, make sure youโre familiar with Native 3D Embeds for Android and you can already embed 3D content in your Android projects.loadResource or loadUrl callback which is invoked once the scene has finished loading:
Info: The
SplineView loads its content asynchronously, so API calls may return null or do nothing if the scene hasnโt finished loading. Always use the onComplete callback to ensure the scene is ready before accessing the API.Read and modify Spline objects
You can query any Spline object in the scene viafindObjectByName() or findObjectById() functions. Then, you can read or write any of its properties.
(You can get the ID of the object from the right-click context panel on the object in the Spline Editor).
null if an object with the specified name was not found.
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 view. You can find a list of all of the Spline Event listeners in the API 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 theemitEvent() function, passing the event type and the name or ID of your object.
(You can get the ID of the object from the right-click context panel on the object).
emitEvent() function in the Spline Events section.
Handling multiple views
If you have severalSplineViewโs in your Android view hierarchy, each view is independent and has its own API. Simply keep a reference to each view to control them separately.
Updating scene variables
If you set up variables in your Spline scene from the editor, you can change them from code after the scene is loaded.Note: If in the 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.
Playback control
You can pause and resume the scene rendering and animations:Customizing the scene
You can customize certain scene properties like zoom level and background color:API
SplineView Methods
You can call all these different methods on theSplineView instance.
| Name | Description |
|---|---|
| loadResource(id, onComplete) | Load a Spline scene from a raw resource file. The callback is invoked when loading is complete. |
| loadUrl(url, onComplete) | Load a Spline scene from a URL. The callback is invoked when loading is complete. |
| addEventListener(event, callback) | Add an event listener for Spline events. |
| removeEventListener(event, callback) | Remove a previously added event listener. |
| emitEvent(event, nameOrUuid) | Triggers a Spline event associated to an object with the provided name or UUID. Starts from the first state to the last state. |
| emitEventReverse(event, nameOrUuid) | Triggers a Spline event associated to an object with the provided name or UUID in reverse order. Starts from the last state to the first state. |
| findObjectById(uuid) | Searches through the sceneโs children and returns the object with that UUID. |
| findObjectByName(name) | Searches through the sceneโs children and returns the first object with that name. |
| setZoom(zoom) | Sets the camera zoom, expects a number value > 0 where 1 is base zoom. |
| setNumberVariable(name, value) | Updates value for passed number variable by name. |
| getNumberVariable(name) | Get current value for a specific number variable from its name. |
| setBooleanVariable(name, value) | Updates value for passed boolean variable by name. |
| getBooleanVariable(name) | Get current value for a specific boolean variable from its name. |
| setStringVariable(name, value) | Updates value for passed string variable by name. |
| getStringVariable(name) | Get current value for a specific string variable from its name. |
| hasVariable(name) | Check if a variable with the given name exists in the scene. |
| stop() | Stop/Pause all rendering, controls and events. |
| play() | Play/Resume rendering, controls and events. |
| setBackgroundColor(color) | Manually sets the scene/canvas background color with a Color value. |
SplineObject Properties and Methods
After retrieving a Spline Object withfindObjectById() or findObjectByName(), there are a variety of properties and methods you can use.
| Name | Description |
|---|---|
| uuid | Gets object UUID. |
| name | Gets / Sets object name. |
| visible | Gets / Sets object visibility. |
| position | Gets / Sets object position as Vector3. |
| rotation | Gets / Sets object rotation as Vector3. |
| scale | Gets / Sets object scale as Vector3. |
| intensity | Only for light objects. Gets / Sets the light intensity. |
| emitEvent(event) | Force trigger an event defined in Spline Editor. |
| emitEventReverse(event) | Force trigger an event defined in Spline Editor in reverse. |
Spline Events
These are all the Spline event types that you can pass to theaddEventListener(), emitEvent() and emitEventReverse() functions.
| Name | Description |
|---|---|
| SplineEventName.mouseUp | Refers to the Spline Mouse Up event type |
| SplineEventName.mouseDown | Refers to the Spline Mouse Down event type |
| SplineEventName.mousePress | Refers to the Spline Mouse Press event type |
| SplineEventName.mouseHover | Refers to the Spline Mouse Hover event type |
| SplineEventName.keyUp | Refers to the Spline Key Up event type |
| SplineEventName.keyDown | Refers to the Spline Key Down event type |
| SplineEventName.keyPress | Refers to the Spline Key Press event type |
| SplineEventName.start | Refers to the Spline Start event type |
| SplineEventName.lookAt | Refers to the Spline Look At event type |
| SplineEventName.follow | Refers to the Spline Follow event type |

