J0chem

Hi,

I have been thinking about making a 2.5D game, e.g. in Paper Mario and Don't Starve style, by rendering the Spine animations in a 3D world. I have noticed that while LibGDX supports this, there does not seem to be such support in Spine, since the DecalBatch is not a subclass of the Batch class.

How difficult would it be to implement this in the Spine runtime myself?

- Jochem
J0chem
Posts: 19

badlogic

Pretty hard, as Decal only represents a 4 vertex quad. You could simply render via sprite or polygon batch, offsetting on z via the transform matrix, and enabling z-writes and depth tests.
User avatar
badlogic

Mario
Posts: 1353

J0chem

Where do I enable z-writes and depth tests? If I want to scale the image in proportion to the distance to the camera, would I need to do some of the linear algebra myself or are there some utility methods I am not aware of? (This is the reason I wanted to use the DecalBatch, because everything has already been done there.)
J0chem
Posts: 19

badlogic

The way you'd do it is as follows:

1. Render your 3D environment with ModelBatch, Decals, what have you. This will write to the z-buffer.
2. Enable depth testing and writes via Gdx.gl.glEnable(GL20.GL_DEPTH_TEST)
3. Set the 3D position of your Spine skeleton on the PolygonSpriteBatch (assuming your skeleton's have mesh attachments) via the setTransformMatrix(). See https://github.com/libgdx/libgdx/wiki/Vectors,-matrices,-quaternions#method-chaining-1 on how to create that matrix based on a position and rotation.
4. Set the projection matrix of the PolygonSpriteBatch based on the camera combined matrix that you used to render the 3D environment via setProjectionMatrix(). That will do the perspective transform for you.
5. Render the skeleton via the SkeletonRenderer, passing in the PolygonSpriteBatch and your skeleton.
User avatar
badlogic

Mario
Posts: 1353


Return to Runtimes