* [ts] poc wegl overlay * [ts] poc wegl overlay * canvas4 * overlay 4 * overlay * overlay fix scroll cut * Zoom fix - WIP horizontal scroll bug see comment at line 495 * Scroll should be resolved * web component * Loading * mostly work - when overflow top/bottom...are > 0, widgets slightly jump on up and down fast scroll. * Renamed * Add OffScreenUpdateBehaviour * Fixed loading spinner example * Translate is done each frame through requestAnimationFrame. * Added clip. * Removed SpineCanvasApp dependency. * Removed code duplication for clipping into div * Refactor drag logic. Drag works with clip too. * WIP - Doc before refactor * WIP - Refactor + animation and skin attribute change will reinit the widget * Modified export script to copy chibi * Fix zoom bug due to screen size remaining the same at different zoom level. * Removed useless changes on other classes. * Removed custom LoadingSpinnerWindget class. Added a new specific method in LoadingSpinner. * Fix 1 pixel misalignment in non clip mode. * Cleaned webcomponent example. * Made span fps display configurable. * Made some changes to make it work on old browsers. * Manage lifecycle for Input and SpineWebComponentOverlay. Missing SpineWebComponentWidget. * Managed lifecycle for SpineWebComponentWidget. * Fixed input remove listener. Run tsfmt. * Fixed infinite requestAnimationFrame calls. * Fix x-axis and y-axis not working in clip mode. * Fix widget using overlay before overlay webcomponent is fully upgraded. * Restore resize observer since the window resize event does not fire on body resize, but on window resize. It's supported by 93% of the browsers. * Add padding attributes/properties. * Exposed parameters to set bounds. Deeply changed how bounds work, especially for the fact that they are not auto recalculated anymore if the animation is changed (unless autoRecalculateBounds is set to true). * Changes to make the widget more dynamic while changing attributes. See now webcomponent-gui.html. * Initial support of spine-widget into scrollable containers, and overlay-id for multiple spine-overlay. working * WIP - Added/Changed: - overlay loading: now overlay is moved as the last element from where it is inserted to avoid widgets covered by backgrounds of html elements after it. - default overlayId - widget position in overlay coordinates (worldX, worldY) (experimental) - cursor position on widget world (cursorWorldX, cursorWorldY) (experimental) - jsonSkeletonKey: allow to load a specific skeleton in json containing multiple skeletons - onViewportManualStart: start the widget when in manual-start and enters the viewport the first time - overlayAssignedPromise: a promise that resolves when the overlay is assigned to the widget. Reads the comment on it - appendTo: to append the widget created using js and wait for the overlayAssignedPromise to resolve - changed how loadingPromise works - added cursorCanvasX, cursorCanvasY, cursorWorldX, cursorWorldY to overlay (experimental) * Docs and minor fixes. * Fixed example. * Allow multiple widgets for the same HTMLElement * Simplified clip to div by using scissor rather than changing viewport+camera. In this way we can treat coordinates equally for cliped and not clipped widgets! * Simplified drag calculation and drag debug removing an additional div. * WIP - Add interactivity events. isdraggable is currently broken. * Add interactivity events. * Fixed a bug where an infinite loop occurred in Firefox when compareDocumentPosition results in DOCUMENT_POSITION_DISCONNECTED. In both Chrome and Firefox, when an element is inside a webcomponent the comparison results in DOCUMENT_POSITION_DISCONNECTED. But in Firefox the element result in DOCUMENT_POSITION_FOLLOWING too, leading to an infinite loop. * Fix physicsTranslate y opposite direction while dragging. * Add followSlot method * Add animations, animations-bound and default-mix attributes. * Original event is passed to bounds and slot callbacks. * Made overlay canvas size consistent across different browsers. Base size is not anymore the screen size due to browser limitations, but the window size. This will trigger additional canvas resize on window resize. * Reduce DPI if canvas is too big to avoid page crash - this happen on webpage on mobile with high dpi and missing meta viewport tag with width=device-width. * Pma properties on atlas is used to detect pma textures. * Add rawData attribute to pass s stringified JSON object for inline base64 assets. * format * Prevent useless resize. * Prevent error on disconnected callback * Update tutorial. * Fixed multiple click events on mobile touches. Add team example. * Fixed slot interaction issue. * Resize overlay when follow slot element is added. * Add interactive widget example. * Temporarily add windmill only manually to webgl assets * Move getBounding in scrollable case. * formatter * Fixed overlay disconnectedCallback. * Overlay should load not for DOMContentLoaded event only if document has already complete loading. * Overlay parent bounding box determined only if necessary. * Overlay needs to consider border if it's scrollable. * Fixed issues with slot events on mobile. * food app and cleanup * Make overlayAssignedPromise private. * Change scrollable to appendedToBody, make it private and determine it at dom connect. * scrollable-tweak-off changed to no-auto-parent-transform. * Update bounds and slot interaction method names. * getHTMLElementReference to getHostElement. * recalculateBounds and autoRecalculateBounds to calculateBounds and autoCalculateBounds. * dpi to dpr and transform DPR to DevicePixelRatio when needed. Add @internal tag to internal fields. * Properties rename. * Better comments and variable names for canvas resize related stuff. * callbacks renamed consistently. * for each to for of. * Update other names. * onScreenManualStart to startWhenVisible. startWhenVisible set manualStart to true. * fix return to continue in for of. * Refcounter for asset manager and gl resources disposal for webcomponent. * Fixes to asset manager ref counter. * Add dispose example. * Fix overlay init not completed in some scenario. DOMContentLoaded is invoked only when document.readyState is interactive. * Cleaned up examples. * spinner to no-spinner. * Move webcomponent to spine-widget folder. * start won't reset bounds. * Remove test file. * Moved team example in its own page. * Improved tutorial explanations. * Moved some examples in their own pages. * Formatter. * Widgets dragged can be dragged even if host is offscreen. * General refactor. spine-widget to spine-skeleton. * spine-widget package renamed to spine-webcomponents. * Moved assets to a single assets folder. * Run formatter. * Add beta notice. * Changed widget occurrences to webcomponents.
9.5 KiB
spine-ts
The spine-ts runtime provides functionality to load and manipulate Spine skeletal animation data using TypeScript and JavaScript. spine-ts is split up into multiple modules:
spine-core/, the core classes to load and process Spine skeletons.spine-webgl/, a self-contained WebGL backend, built on the core classes.spine-canvas/, a self-contained Canvas backend, built on the core classes.spine-canvaskit/, a self-contained CanvasKit backend, built on the core classes for CanvasKit, supporting both NodeJS for headless rendering, and browsers.spine-player/, a self-contained player to easily display Spine animations on your website, built on the core classes and WebGL backend.spine-webcomponents/, web components to easily display Spine animations on your website, built on the core classes and WebGL backend.spine-threejs/, a THREE.JS backend, built on the core classes.spine-phaser-v3/, a Phaser v3 backend, built on the core classes.spine-phaser-v4/, a Phaser v4 backend, built on the core classes.spine-pixi-v7/, a PixiJS v7 backend, built on the core classes.spine-pixi-v8/, a PixiJS v8 backend, built on the core classes.
In most cases, the spine-player module is best suited for your needs. Please refer to the Spine Web Player documentation for more information.
For documentation of the core API in spine-core, please refer to our Spine Runtimes Guide.
For documentation of spine-phaser-v3 and spine-phaser-v4, please refer to our spine-phaser Guide.
For documentation of spine-pixi-v7 and spine-pixi-v8, please refer to our spine-pixi Guide.
For documentation of spine-canvaskit, please refer to our spine-canvaskit Guide.
For module specific APIs in spine-canvas, spine-webgl, and spine-threejs, please refer to the Examples in the respecitve spine-<modulename>/example folder. For spine-webgl specifically, we have provided additional demos, which you can also view online.
Licensing
You are welcome to evaluate the Spine Runtimes and the examples we provide in this repository free of charge.
You can integrate the Spine Runtimes into your software free of charge, but users of your software must have their own Spine license. Please make your users aware of this requirement! This option is often chosen by those making development tools, such as an SDK, game toolkit, or software library.
In order to distribute your software containing the Spine Runtimes to others that don't have a Spine license, you need a Spine license at the time of integration. Then you can distribute your software containing the Spine Runtimes however you like, provided others don't modify it or use it to create new software. If others want to do that, they'll need their own Spine license.
For the official legal terms governing the Spine Runtimes, please read the Spine Runtimes License Agreement and Section 2 of the Spine Editor License Agreement.
Spine version
spine-ts works with data exported from Spine 4.2.xx.
spine-ts Canvas does not support mesh attachments, clipping attachments, or two-color tinting. Only the alpha channel from tint colors is applied. Experimental support for mesh attachments can be enabled by setting spine.SkeletonRenderer.useTriangleRendering to true. Note that this experimental mesh rendering is slow and render with artifacts on some browsers.
spine-canvaskit supports all Spine features except two-color tinting.
The spine-webgl and spine-player support all Spine features.
spine-ts THREE.JS does not support two color tinting. The THREE.JS backend provides SkeletonMesh.zOffset to avoid z-fighting. Adjust to your near/far plane settings.
Usage
All spine-ts modules are published to npm for consumption via vanilla JavaScript as well as
Usage in vanilla JavaScript
You can include a module in your project via a <script> tag from the unpkg CDN, specifying the version as part of the URL. In the examples below, the version is 4.0.*, which fetches the latest patch release, and which will work with all exports from Spine Editor version 4.0.x.
// spine-core
<script src="https://unpkg.com/@esotericsoftware/spine-core@4.2.*/dist/iife/spine-core.js"></script>
// spine-canvas
<script src="https://unpkg.com/@esotericsoftware/spine-canvas@4.2.*/dist/iife/spine-canvas.js"></script>
// spine-canvaskit
<script src="https://unpkg.com/@esotericsoftware/spine-canvas@4.2.*/dist/iife/spine-canvaskit.js"></script>
// spine-webgl
<script src="https://unpkg.com/@esotericsoftware/spine-webgl@4.2.*/dist/iife/spine-webgl.js"></script>
// spine-player, which requires a spine-player.css as well
<script src="https://unpkg.com/@esotericsoftware/spine-player@4.2.*/dist/iife/spine-player.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@esotericsoftware/spine-player@4.0.*/dist/spine-player.css">
// spine-threejs
<script src="https://unpkg.com/@esotericsoftware/spine-threejs@4.2.*/dist/iife/spine-threejs.js"></script>
// spine-phaser-v3
<script src="https://unpkg.com/@esotericsoftware/spine-phaser-v3@4.2.*/dist/iife/spine-phaser-v3.js"></script>
// spine-phaser-v4
<script src="https://unpkg.com/@esotericsoftware/spine-phaser-v4@4.2.*/dist/iife/spine-phaser-v4.js"></script>
// spine-pixi-v7
<script src="https://unpkg.com/@esotericsoftware/spine-pixi-v7@4.2.*/dist/iife/spine-pixi-v7.js"></script>
// spine-pixi-v8
<script src="https://unpkg.com/@esotericsoftware/spine-pixi-v8@4.2.*/dist/iife/spine-pixi-v8.js"></script>
We also provide js.map source maps. They will be automatically fetched from unpkg when debugging code of a spine-module in Chrome, Firefox, or Safari, mapping the JavaScript code back to its original TypeScript sources.
We provide minified versions of each module, which can be used by replacing the .js file suffix with .min.js in the unpkg URLs.
Usage via NPM or Yarn
If your project dependencies are managed through NPM or Yarn, you can add spine-ts modules the usual way:
npm install @esotericsoftware/spine-core
npm install @esotericsoftware/spine-canvas
npm install @esotericsoftware/spine-canvaskit
npm install @esotericsoftware/spine-webgl
npm install @esotericsoftware/spine-player
npm install @esotericsoftware/spine-threejs
npm install @esotericsoftware/spine-phaser
npm install @esotericsoftware/spine-pixi-v7
npm install @esotericsoftware/spine-pixi-v8
spine-ts modules are provided in the ECMAScript format, which can be consumed natively by all modern browsers, or bundled by tools like webpack, Babel, Parcel, or esbuild. You can import functions and classes from a spine-ts module in your JavaScript or TypeScript code using the import syntax to get access to all exported constants, functions, and classes of a module:
import spine from "@esotericsoftware/spine-core"
Our module packages also contain js.map source maps as well as d.ts typings for easier debugging and development.
You can find all our published modules on the npm registry via the @esotericsoftware scope.
Examples
Every module except spine-core contains an example/ folder demonstrating usage of that module's API. To run the examples, install Node.js, then run the following command in the spine-runtimes/spine-ts folder:
npm run dev
This will compile the modules and start a server that serves the example pages at http://127.0.0.1:8080. When you make changes to the source code of either the modules and the examples, the source get recompiled, and the open page in the browser is reloaded automatically.
Development setup
spine-ts is developed with TypeScript, we thus recommend the following development environment when working on its sources:
- Install a Git Client and make sure it's available on the command line.
- Install NPM and make sure it's available on the command line.
- Install Visual Studio Code.
- Open a terminal and execute
git clone https://github.com/esotericsoftware/spine-runtimes
cd spine-runtimes/spine-ts
npm install
npm run dev
The final command npm run dev will start a local web server at http://127.0.0.1:8080, which reloads any page it served automatically in case the source code has changed. The command will also start the build tools in watch mode, meaning they will recompile any source code changes in the background automatically.
You can then open Visual Studio Code to inspect, edit, and debug the source code. We also supply launch configurations to start examples and demos in debug mode, so you can debug them right inside Visual Studio code.
To build the artifacts as they are published to NPM, run npm run build.