mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 18:26:12 +08:00
[ts][threejs] Cleaned up example, added license headers, updated README.md
This commit is contained in:
parent
5b4af038b8
commit
4a657158ba
@ -6,6 +6,7 @@ up into multiple modules:
|
|||||||
1. **Core**: `core/`, the core classes to load and process Spine models
|
1. **Core**: `core/`, the core classes to load and process Spine models
|
||||||
1. **WebGL**: `webgl/`, a self-contained WebGL backend, build on the core classes
|
1. **WebGL**: `webgl/`, a self-contained WebGL backend, build on the core classes
|
||||||
1. **Canvas**: `canvas/`, a self-contained Canvas backend, build on the core classes
|
1. **Canvas**: `canvas/`, a self-contained Canvas backend, build on the core classes
|
||||||
|
1. **THREE.JS**: `threejs/`, a self-contained THREE.JS backend, build on the core classes
|
||||||
1. **Widget**: `widget/`, a self-contained widget to easily display Spine animations on your website, build on core classes & WebGL backend.
|
1. **Widget**: `widget/`, a self-contained widget to easily display Spine animations on your website, build on core classes & WebGL backend.
|
||||||
|
|
||||||
While the source code for the core library and backends is written in TypeScript, all code is compiled to easily consumable JavaScript.
|
While the source code for the core library and backends is written in TypeScript, all code is compiled to easily consumable JavaScript.
|
||||||
@ -19,7 +20,7 @@ The Spine Runtimes are developed with the intent to be used with data exported f
|
|||||||
|
|
||||||
spine-ts works with data exported from the latest Spine version.
|
spine-ts works with data exported from the latest Spine version.
|
||||||
|
|
||||||
spine-ts WebGL & Widget backends supports all Spine features. The spine-ts Canvas backend does not support color tinting, mesh attachments or shearing. Mesh attachments are supported by setting `spine.canvas.SkeletonRenderer.useTriangleRendering` to true. Note that this method is slow and may lead to artifacts on some browsers.
|
spine-ts WebGL & Widget backends supports all Spine features. The spine-ts Canvas backend does not support color tinting, mesh attachments or shearing. Mesh attachments are supported by setting `spine.canvas.SkeletonRenderer.useTriangleRendering` to true. Note that this method is slow and may lead to artifacts on some browsers. The spine-ts THREE.JS backend does not support color tinting and blend modes. The THREE.JS backend provides `SkeletonMesh.zOffset` to avoid z-fighting. Adjust to your near/far plane settings.
|
||||||
|
|
||||||
spine-ts does not yet support loading the binary format.
|
spine-ts does not yet support loading the binary format.
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ spine-ts does not yet support loading the binary format.
|
|||||||
3. To use the WebGL backend, include the `spine-webgl.js` file in your project.
|
3. To use the WebGL backend, include the `spine-webgl.js` file in your project.
|
||||||
3. To use the Canvas backend, include the `spine-canvas.js` file in your project.
|
3. To use the Canvas backend, include the `spine-canvas.js` file in your project.
|
||||||
4. To use the Widget, include `spine-widget.js` file in your project.
|
4. To use the Widget, include `spine-widget.js` file in your project.
|
||||||
|
5. To use the THREE.JS backend, include the `spine-threejs.js` file in your project. THREE.JS must be loaded first.
|
||||||
|
|
||||||
All `*.js` files are self-contained and include both the core and respective backend classes.
|
All `*.js` files are self-contained and include both the core and respective backend classes.
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ cd spine-ts
|
|||||||
python -m SimpleHTTPServer
|
python -m SimpleHTTPServer
|
||||||
````
|
````
|
||||||
|
|
||||||
Then open `http://localhost:8000/webgl/example`, `http://localhost:8000/canvas/example` or `http://localhost:8000/widget/example` in your browser.
|
Then open `http://localhost:8000/webgl/example`, `http://localhost:8000/canvas/example`, `https://localhost:8000/threejs/example` or `http://localhost:8000/widget/example` in your browser.
|
||||||
|
|
||||||
## Development Setup
|
## Development Setup
|
||||||
The spine-ts runtime and the various backends are implemented in TypeScript for greater maintainability and better tooling support. To
|
The spine-ts runtime and the various backends are implemented in TypeScript for greater maintainability and better tooling support. To
|
||||||
@ -57,6 +59,7 @@ setup a development environment, follow these steps.
|
|||||||
* **Core**: `tsc -w -p tsconfig.core.json`, builds `core/src`, outputs `build/spine-core.js|d.ts|js.map`
|
* **Core**: `tsc -w -p tsconfig.core.json`, builds `core/src`, outputs `build/spine-core.js|d.ts|js.map`
|
||||||
* **WebGL**: `tsc -w -p tsconfig.webgl.json`, builds `core/src` and `webgl/src`, outputs `build/spine-webgl.js|d.ts|js.map`
|
* **WebGL**: `tsc -w -p tsconfig.webgl.json`, builds `core/src` and `webgl/src`, outputs `build/spine-webgl.js|d.ts|js.map`
|
||||||
* **WebGL**: `tsc -w -p tsconfig.canvas.json`, builds `core/src` and `canvas/src`, outputs `build/spine-canvas.js|d.ts|js.map`
|
* **WebGL**: `tsc -w -p tsconfig.canvas.json`, builds `core/src` and `canvas/src`, outputs `build/spine-canvas.js|d.ts|js.map`
|
||||||
|
* **THREE.JS**: `tsc -w -p tsconfig.threejs.json`, builds `core/src` and `threejs/src`, outputs `build/spine-threejs.js|d.ts|js.map`
|
||||||
* **Widget**: `tsc -w -p tsconfig.widget.json`, builds `core/src` and `widget/src`, outputs `build/spine-widget.js|d.ts|js.map`
|
* **Widget**: `tsc -w -p tsconfig.widget.json`, builds `core/src` and `widget/src`, outputs `build/spine-widget.js|d.ts|js.map`
|
||||||
6. Open the `spine-ts` folder in Visual Studio Code. VS Code will use the `tsconfig.json` file all source files from core and all
|
6. Open the `spine-ts` folder in Visual Studio Code. VS Code will use the `tsconfig.json` file all source files from core and all
|
||||||
backends for your development pleasure. The actual JavaScript output is still created by the command line TypeScript compiler process from the previous step.
|
backends for your development pleasure. The actual JavaScript output is still created by the command line TypeScript compiler process from the previous step.
|
||||||
@ -69,4 +72,4 @@ cd spine-ts
|
|||||||
python -m SimpleHTTPServer
|
python -m SimpleHTTPServer
|
||||||
```
|
```
|
||||||
|
|
||||||
Then navigate to `http://localhost:8000/webgl/example`, `http://localhost:8000/canvas/example` or `http://localhost:8000/widget/example`
|
Then navigate to `http://localhost:8000/webgl/example`, `http://localhost:8000/canvas/example`, `http://localhost:8000/threejs/example` or `http://localhost:8000/widget/example`
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -4,32 +4,26 @@
|
|||||||
<title>spine-threejs</title>
|
<title>spine-threejs</title>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.js"></script>
|
||||||
<script src="../../build/spine-threejs.js"></script>
|
<script src="../../build/spine-threejs.js"></script>
|
||||||
|
|
||||||
<style>body, input { font-family: tahoma; font-size: 11pt }</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
var scene, camera, renderer;
|
var scene, camera, renderer;
|
||||||
var geometry, material, mesh, skeletonMesh;
|
var geometry, material, mesh, skeletonMesh;
|
||||||
var assetManager;
|
var assetManager;
|
||||||
var lastFrameTime = Date.now() / 1000;
|
var lastFrameTime = Date.now() / 1000;
|
||||||
var dynMesh;
|
|
||||||
var batcher;
|
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
scene = new THREE.Scene();
|
// create the THREE.JS camera, scene and renderer (WebGL)
|
||||||
|
|
||||||
var width = 640, height = 480;
|
var width = 640, height = 480;
|
||||||
camera = new THREE.PerspectiveCamera(75, width / height, 1, 3000);
|
camera = new THREE.PerspectiveCamera(75, width / height, 1, 3000);
|
||||||
camera.position.z = 400;
|
camera.position.z = 400;
|
||||||
|
scene = new THREE.Scene();
|
||||||
renderer = new THREE.WebGLRenderer();
|
renderer = new THREE.WebGLRenderer();
|
||||||
renderer.setSize(width, height);
|
renderer.setSize(width, height);
|
||||||
|
|
||||||
document.body.appendChild(renderer.domElement);
|
document.body.appendChild(renderer.domElement);
|
||||||
|
|
||||||
|
// load the assets required to display the Raptor model
|
||||||
assetManager = new spine.threejs.AssetManager();
|
assetManager = new spine.threejs.AssetManager();
|
||||||
assetManager.loadText("assets/raptor.json");
|
assetManager.loadText("assets/raptor.json");
|
||||||
assetManager.loadText("assets/raptor.atlas");
|
assetManager.loadText("assets/raptor.atlas");
|
||||||
@ -52,6 +46,8 @@ function load (name, scale) {
|
|||||||
return assetManager.get("assets/" + path);
|
return assetManager.get("assets/" + path);
|
||||||
});
|
});
|
||||||
var skeletonData = loadSkeleton("raptor", 0.4);
|
var skeletonData = loadSkeleton("raptor", 0.4);
|
||||||
|
|
||||||
|
// Create a SkeletonMesh from the data and attach it to the scene
|
||||||
skeletonMesh = new spine.threejs.SkeletonMesh(skeletonData);
|
skeletonMesh = new spine.threejs.SkeletonMesh(skeletonData);
|
||||||
skeletonMesh.state.setAnimation(0, "walk", true);
|
skeletonMesh.state.setAnimation(0, "walk", true);
|
||||||
mesh.add(skeletonMesh);
|
mesh.add(skeletonMesh);
|
||||||
@ -81,17 +77,19 @@ function loadSkeleton (name, scale) {
|
|||||||
|
|
||||||
var lastTime = Date.now();
|
var lastTime = Date.now();
|
||||||
function render() {
|
function render() {
|
||||||
|
// calculate delta time for animation purposes
|
||||||
var now = Date.now() / 1000;
|
var now = Date.now() / 1000;
|
||||||
var delta = now - lastFrameTime;
|
var delta = now - lastFrameTime;
|
||||||
lastFrameTime = now;
|
lastFrameTime = now;
|
||||||
|
|
||||||
var a = Math.sin(now);
|
// rotate the cube
|
||||||
var b = Math.cos(now);
|
mesh.rotation.x = Math.sin(now) * Math.PI * 0.2;
|
||||||
|
mesh.rotation.y = Math.cos(now) * Math.PI * 0.4;
|
||||||
mesh.rotation.x = a * Math.PI * 0.2;
|
|
||||||
mesh.rotation.y = b * Math.PI * 0.4;
|
|
||||||
|
|
||||||
|
// update the animation
|
||||||
skeletonMesh.update(delta);
|
skeletonMesh.update(delta);
|
||||||
|
|
||||||
|
// render the scene
|
||||||
renderer.render(scene, camera);
|
renderer.render(scene, camera);
|
||||||
|
|
||||||
requestAnimationFrame(render);
|
requestAnimationFrame(render);
|
||||||
|
|||||||
@ -1,3 +1,34 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Spine Runtimes Software License
|
||||||
|
* Version 2.5
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
* non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
* Runtimes software and derivative works solely for personal or internal
|
||||||
|
* use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
* the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
* adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
* create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
* or other intellectual property or proprietary rights notices on or in the
|
||||||
|
* Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
* form must include this license and terms.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
module spine.threejs {
|
module spine.threejs {
|
||||||
export class AssetManager extends spine.AssetManager {
|
export class AssetManager extends spine.AssetManager {
|
||||||
constructor () {
|
constructor () {
|
||||||
|
|||||||
@ -1,3 +1,34 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Spine Runtimes Software License
|
||||||
|
* Version 2.5
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
* non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
* Runtimes software and derivative works solely for personal or internal
|
||||||
|
* use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
* the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
* adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
* create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
* or other intellectual property or proprietary rights notices on or in the
|
||||||
|
* Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
* form must include this license and terms.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
module spine.threejs {
|
module spine.threejs {
|
||||||
export class MeshBatcher {
|
export class MeshBatcher {
|
||||||
mesh: THREE.Mesh;
|
mesh: THREE.Mesh;
|
||||||
|
|||||||
@ -1,3 +1,34 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Spine Runtimes Software License
|
||||||
|
* Version 2.5
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
* non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
* Runtimes software and derivative works solely for personal or internal
|
||||||
|
* use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
* the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
* adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
* create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
* or other intellectual property or proprietary rights notices on or in the
|
||||||
|
* Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
* form must include this license and terms.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
module spine.threejs {
|
module spine.threejs {
|
||||||
export class SkeletonMesh extends THREE.Mesh {
|
export class SkeletonMesh extends THREE.Mesh {
|
||||||
|
|
||||||
@ -72,7 +103,7 @@ module spine.threejs {
|
|||||||
mat.map = texture.texture;
|
mat.map = texture.texture;
|
||||||
mat.needsUpdate = true;
|
mat.needsUpdate = true;
|
||||||
}
|
}
|
||||||
// FIXME
|
// FIXME per slot blending would require multiple material support
|
||||||
//let slotBlendMode = slot.data.blendMode;
|
//let slotBlendMode = slot.data.blendMode;
|
||||||
//if (slotBlendMode != blendMode) {
|
//if (slotBlendMode != blendMode) {
|
||||||
// blendMode = slotBlendMode;
|
// blendMode = slotBlendMode;
|
||||||
|
|||||||
@ -1,3 +1,34 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Spine Runtimes Software License
|
||||||
|
* Version 2.5
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
* non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
* Runtimes software and derivative works solely for personal or internal
|
||||||
|
* use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
* the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
* adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
* create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
* or other intellectual property or proprietary rights notices on or in the
|
||||||
|
* Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
* form must include this license and terms.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
module spine.threejs {
|
module spine.threejs {
|
||||||
export class ThreeJsTexture extends Texture {
|
export class ThreeJsTexture extends Texture {
|
||||||
texture: THREE.Texture;
|
texture: THREE.Texture;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user