Рендерлер Spine-Skiasharp в мобильном приложении .NET MauiC#

Место общения программистов C#
Ответить
Anonymous
 Рендерлер Spine-Skiasharp в мобильном приложении .NET Maui

Сообщение Anonymous »

Я пытаюсь отобрать анимацию позвоночника в приложении C# .net Maui с использованием Skiasharp.
Мой алгоритм выглядит неправильно, я не могу понять, что не хватает. Br /> Вот мой результат, похоже, что позиция региона Y неверна, а также ориентация на регион: < /p>
< /p>
Это ожидаемый результат: < /p>

Это метод, который рисует область:

Код: Выделить всё

    private void DrawRegionAttachment(SKCanvas canvas, RegionAttachment regionAttachment, Slot slot)
{
Bone bone = slot.Bone;

// Calculate position and cumulated rotation
float worldX = bone.WorldX;
float worldY = bone.WorldY;
float rotation = bone.WorldRotationX + regionAttachment.Rotation;
float scaleX = bone.WorldScaleX * regionAttachment.ScaleX;
float scaleY = bone.WorldScaleY * regionAttachment.ScaleY;

// Convert rotation to rad
float radians = rotation * MathF.PI / 180f;
float cos = MathF.Cos(radians);
float sin = MathF.Sin(radians);

// Calculate world verticies
float offsetX = regionAttachment.X;
float offsetY = regionAttachment.Y;
float renderX = worldX + (offsetX * cos - offsetY * sin);
float renderY = worldY - (offsetX * sin - offsetY * cos); // Should inverse Y axis for Skiasharp

// Retrieve the texture from the texture loader
string textureName = "spineboy-ess.png";
var bitmap = textureLoader.GetTexture(textureName);

// Get the region attachment texture coordinates
float textureWidth = bitmap.Width;
float textureHeight = bitmap.Height;
var sourceRect = new SKRect(
regionAttachment.Region.u * textureWidth,
regionAttachment.Region.v * textureHeight,
regionAttachment.Region.u2 * textureWidth,
regionAttachment.Region.v2 * textureHeight
);

// Calculate the attachment width and height
float attachmentWidth = regionAttachment.Width * scaleX;
float attachmentHeight = regionAttachment.Height * scaleY;

// Define the destination rectangle
var destRect = new SKRect(
renderX - attachmentWidth / 2,
renderY - attachmentHeight / 2,
renderX + attachmentWidth / 2,
renderY + attachmentHeight / 2
);

// Render texture on SKiasharp canvas
using var paint = new SKPaint
{
IsAntialias = true,
FilterQuality = SKFilterQuality.High
};

canvas.DrawBitmap(bitmap, sourceRect, destRect, paint);
}
Полный проект доступен здесь https://github.com/espritm/Spine-skiasharp со спрайтом, атласом и json. Анимация представляет собой базовый образец Spineboy.
Есть ли шанс, что кто-нибудь поможет мне применить правильные преобразования, чтобы отрисовка была правильной?

Подробнее здесь: https://stackoverflow.com/questions/793 ... mobile-app
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»