# @galacean/mars-plugin-spine

> Mars Player spine plugin

Latest version **2.8.1** (published 2024-01-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @galacean/mars-plugin-spine
pnpm add @galacean/mars-plugin-spine
yarn add @galacean/mars-plugin-spine
bun add @galacean/mars-plugin-spine
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.8.1 |
| Published | 2024-01-20 |
| First published | 2023-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ant Group CO., Ltd. |
| Maintainers | chengkong.zxx, imchenjian, ruimeng.su, yinjie, yiqi, jujie, luzhuang, husong, mrkou47, johanzhu, zhuxudong, zhanyingwei, gl3336563, eyworldwide |

## Links

- npm: https://www.npmjs.com/package/@galacean/mars-plugin-spine
- npm.io page: https://npm.io/package/@galacean/mars-plugin-spine

## Dependencies (1)

- [@esotericsoftware/spine-core](https://npm.io/package/@esotericsoftware/spine-core.md) ~4.2.33

## Recent versions

- 2.8.1 (latest) — 2024-01-20
- 2.8.0-alpha.19 (alpha) — 2024-01-19
- 0.0.0-experimental-1124-2.4.20231130 (experimental) — 2023-11-30
- 2.8.0 — 2024-01-20
- 2.8.0-alpha.18 — 2024-01-19
- 2.8.0-alpha.17 — 2024-01-18
- 2.8.0-alpha.16 — 2024-01-18
- 2.8.0-alpha.15 — 2024-01-18
- 2.8.0-alpha.14 — 2024-01-17
- 2.8.0-alpha.13 — 2024-01-17
- 2.8.0-alpha.12 — 2024-01-11
- 2.8.0-alpha.11 — 2024-01-11
- 2.8.0-alpha.10 — 2024-01-10
- 2.8.0-alpha.9 — 2024-01-07
- 2.8.0-alpha.8 — 2024-01-07
- … 67 more at https://npm.io/package/@galacean/mars-plugin-spine/versions

## README

# Mars 骨骼动画插件

## 使用
### React demo (Smallfish)
https://code.alipay.com/shixian.cr/spine-demo

### 简单引入

``` ts
import { MarsPlayer } from '@galacean/mars-player';
import '@galacean/mars-plugin-spine';
```

### 获取 spine 资源列表

``` ts
import type { SpineResource } from '@galacean/mars-plugin-spine';

const comp = await player.play(scene);
const spineData: SpineResource[] = comp.loaderData.spineDatas;
```

### 获取动画列表/皮肤列表

1. 使用函数获取

``` ts
const comp = await new MarsPlayer().loadScene(scene);
const item = comp.getItemByName(name)
const { skeletonData } = item.spineDataCache;
const animationList = getAnimationList(skeletonData);
const skinList = getSkinList(skeletonData);
```

2. 在 `spineDatas` 数组中获取

``` ts
const comp = await new MarsPlayer().loadScene(scene);
const { skinList, animationList } = comp.loaderData.spineDatas[index];
```

### 获取指定动画时长

``` ts
const animationDuration = getAnimationDuration(skeletonData, animationName);
```

### 获取创建纹理的参数
``` ts
import { getTextureOptions } from '@galacean/mars-plugin-spine';

const { magFilter, minFilter, wrapS, wrapT, pma } = getTextureOptions(atlasBuffer);
```

### 设置动画 mix 时间

1. 设置动画的默认 mix 时间 （需要在 `player.play`` 前调用）

``` ts
const comp = await new MarsPlayer().loadScene(scene);
const item = comp.getItemByName(name);

item.setDefaultMixDuration(mix);
```

2. 设置指定动作的 mix 时间 （需要在 `player.play`` 前调用）

``` ts
const comp = await new MarsPlayer().loadScene(scene);
const item = comp.getItemByName(name);

item.setMixDuration(animationOut, animationIn, mix);
```
### 设置播放速度

``` ts
const comp = await new MarsPlayer().loadScene(scene);
const item = comp.getItemByName(name);

item.setSpeed(speed);
```

### 设置动画

1. 设置单个动画
``` ts
const comp = await new MarsPlayer().loadScene(scene);
const item = comp.getItemByName(name);

item.setAnimation(animationName, speed);
```

2. 设置一组动画

``` ts
const comp = await new MarsPlayer().loadScene(scene);
const item = comp.getItemByName(name);
const animationList = [animationName1, animationName2, animationName3];

item.setAnimation(animationList, speed);
```

## 本地开发

### 开始开发

``` bash
# demo
pnpm --filter @galacean/mars-plugin-spine dev
```

> 浏览器打开：http://localhost:8081/demo/

## 帧对比测试

> 浏览器打开：http://localhost:8081/test/

---
_Source: https://npm.io/package/@galacean/mars-plugin-spine · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
