[unity] Fixed SpineVisualElement not rendering back-faces by providing a Flip Back Faces property (UI Elements). Closes #3016.

This commit is contained in:
Harald Csaszar 2026-01-27 12:41:26 +01:00
parent 092decd240
commit 663df0ec03
4 changed files with 34 additions and 2 deletions

View File

@ -1230,6 +1230,33 @@ namespace Spine.Unity {
}
}
}
public void FlipBackfaceWindingOrder () {
int submeshCount = submeshes.Count;
ExposedList<int>[] submeshesItems = submeshes.Items;
Vector3[] vertexPositions = vertexBuffer.Items;
for (int s = 0; s < submeshCount; ++s) {
ExposedList<int> submeshIndices = submeshesItems[s];
int indexCount = submeshIndices.Count;
int[] indices = submeshIndices.Items;
for (int i = 0; i < indexCount; i += 3) {
int iA = indices[i];
int iB = indices[i + 1];
int iC = indices[i + 2];
Vector3 a = vertexPositions[iA];
Vector3 b = vertexPositions[iB];
Vector3 c = vertexPositions[iC];
Vector2 d1 = new Vector2(b.x - a.x, b.y - a.y);
Vector2 d2 = new Vector2(c.x - b.x, c.y - b.y);
float z = d1.x * d2.y - d1.y * d2.x;
if (z < 0.0f) {
indices[i + 1] = iC;
indices[i + 2] = iB;
}
}
}
}
#endregion
#region Step 3 : Transfer vertex and triangle data to UnityEngine.Mesh

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.spine-unity",
"displayName": "spine-unity Runtime",
"description": "This plugin provides the spine-unity runtime core and examples. Spine Examples can be installed via the Samples tab.",
"version": "4.3.40",
"version": "4.3.41",
"unity": "2018.3",
"author": {
"name": "Esoteric Software",

View File

@ -95,6 +95,9 @@ namespace Spine.Unity {
}
public string initialSkinName;
/// <summary>Flip indices of back-faces to correct winding order during mesh generation.
/// UI Elements otherwise does not draw back-faces.</summary>
[UxmlAttribute] public bool flipBackFaces { get; set; } = true;
[UxmlAttribute] public bool startingLoop { get; set; } = true;
[UxmlAttribute] public float timeScale { get; set; } = 1.0f;
@ -335,6 +338,8 @@ namespace Spine.Unity {
// clipping is done, vertex counts are final.
PrepareUISubmesh(uiSubmesh, meshGenerator.VertexCount, meshGenerator.SubmeshIndexCount(0));
if (flipBackFaces)
meshGenerator.FlipBackfaceWindingOrder();
meshGenerator.FillVertexData(ref uiSubmesh.verticesSlice);
meshGenerator.FillTrianglesSingleSubmesh(ref uiSubmesh.indicesSlice);

View File

@ -2,7 +2,7 @@
"name": "com.esotericsoftware.spine.ui-toolkit",
"displayName": "Spine UI Toolkit [Experimental]",
"description": "This plugin provides UI Toolkit integration for the spine-unity runtime.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 4.3.0 or newer and Unity 6000.0.16 or newer (requires [this bugfix](https://issuetracker.unity3d.com/issues/some-default-uxmlconverters-are-dependent-on-the-current-culture)).\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)",
"version": "4.3.0-preview.3",
"version": "4.3.0-preview.4",
"unity": "6000.0",
"author": {
"name": "Esoteric Software",