Merge branch '3.8' into 3.9-beta

This commit is contained in:
badlogic 2019-10-25 13:54:53 +02:00
commit 4dd94dfb4d
3 changed files with 131 additions and 3 deletions

View File

@ -0,0 +1,128 @@
package com.esotericsoftware.spine;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.esotericsoftware.spine.utils.TwoColorPolygonBatch;
/** Demonstrates how to let the target bone of an IK constraint
* follow the mouse or touch position, which in turn repositions
* part of the skeleton, in this case Spineboy's back arm including
* his gun.
*/
public class IKTest extends ApplicationAdapter {
OrthographicCamera camera;
TwoColorPolygonBatch batch;
SkeletonRenderer renderer;
TextureAtlas atlas;
Skeleton skeleton;
AnimationState state;
Vector3 cameraCoords = new Vector3();
Vector2 boneCoords = new Vector2();
public void create () {
// Create objects needed for rendering
camera = new OrthographicCamera();
batch = new TwoColorPolygonBatch();
renderer = new SkeletonRenderer();
renderer.setPremultipliedAlpha(true);
// Load the texture atlas and skeleton data
atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy-pma.atlas"));
SkeletonBinary json = new SkeletonBinary(atlas);
json.setScale(0.6f);
SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy-pro.skel"));
// Create a skeleton from the skeleton data
skeleton = new Skeleton(skeletonData);
skeleton.setPosition(250, 20);
// Create an animation satte
AnimationStateData stateData = new AnimationStateData(skeletonData);
state = new AnimationState(stateData);
// Queue the "walk" animation on the first track.
state.setAnimation(0, "walk", true);
// Queue the "aim" animation on a higher track.
// It consists of a single frame that positions
// the back arm and gun such that they point at
// the "crosshair" bone. By setting this
// animation on a higher track, it overrides
// any changes to the back arm and gun made
// by the walk animation, allowing us to
// mix the two. The mouse position following
// is performed in the render() method below.
state.setAnimation(1, "aim", true);
// apply the state once, so we have world
// bone positions that we can use.
skeleton.setToSetupPose();
}
public void render () {
// Update and apply the animations to the skeleton,
// then calculate the world transforms of every bone.
// This is needed so we can call Bone#worldToLocal()
// later.
state.update(Gdx.graphics.getDeltaTime());
state.apply(skeleton);
skeleton.updateWorldTransform();
// Position the "crosshair" bone at the mouse
// location. We do this before calling
// skeleton.updateWorldTransform() below, so
// our change is incorporated before the IK
// constraint is applied.
//
// When setting the crosshair bone position
// to the mouse position, we need to translate
// from "mouse space" to "camera space"
// and then to "local bone space". Note that the local
// bone space is calculated using the bone's parent
// worldToLocal() function!
cameraCoords.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(cameraCoords); // mouse space to camera space
Bone crosshair = skeleton.findBone("crosshair"); // Should be cached.
boneCoords.set(cameraCoords.x, cameraCoords.y);
crosshair.getParent().worldToLocal(boneCoords); // camera space to local bone space
crosshair.setPosition(boneCoords.x, boneCoords.y); // override the crosshair position
crosshair.setAppliedValid(false);
// Calculate final world transform with the
// crosshair bone set to the mouse cursor
// position.
skeleton.updateWorldTransform();
// Clear the screen, update the camera and
// render the skeleton.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
batch.getProjectionMatrix().set(camera.combined);
batch.begin();
renderer.draw(batch, skeleton);
batch.end();
}
public void resize (int width, int height) {
camera.setToOrtho(false); // Update camera with new size.
}
public void dispose () {
atlas.dispose();
}
public static void main (String[] args) throws Exception {
new LwjglApplication(new IKTest());
}
}

View File

@ -1,5 +1,5 @@
# spine-ue4
The spine-ue4 runtime provides functionality to load, manipulate and render [Spine](http://esotericsoftware.com) skeletal animation data using [Unreal Engine 4.18+](https://www.unrealengine.com/). spine-ue4 is based on [spine-cpp](../spine-cpp).
The spine-ue4 runtime provides functionality to load, manipulate and render [Spine](http://esotericsoftware.com) skeletal animation data using [Unreal Engine 4.21+](https://www.unrealengine.com/). spine-ue4 is based on [spine-cpp](../spine-cpp).
## Licensing
@ -33,7 +33,7 @@ See the [Spine Runtimes documentation](http://esotericsoftware.com/spine-documen
## Example
### [Please see the spine-ue4 guide for full documentation](http://esotericsoftware.com/spine-ue4)
The Spine UE4 example works on all platforms supported by Unreal Engine. The samples require Unreal Engine 4.18.
The Spine UE4 example works on all platforms supported by Unreal Engine. The samples require Unreal Engine 4.23+.
1. Copy the `spine-cpp` folder from this repositories root directory to your `Plugins/SpinePlugin/Sources/SpinePlugin/Public/` directory.
2. Open the SpineUE4.uproject file with Unreal Editor

View File

@ -1,6 +1,6 @@
{
"FileVersion": 3,
"EngineAssociation": "4.22",
"EngineAssociation": "4.23",
"Category": "",
"Description": "",
"Modules": [