weremsoft

Hi, I'm trying to create a spine runtime for rayblib (https://www.raylib.com/)

For that, I'm using the generic C libraries version 3.8 (https://github.com/EsotericSoftware/spine-runtimes/tree/3.8/spine-c)

Everything goes well except for 2 things:

1. The animation is upside down.
2. Any scale < 0 make the animation disappear.

The most important thing to solve for me is 1, but maybe this two problems are related.

My code is here:
https://github.com/WEREMSOFT/flecs_plus_raylib/tree/raylib-example

The meaningful code is here:

https://github.com/WEREMSOFT/flecs_plus_raylib/blob/raylib-example/src/spine/extension.c
in the function
engine_drawMesh
this is the meaningful code where I think is the problem:
void draw_vertex(Vertex vertex, Vector3 position){
rlTexCoord2f(vertex.u, vertex.v);
rlColor4f(vertex.r, vertex.g, vertex.b, vertex.a);
rlVertex3f( position.x + vertex.x, position.y + vertex.y, position.z);
}

void engine_drawMesh(Vertex* vertices, int numVertices, Texture* texture, Vector3 position){
Vertex vertex;

rlEnableTexture(texture->id);

rlPushMatrix();
{
rlBegin(RL_QUADS);
{
rlNormal3f(0.0f, 0.0f, 1.0f);
for (int i = 0; i < numVertices; i++){
if(i < 3 || i == 4){
vertex = vertices[i];
draw_vertex(vertex, position);
}
}
}rlEnd();
}rlPopMatrix();
rlDisableTexture();
}
What I've already tried:
Invert the normal when doing scaleY = -1 on the skeleton
Draw Vertices in inverse orden when scaleY = -1 on the skeleton

This is how it looks when loading the skeleton without any scale

Screen Shot 2020-01-08 at 21.54.49.png


This is how it looks with a scaleY of 0.25

Screen Shot 2020-01-10 at 15.45.01.png


This is how it looks with a scaleY -1

Screen Shot 2020-01-10 at 15.46.40.png


I have same results when I scale on X axis.

Thanks in advance
You do not have the required permissions to view the files attached to this post.
weremsoft
  • Posts: 3

Mario

Good stuff, I love Raylib! Regarding the up-side-down issue, a call to spBone_setYDown(true) should do the trick! spine-runtimes/spine-sfml.cpp at 3.8
User avatar
Mario

Mario
  • Posts: 2222

weremsoft

Thanks @badlogic. It's not upside down anymore, but I have to flip it vertically in order to see the render.
spBone_setYDown(true);
skeleton = spSkeleton_create(skeletonData);
skeleton->scaleX = -0.5; // Now I have to do this!
skeleton->scaleY = 0.5;
I'm having this problem flicking the model and I don't understand why. It's about the backface culling for sure.

Do you have any idea about what else can I try to solve this flicking problem?

This is what I have (the model is looking in the wrong direction)
Screen Shot 2020-01-10 at 20.47.11.png


---

Ok, I have to disable the backface culling but this is a performance hit! I need to check if it's possible to disable backface culling only for the spine model.
rlDisableBackfaceCulling(); // Disables the backface culling for the whole game!!!
You do not have the required permissions to view the files attached to this post.
weremsoft
  • Posts: 3

Mario

I wouldn't suggest to just disable backface culling. Instead, you can reorder the winding of the triangle vertices in your rendering code. Enabling/disabling a GPU state like culling all the time is much more detrimental than just reordering triangle vertex order.
User avatar
Mario

Mario
  • Posts: 2222


Return to Runtimes