Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rmodels] Animation issue with the GLB/GLTF files #4569

Open
efeozyer opened this issue Dec 2, 2024 · 5 comments
Open

[rmodels] Animation issue with the GLB/GLTF files #4569

efeozyer opened this issue Dec 2, 2024 · 5 comments
Labels
help needed - please! I need help with this issue

Comments

@efeozyer
Copy link

efeozyer commented Dec 2, 2024

  • [ x ] I tested it on latest raylib version from master branch
  • [ x ] I checked there is no similar issue already reported
  • [ x ] I checked the documentation on the wiki
  • [ x ] My code has no errors or misuse of raylib

Issue description

Hi folks, I recently started using Raylib with the basic setup. Basically I was trying to load ,GLB file and animate it.
You can see there, my character how looks like without animation.

image

But.. that happens when I called UpdateModelAnimation method.
image

I thought that, something wrong with my .GLB file but I have tried this, web site and it was working properly.

https://gltf-viewer.donmccurdy.com/

Environment

Windows x64 \ Raylib 5.5 \ VC++

Additional files

orc_warrior.zip

// Raylib.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "raylib.h"
#include <iostream>

int main()
{
	InitWindow(800, 600, "Raylib Window");

	int animCount = 0;
	int animFrame = 0;
	auto model = LoadModel("orc_warrior.glb");
	auto animations = LoadModelAnimations("orc_warrior.glb", &animCount);

	Camera camera = { 0 };
	camera.position = { 4.0f, 4.0f, 4.f };
	camera.target = { 0.0f, 2.0f, 0.0f };
	camera.up = { 0.0f, 1.0f, 0.0f };
	camera.fovy = 60.0f;
	camera.projection = CAMERA_PERSPECTIVE;

	while (!WindowShouldClose()) {
		BeginDrawing();
		ClearBackground(BLACK);
		BeginMode3D(camera);
		DrawText("Hello, Raylib!", 190, 200, 20, LIGHTGRAY);
		DrawModel(model, { 0.0f, 0.0f, 0.0f }, 1.0f, WHITE);
		
		if (IsKeyDown(KEY_W))
		{
			UpdateModelAnimation(model, animations[0], animFrame);
			if (animFrame >= animations[0].frameCount) {
				animFrame = 0;
			}
			animFrame++;
		}

		DrawGrid(100, 5);
		EndMode3D();
		EndDrawing();
	}
	CloseWindow();
	return 0;
}


@efeozyer efeozyer changed the title Animation issue GLB/GLTF files Animation issue with the GLB/GLTF files Dec 2, 2024
@raysan5 raysan5 changed the title Animation issue with the GLB/GLTF files [rmodels] Animation issue with the GLB/GLTF files Dec 3, 2024
@raysan5 raysan5 added the help needed - please! I need help with this issue label Dec 3, 2024
@Kirandeep-Singh-Khehra
Copy link
Contributor

Kirandeep-Singh-Khehra commented Dec 4, 2024

Hi @efeozyer,

I faced similar issue before with Mixamo Y-bot. I tried your example too. and its somewhat similar. I have modified your model a little and you can get here. orc_warrior.zip.

What i did:

  1. Open blender.
  2. Import model in blender.
  3. Delete camera, default cube and light.
  4. Change rotation model to Euler model and set rotations to 0. As shown here.
    image
  5. Now export the model and use it again.
  6. It will work now. You can apply transform in code to make him upright. There's a way to apply transforms permanently to a model in blender but i'm not good with blender.

I think this issue is with UpdateModelAnimation() function(or UpdateModelAnimationBones()) or issue could be that bindPose does not consider rotation of mesh while loading or updating bones. But this process works.

You may see animation running too fast, you can add SetTargetFPS(60); before while loop to see it at normal speeds.

@Fabus1184
Copy link

Fabus1184 commented Jan 2, 2025

I'm having the same Issue (still with the current master 5.5-116-g0f6e85a9).

Trying this really simple model https://poly.pizza/m/BEcU9rjiAq shows that there seems to be something wrong with the transformations themselves:
with raylib the tail of the fish is rotating lengthwise, but the correct animation as shown on the web page only has side to side translation.

@Kirandeep-Singh-Khehra
Copy link
Contributor

Hi @Fabus1184, have you tried this. #4569 (comment).

IMO raylib is not considering the orientation of pivot point.

@Fabus1184
Copy link

Yes I tried, but somehow the animation looks even worse then

@Kirandeep-Singh-Khehra
Copy link
Contributor

Kirandeep-Singh-Khehra commented Jan 2, 2025

Okay you can import it in blender remove default stuff. Press A then Ctrl + A and the select All Transforms and then export it again.
Here is your modified model Fish.glb.zip
and it worked for me. Here's a video link.
https://github.com/user-attachments/assets/b6c80194-cd5f-4eac-a5c5-9c9cfbd47c47

I'm also waiting on this fix. But for now you can use the model i shared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help needed - please! I need help with this issue
Projects
None yet
Development

No branches or pull requests

4 participants