From 45eb76fed2af911df0c1d99fb725bf194b5b69df Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 30 Jun 2025 18:14:35 +0200 Subject: [PATCH] [monogame] Adjusted monogame code to spine-csharp 4.3 changes. --- .../spine-monogame-example/ExampleGame.cs | 14 +- .../spine-monogame/spine-monogame.csproj | 212 ++++++------------ .../src/SkeletonDebugRenderer.cs | 22 +- .../spine-monogame/src/SkeletonRenderer.cs | 40 ++-- 4 files changed, 108 insertions(+), 180 deletions(-) diff --git a/spine-monogame/spine-monogame-example/ExampleGame.cs b/spine-monogame/spine-monogame-example/ExampleGame.cs index 88d06f9e1..623cc53d8 100644 --- a/spine-monogame/spine-monogame-example/ExampleGame.cs +++ b/spine-monogame/spine-monogame-example/ExampleGame.cs @@ -95,7 +95,7 @@ namespace Spine { state.Apply(skeleton); // Update the transformations of bones and other parts of the skeleton - skeleton.UpdateWorldTransform(Skeleton.Physics.Update); + skeleton.UpdateWorldTransform(Physics.Update); // Clear the screen and setup the projection matrix of the skeleton renderer game.GraphicsDevice.Clear(Color.Black); @@ -148,7 +148,7 @@ namespace Spine { skeleton.Update(deltaTime); state.Apply(skeleton); - skeleton.UpdateWorldTransform(Skeleton.Physics.Update); + skeleton.UpdateWorldTransform(Physics.Update); // Clear the screen and setup the projection matrix of the custom effect through the // "Projection" parameter. @@ -193,7 +193,7 @@ namespace Spine { // Set the "walk" animation on track one and let it loop forever state.SetAnimation(0, "walk", true); - + // Queue another animation after 2 seconds to let Spineboy jump state.AddAnimation(0, "jump", false, 2); @@ -206,7 +206,7 @@ namespace Spine { skeleton.Update(deltaTime); state.Apply(skeleton); - skeleton.UpdateWorldTransform(Skeleton.Physics.Update); + skeleton.UpdateWorldTransform(Physics.Update); game.GraphicsDevice.Clear(Color.Black); ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height, 0, 1, 0); @@ -267,7 +267,7 @@ namespace Spine { skeleton.Update(deltaTime); state.Apply(skeleton); - skeleton.UpdateWorldTransform(Skeleton.Physics.Update); + skeleton.UpdateWorldTransform(Physics.Update); game.GraphicsDevice.Clear(Color.Black); ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height, 0, 1, 0); @@ -323,7 +323,7 @@ namespace Spine { // lastPosition = currentPosition; state.Apply(skeleton); - skeleton.UpdateWorldTransform(Skeleton.Physics.Update); + skeleton.UpdateWorldTransform(Physics.Update); game.GraphicsDevice.Clear(Color.Black); ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height, 0, 1, 0); @@ -380,7 +380,7 @@ namespace Spine { // lastPosition = currentPosition; state.Apply(skeleton); - skeleton.UpdateWorldTransform(Skeleton.Physics.Update); + skeleton.UpdateWorldTransform(Physics.Update); game.GraphicsDevice.Clear(Color.Black); ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height, 0, 1, 0); diff --git a/spine-monogame/spine-monogame/spine-monogame.csproj b/spine-monogame/spine-monogame/spine-monogame.csproj index 19e940491..788aed7e2 100644 --- a/spine-monogame/spine-monogame/spine-monogame.csproj +++ b/spine-monogame/spine-monogame/spine-monogame.csproj @@ -18,147 +18,74 @@ - - spine-csharp\Animation.cs - - - spine-csharp\AnimationState.cs - - - spine-csharp\AnimationStateData.cs - - - spine-csharp\Atlas.cs - - - spine-csharp\BlendMode.cs - - - spine-csharp\Bone.cs - - - spine-csharp\BoneData.cs - - - spine-csharp\ConstraintData.cs - - - spine-csharp\Event.cs - - - spine-csharp\EventData.cs - - - spine-csharp\ExposedList.cs - - - spine-csharp\IkConstraint.cs - - - spine-csharp\IkConstraintData.cs - - - spine-csharp\PhysicsConstraint.cs - - - spine-csharp\PhysicsConstraintData.cs - - - spine-csharp\IUpdatable.cs - - - spine-csharp\Json.cs - - - spine-csharp\MathUtils.cs - - - spine-csharp\PathConstraint.cs - - - spine-csharp\PathConstraintData.cs - - - spine-csharp\Skeleton.cs - - - spine-csharp\SkeletonBinary.cs - - - spine-csharp\SkeletonBounds.cs - - - spine-csharp\SkeletonClipping.cs - - - spine-csharp\SkeletonData.cs - - - spine-csharp\SkeletonJson.cs - - - spine-csharp\SkeletonLoader.cs - - - spine-csharp\Skin.cs - - - spine-csharp\Slot.cs - - - spine-csharp\SlotData.cs - - - spine-csharp\TextureRegion.cs - - - spine-csharp\TransformConstraint.cs - - - spine-csharp\TransformConstraintData.cs - - - spine-csharp\Triangulator.cs - - - spine-csharp\Attachments\AtlasAttachmentLoader.cs - - - spine-csharp\Attachments\Attachment.cs - - - spine-csharp\Attachments\AttachmentLoader.cs - - - spine-csharp\Attachments\AttachmentType.cs - - - spine-csharp\Attachments\BoundingBoxAttachment.cs - - - spine-csharp\Attachments\ClippingAttachment.cs - - - spine-csharp\Attachments\IHasTextureRegion.cs - - - spine-csharp\Attachments\MeshAttachment.cs - - - spine-csharp\Attachments\PathAttachment.cs - - - spine-csharp\Attachments\PointAttachment.cs - - - spine-csharp\Attachments\RegionAttachment.cs - - - spine-csharp\Attachments\Sequence.cs - - - spine-csharp\Attachments\VertexAttachment.cs - + + spine-csharp\Animation.cs + spine-csharp\AnimationState.cs + spine-csharp\AnimationStateData.cs + spine-csharp\Atlas.cs + spine-csharp\BlendMode.cs + spine-csharp\Bone.cs + spine-csharp\BoneData.cs + spine-csharp\BoneLocal.cs + spine-csharp\BonePose.cs + spine-csharp\ColorMono.cs + spine-csharp\ColorUnity.cs + spine-csharp\Constraint.cs + spine-csharp\ConstraintData.cs + spine-csharp\Event.cs + spine-csharp\EventData.cs + spine-csharp\ExposedList.cs + spine-csharp\IkConstraint.cs + spine-csharp\IkConstraintData.cs + spine-csharp\IkConstraintPose.cs + spine-csharp\IPose.cs + spine-csharp\IUpdate.cs + spine-csharp\Json.cs + spine-csharp\MathUtils.cs + spine-csharp\PathConstraint.cs + spine-csharp\PathConstraintData.cs + spine-csharp\PathConstraintPose.cs + spine-csharp\Physics.cs + spine-csharp\PhysicsConstraint.cs + spine-csharp\PhysicsConstraintData.cs + spine-csharp\PhysicsConstraintPose.cs + spine-csharp\Posed.cs + spine-csharp\PosedActive.cs + spine-csharp\PosedData.cs + spine-csharp\Skeleton.cs + spine-csharp\SkeletonBinary.cs + spine-csharp\SkeletonBounds.cs + spine-csharp\SkeletonClipping.cs + spine-csharp\SkeletonData.cs + spine-csharp\SkeletonJson.cs + spine-csharp\SkeletonLoader.cs + spine-csharp\Skin.cs + spine-csharp\Slider.cs + spine-csharp\SliderData.cs + spine-csharp\SliderPose.cs + spine-csharp\Slot.cs + spine-csharp\SlotData.cs + spine-csharp\SlotPose.cs + spine-csharp\TextureRegion.cs + spine-csharp\TransformConstraint.cs + spine-csharp\TransformConstraintData.cs + spine-csharp\TransformConstraintPose.cs + spine-csharp\Triangulator.cs + + + spine-csharp\Attachments\AtlasAttachmentLoader.cs + spine-csharp\Attachments\Attachment.cs + spine-csharp\Attachments\AttachmentLoader.cs + spine-csharp\Attachments\AttachmentType.cs + spine-csharp\Attachments\BoundingBoxAttachment.cs + spine-csharp\Attachments\ClippingAttachment.cs + spine-csharp\Attachments\IHasTextureRegion.cs + spine-csharp\Attachments\MeshAttachment.cs + spine-csharp\Attachments\PathAttachment.cs + spine-csharp\Attachments\PointAttachment.cs + spine-csharp\Attachments\RegionAttachment.cs + spine-csharp\Attachments\Sequence.cs + spine-csharp\Attachments\VertexAttachment.cs @@ -203,9 +130,6 @@ spine-csharp\IkConstraintData.cs.meta - - spine-csharp\IUpdatable.cs.meta - spine-csharp\Json.cs.meta diff --git a/spine-monogame/spine-monogame/src/SkeletonDebugRenderer.cs b/spine-monogame/spine-monogame/src/SkeletonDebugRenderer.cs index 2b54665a8..5bdfbea95 100644 --- a/spine-monogame/spine-monogame/src/SkeletonDebugRenderer.cs +++ b/spine-monogame/spine-monogame/src/SkeletonDebugRenderer.cs @@ -107,9 +107,10 @@ namespace Spine { for (int i = 0, n = bones.Count; i < n; i++) { var bone = bones.Items[i]; if (bone.Parent == null) continue; - var x = bone.Data.Length * bone.A + bone.WorldX; - var y = bone.Data.Length * bone.C + bone.WorldY; - renderer.Line(bone.WorldX, bone.WorldY, x, y, z); + BonePose bonePose = bone.AppliedPose; + var x = bone.Data.Length * bonePose.A + bonePose.WorldX; + var y = bone.Data.Length * bonePose.C + bonePose.WorldY; + renderer.Line(bonePose.WorldX, bonePose.WorldY, x, y, z); } if (DrawSkeletonXY) renderer.X(skeletonX, skeletonY, 4, z); } @@ -119,7 +120,7 @@ namespace Spine { var slots = skeleton.Slots; for (int i = 0, n = slots.Count; i < n; i++) { var slot = slots.Items[i]; - var attachment = slot.Attachment; + var attachment = slot.AppliedPose.Attachment; if (attachment is RegionAttachment) { var regionAttachment = (RegionAttachment)attachment; var vertices = this.vertices; @@ -136,11 +137,11 @@ namespace Spine { var slots = skeleton.Slots; for (int i = 0, n = slots.Count; i < n; i++) { var slot = slots.Items[i]; - var attachment = slot.Attachment; + var attachment = slot.AppliedPose.Attachment; if (!(attachment is MeshAttachment)) continue; var mesh = (MeshAttachment)attachment; var world = vertices = vertices.Length < mesh.WorldVerticesLength ? new float[mesh.WorldVerticesLength] : vertices; - mesh.ComputeWorldVertices(slot, 0, mesh.WorldVerticesLength, world, 0, 2); + mesh.ComputeWorldVertices(skeleton, slot, 0, mesh.WorldVerticesLength, world, 0, 2); int[] triangles = mesh.Triangles; var hullLength = mesh.HullLength; if (DrawMeshTriangles) { @@ -184,8 +185,9 @@ namespace Spine { if (DrawBones) { renderer.SetColor(boneOriginColor); for (int i = 0, n = bones.Count; i < n; i++) { - var bone = bones.Items[i]; - renderer.Circle(bone.WorldX, bone.WorldY, 3, z); + Bone bone = bones.Items[i]; + BonePose bonePose = bone.AppliedPose; + renderer.Circle(bonePose.WorldX, bonePose.WorldY, 3, z); } } @@ -194,12 +196,12 @@ namespace Spine { renderer.SetColor(clipColor); for (int i = 0, n = slots.Count; i < n; i++) { var slot = slots.Items[i]; - var attachment = slot.Attachment; + var attachment = slot.AppliedPose.Attachment; if (!(attachment is ClippingAttachment)) continue; var clip = (ClippingAttachment)attachment; var nn = clip.WorldVerticesLength; var world = vertices = vertices.Length < nn ? new float[nn] : vertices; - clip.ComputeWorldVertices(slot, 0, nn, world, 0, 2); + clip.ComputeWorldVertices(skeleton, slot, 0, nn, world, 0, 2); ExposedList clippingPolygon = new ExposedList(); for (int ii = 0; ii < nn; ii += 2) { var x = world[ii]; diff --git a/spine-monogame/spine-monogame/src/SkeletonRenderer.cs b/spine-monogame/spine-monogame/src/SkeletonRenderer.cs index 8698813d3..8e79e1e2d 100644 --- a/spine-monogame/spine-monogame/src/SkeletonRenderer.cs +++ b/spine-monogame/spine-monogame/src/SkeletonRenderer.cs @@ -114,22 +114,24 @@ namespace Spine { public void Draw (Skeleton skeleton) { var drawOrder = skeleton.DrawOrder; var drawOrderItems = skeleton.DrawOrder.Items; - float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A; - Color color = new Color(); + Color32F skeletonColor = skeleton.GetColor(); if (VertexEffect != null) VertexEffect.Begin(skeleton); for (int i = 0, n = drawOrder.Count; i < n; i++) { Slot slot = drawOrderItems[i]; + SlotPose slotPose = slot.AppliedPose; if (!slot.Bone.Active) { clipper.ClipEnd(slot); continue; } - Attachment attachment = slot.Attachment; + Attachment attachment = slotPose.Attachment; float attachmentZOffset = z + zSpacing * i; - float attachmentColorR, attachmentColorG, attachmentColorB, attachmentColorA; + Color32F attachmentColor; + Color32F slotColor = slotPose.GetColor(); + Color color; object textureObject = null; int verticesCount = 0; float[] vertices = this.vertices; @@ -139,7 +141,7 @@ namespace Spine { if (attachment is RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; - attachmentColorR = regionAttachment.R; attachmentColorG = regionAttachment.G; attachmentColorB = regionAttachment.B; attachmentColorA = regionAttachment.A; + attachmentColor = regionAttachment.GetColor(); regionAttachment.ComputeWorldVertices(slot, vertices, 0, 2); verticesCount = 4; indicesCount = 6; @@ -149,11 +151,11 @@ namespace Spine { textureObject = region.page.rendererObject; } else if (attachment is MeshAttachment) { MeshAttachment mesh = (MeshAttachment)attachment; - attachmentColorR = mesh.R; attachmentColorG = mesh.G; attachmentColorB = mesh.B; attachmentColorA = mesh.A; + attachmentColor = mesh.GetColor(); int vertexCount = mesh.WorldVerticesLength; if (vertices.Length < vertexCount) this.vertices = vertices = new float[vertexCount]; verticesCount = vertexCount >> 1; - mesh.ComputeWorldVertices(slot, vertices); + mesh.ComputeWorldVertices(skeleton, slot, vertices); indicesCount = mesh.Triangles.Length; indices = mesh.Triangles; uvs = mesh.UVs; @@ -161,7 +163,7 @@ namespace Spine { textureObject = region.page.rendererObject; } else if (attachment is ClippingAttachment) { ClippingAttachment clip = (ClippingAttachment)attachment; - clipper.ClipStart(slot, clip); + clipper.ClipStart(skeleton, slot, clip); continue; } else { clipper.ClipEnd(slot); @@ -187,25 +189,25 @@ namespace Spine { } // calculate color - float a = skeletonA * slot.A * attachmentColorA; + Color32F combinedColor = skeletonColor * slotColor * attachmentColor; + float a = combinedColor.a; if (premultipliedAlpha) { color = new Color( - skeletonR * slot.R * attachmentColorR * a, - skeletonG * slot.G * attachmentColorG * a, - skeletonB * slot.B * attachmentColorB * a, a); + combinedColor.r * a, + combinedColor.g * a, + combinedColor.b * a, a); } else { - color = new Color( - skeletonR * slot.R * attachmentColorR, - skeletonG * slot.G * attachmentColorG, - skeletonB * slot.B * attachmentColorB, a); + color = combinedColor; } Color darkColor = new Color(); - if (slot.HasSecondColor) { + Color32F? slotDarkColorOptional = slotPose.GetDarkColor(); + if (slotDarkColorOptional.HasValue) { + Color32F slotDarkColor = slotDarkColorOptional.Value; if (premultipliedAlpha) { - darkColor = new Color(slot.R2 * a, slot.G2 * a, slot.B2 * a); + darkColor = new Color(slotDarkColor.r * a, slotDarkColor.g * a, slotDarkColor.b * a); } else { - darkColor = new Color(slot.R2 * a, slot.G2 * a, slot.B2 * a); + darkColor = new Color(slotDarkColor.r * a, slotDarkColor.g * a, slotDarkColor.b * a); } } darkColor.A = premultipliedAlpha ? (byte)255 : (byte)0;