mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Null mesh cleanup fixed in SkeletonRenderer
Added "Front Facing" parameter to SkeletonRenderer
This commit is contained in:
parent
86a5b5289d
commit
c445d14f6e
@ -33,7 +33,7 @@ using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(SkeletonRenderer))]
|
||||
public class SkeletonRendererInspector : Editor {
|
||||
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, submeshSeparators;
|
||||
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, submeshSeparators, front;
|
||||
|
||||
protected virtual void OnEnable () {
|
||||
SpineEditorUtilities.ConfirmInitialization();
|
||||
@ -44,6 +44,7 @@ public class SkeletonRendererInspector : Editor {
|
||||
meshes = serializedObject.FindProperty("renderMeshes");
|
||||
immutableTriangles = serializedObject.FindProperty("immutableTriangles");
|
||||
submeshSeparators = serializedObject.FindProperty("submeshSeparators");
|
||||
front = serializedObject.FindProperty("frontFacing");
|
||||
}
|
||||
|
||||
protected virtual void gui () {
|
||||
@ -97,6 +98,7 @@ public class SkeletonRendererInspector : Editor {
|
||||
new GUIContent("Immutable Triangles", "Enable to optimize rendering for skeletons that never change attachment visbility"));
|
||||
EditorGUILayout.PropertyField(normals);
|
||||
EditorGUILayout.PropertyField(tangents);
|
||||
EditorGUILayout.PropertyField(front);
|
||||
EditorGUILayout.PropertyField(submeshSeparators, true);
|
||||
}
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
public bool calculateNormals, calculateTangents;
|
||||
public float zSpacing;
|
||||
public bool renderMeshes = true, immutableTriangles;
|
||||
public bool frontFacing;
|
||||
public bool logErrors = false;
|
||||
|
||||
[SpineSlot]
|
||||
@ -114,6 +115,11 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
submeshSeparatorSlots.Add(skeleton.FindSlot(submeshSeparators[i]));
|
||||
}
|
||||
|
||||
|
||||
// Store flipped triangles for meshes
|
||||
|
||||
|
||||
|
||||
if (OnReset != null)
|
||||
OnReset(this);
|
||||
}
|
||||
@ -125,10 +131,16 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
|
||||
public virtual void OnDisable() {
|
||||
if (Application.isPlaying && gameObject.activeInHierarchy == false) {
|
||||
if (mesh1 != null)
|
||||
if (mesh1 != null) {
|
||||
Destroy(mesh1);
|
||||
if (mesh2 != null)
|
||||
mesh1 = null;
|
||||
}
|
||||
|
||||
if (mesh2 != null) {
|
||||
Destroy(mesh2);
|
||||
mesh2 = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -369,12 +381,13 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
submesh.triangleCount = 0;
|
||||
}
|
||||
|
||||
if (!renderMeshes) {
|
||||
if (!renderMeshes && !frontFacing) {
|
||||
// Use stored triangles if possible.
|
||||
if (submesh.firstVertex != firstVertex || submesh.triangleCount < triangleCount) {
|
||||
submesh.triangleCount = triangleCount;
|
||||
submesh.firstVertex = firstVertex;
|
||||
for (int i = 0; i < triangleCount; i += 6, firstVertex += 4) {
|
||||
int drawOrderIndex = 0;
|
||||
for (int i = 0; i < triangleCount; i += 6, firstVertex += 4, drawOrderIndex++) {
|
||||
triangles[i] = firstVertex;
|
||||
triangles[i + 1] = firstVertex + 2;
|
||||
triangles[i + 2] = firstVertex + 1;
|
||||
@ -389,14 +402,27 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
// Store triangles.
|
||||
List<Slot> drawOrder = skeleton.DrawOrder;
|
||||
for (int i = startSlot, triangleIndex = 0; i < endSlot; i++) {
|
||||
Attachment attachment = drawOrder[i].attachment;
|
||||
Slot slot = drawOrder[i];
|
||||
Attachment attachment = slot.attachment;
|
||||
bool flip = frontFacing && ((slot.Bone.WorldFlipX != slot.Bone.WorldFlipY) != (Mathf.Sign(slot.Bone.WorldScaleX) != Mathf.Sign(slot.bone.WorldScaleY)));
|
||||
|
||||
if (attachment is RegionAttachment) {
|
||||
if (!flip) {
|
||||
triangles[triangleIndex] = firstVertex;
|
||||
triangles[triangleIndex + 1] = firstVertex + 2;
|
||||
triangles[triangleIndex + 2] = firstVertex + 1;
|
||||
triangles[triangleIndex + 3] = firstVertex + 2;
|
||||
triangles[triangleIndex + 4] = firstVertex + 3;
|
||||
triangles[triangleIndex + 5] = firstVertex + 1;
|
||||
} else {
|
||||
triangles[triangleIndex] = firstVertex + 1;
|
||||
triangles[triangleIndex + 1] = firstVertex + 2;
|
||||
triangles[triangleIndex + 2] = firstVertex;
|
||||
triangles[triangleIndex + 3] = firstVertex + 1;
|
||||
triangles[triangleIndex + 4] = firstVertex + 3;
|
||||
triangles[triangleIndex + 5] = firstVertex + 2;
|
||||
}
|
||||
|
||||
triangleIndex += 6;
|
||||
firstVertex += 4;
|
||||
continue;
|
||||
@ -413,8 +439,19 @@ public class SkeletonRenderer : MonoBehaviour {
|
||||
attachmentTriangles = meshAttachment.triangles;
|
||||
} else
|
||||
continue;
|
||||
for (int ii = 0, nn = attachmentTriangles.Length; ii < nn; ii++, triangleIndex++)
|
||||
|
||||
if (flip) {
|
||||
for (int ii = 0, nn = attachmentTriangles.Length; ii < nn; ii += 3, triangleIndex += 3) {
|
||||
triangles[triangleIndex + 2] = firstVertex + attachmentTriangles[ii];
|
||||
triangles[triangleIndex + 1] = firstVertex + attachmentTriangles[ii + 1];
|
||||
triangles[triangleIndex] = firstVertex + attachmentTriangles[ii + 2];
|
||||
}
|
||||
} else {
|
||||
for (int ii = 0, nn = attachmentTriangles.Length; ii < nn; ii++, triangleIndex++) {
|
||||
triangles[triangleIndex] = firstVertex + attachmentTriangles[ii];
|
||||
}
|
||||
}
|
||||
|
||||
firstVertex += attachmentVertexCount;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user