diff --git a/spine-tk2d/Assets/Spine/Editor/SkeletonAnimationInspector.cs b/spine-tk2d/Assets/Spine/Editor/SkeletonAnimationInspector.cs index 6524c387f..59320dfa4 100644 --- a/spine-tk2d/Assets/Spine/Editor/SkeletonAnimationInspector.cs +++ b/spine-tk2d/Assets/Spine/Editor/SkeletonAnimationInspector.cs @@ -28,7 +28,8 @@ using UnityEngine; [CustomEditor(typeof(SkeletonAnimation))] public class SkeletonAnimationInspector : Editor { - private SerializedProperty skeletonDataAsset, animationName, loop, useAnimationName, initialSkinName, timeScale; + private SerializedProperty skeletonDataAsset, initialSkinName, timeScale, normals, tangents; + private SerializedProperty animationName, loop, useAnimationName; void OnEnable () { skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); @@ -37,6 +38,8 @@ public class SkeletonAnimationInspector : Editor { useAnimationName = serializedObject.FindProperty("useAnimationName"); initialSkinName = serializedObject.FindProperty("initialSkinName"); timeScale = serializedObject.FindProperty("timeScale"); + normals = serializedObject.FindProperty("calculateNormals"); + tangents = serializedObject.FindProperty("calculateTangents"); } override public void OnInspectorGUI () { @@ -104,6 +107,8 @@ public class SkeletonAnimationInspector : Editor { EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(timeScale); + EditorGUILayout.PropertyField(normals); + EditorGUILayout.PropertyField(tangents); if (serializedObject.ApplyModifiedProperties() || (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") diff --git a/spine-tk2d/Assets/Spine/Editor/SkeletonComponentInspector.cs b/spine-tk2d/Assets/Spine/Editor/SkeletonComponentInspector.cs index cb23a1546..6d79063bf 100644 --- a/spine-tk2d/Assets/Spine/Editor/SkeletonComponentInspector.cs +++ b/spine-tk2d/Assets/Spine/Editor/SkeletonComponentInspector.cs @@ -28,12 +28,14 @@ using UnityEngine; [CustomEditor(typeof(SkeletonComponent))] public class SkeletonComponentInspector : Editor { - private SerializedProperty skeletonDataAsset, initialSkinName, timeScale; + private SerializedProperty skeletonDataAsset, initialSkinName, timeScale, normals, tangents; void OnEnable () { skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); initialSkinName = serializedObject.FindProperty("initialSkinName"); timeScale = serializedObject.FindProperty("timeScale"); + normals = serializedObject.FindProperty("calculateNormals"); + tangents = serializedObject.FindProperty("calculateTangents"); } override public void OnInspectorGUI () { @@ -65,6 +67,8 @@ public class SkeletonComponentInspector : Editor { } EditorGUILayout.PropertyField(timeScale); + EditorGUILayout.PropertyField(normals); + EditorGUILayout.PropertyField(tangents); if (serializedObject.ApplyModifiedProperties() || (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") diff --git a/spine-tk2d/Assets/Spine/SkeletonComponent.cs b/spine-tk2d/Assets/Spine/SkeletonComponent.cs index 2ab63c07d..4c9fe7627 100644 --- a/spine-tk2d/Assets/Spine/SkeletonComponent.cs +++ b/spine-tk2d/Assets/Spine/SkeletonComponent.cs @@ -35,15 +35,18 @@ public class SkeletonComponent : MonoBehaviour { public Skeleton skeleton; public String initialSkinName; public float timeScale = 1; + public bool calculateNormals; + public bool calculateTangents; private Mesh mesh; + private float[] vertexPositions = new float[8]; private int lastVertexCount; private Vector3[] vertices; private Color32[] colors; private Vector2[] uvs; - private float[] vertexPositions = new float[8]; + private Material[] sharedMaterials = new Material[0]; private List submeshMaterials = new List(); private List submeshIndexes = new List(); - private Material[] sharedMaterials = new Material[0]; + private Vector4[] tangents = new Vector4[0]; public virtual void Clear () { GetComponent().mesh = null; @@ -80,6 +83,7 @@ public class SkeletonComponent : MonoBehaviour { public virtual void Update () { SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); + // Clear fields if missing information to render. if (skeletonDataAsset == null || skeletonData == null) { Clear(); @@ -180,9 +184,22 @@ public class SkeletonComponent : MonoBehaviour { mesh.vertices = vertices; mesh.colors32 = colors; mesh.uv = uvs; + mesh.subMeshCount = submeshMaterials.Count; for (int i = 0; i < mesh.subMeshCount; ++i) mesh.SetTriangles(submeshIndexes[i], i); + + if (calculateNormals) { + mesh.RecalculateNormals(); + if (calculateTangents) { + Vector4[] tangents = this.tangents; + int count = mesh.normals.Length; + if (tangents.Length != count) this.tangents = tangents = new Vector4[count]; + for (int i = 0; i < count; i++) + tangents[i] = new Vector4(1, 0, 0, 1); + mesh.tangents = tangents; + } + } } /** Adds a material. Adds submesh indexes if existing indexes aren't sufficient. */ diff --git a/spine-unity/Assets/Spine/Editor/SkeletonAnimationInspector.cs b/spine-unity/Assets/Spine/Editor/SkeletonAnimationInspector.cs index 362ebbf68..59320dfa4 100644 --- a/spine-unity/Assets/Spine/Editor/SkeletonAnimationInspector.cs +++ b/spine-unity/Assets/Spine/Editor/SkeletonAnimationInspector.cs @@ -22,14 +22,14 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ - using System; using UnityEditor; using UnityEngine; [CustomEditor(typeof(SkeletonAnimation))] public class SkeletonAnimationInspector : Editor { - private SerializedProperty skeletonDataAsset, animationName, loop, useAnimationName, initialSkinName, timeScale; + private SerializedProperty skeletonDataAsset, initialSkinName, timeScale, normals, tangents; + private SerializedProperty animationName, loop, useAnimationName; void OnEnable () { skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); @@ -38,6 +38,8 @@ public class SkeletonAnimationInspector : Editor { useAnimationName = serializedObject.FindProperty("useAnimationName"); initialSkinName = serializedObject.FindProperty("initialSkinName"); timeScale = serializedObject.FindProperty("timeScale"); + normals = serializedObject.FindProperty("calculateNormals"); + tangents = serializedObject.FindProperty("calculateTangents"); } override public void OnInspectorGUI () { @@ -54,7 +56,8 @@ public class SkeletonAnimationInspector : Editor { for (int i = 0; i < skins.Length - 1; i++) { String name = component.skeleton.Data.Skins[i].Name; skins[i] = name; - if (name == initialSkinName.stringValue) skinIndex = i; + if (name == initialSkinName.stringValue) + skinIndex = i; } EditorGUILayout.BeginHorizontal(); @@ -74,7 +77,8 @@ public class SkeletonAnimationInspector : Editor { for (int i = 0; i < animations.Length - 2; i++) { String name = component.skeleton.Data.Animations[i].Name; animations[i + 2] = name; - if (name == animationName.stringValue) animationIndex = i + 2; + if (name == animationName.stringValue) + animationIndex = i + 2; } EditorGUILayout.BeginHorizontal(); @@ -103,6 +107,8 @@ public class SkeletonAnimationInspector : Editor { EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(timeScale); + EditorGUILayout.PropertyField(normals); + EditorGUILayout.PropertyField(tangents); if (serializedObject.ApplyModifiedProperties() || (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") diff --git a/spine-unity/Assets/Spine/Editor/SkeletonComponentInspector.cs b/spine-unity/Assets/Spine/Editor/SkeletonComponentInspector.cs index e8746090d..6d79063bf 100644 --- a/spine-unity/Assets/Spine/Editor/SkeletonComponentInspector.cs +++ b/spine-unity/Assets/Spine/Editor/SkeletonComponentInspector.cs @@ -22,19 +22,20 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ - using System; using UnityEditor; using UnityEngine; [CustomEditor(typeof(SkeletonComponent))] public class SkeletonComponentInspector : Editor { - private SerializedProperty skeletonDataAsset, initialSkinName, timeScale; + private SerializedProperty skeletonDataAsset, initialSkinName, timeScale, normals, tangents; void OnEnable () { skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); initialSkinName = serializedObject.FindProperty("initialSkinName"); timeScale = serializedObject.FindProperty("timeScale"); + normals = serializedObject.FindProperty("calculateNormals"); + tangents = serializedObject.FindProperty("calculateTangents"); } override public void OnInspectorGUI () { @@ -51,7 +52,8 @@ public class SkeletonComponentInspector : Editor { for (int i = 0; i < skins.Length - 1; i++) { String name = component.skeleton.Data.Skins[i].Name; skins[i] = name; - if (name == initialSkinName.stringValue) skinIndex = i; + if (name == initialSkinName.stringValue) + skinIndex = i; } EditorGUILayout.BeginHorizontal(); @@ -65,6 +67,8 @@ public class SkeletonComponentInspector : Editor { } EditorGUILayout.PropertyField(timeScale); + EditorGUILayout.PropertyField(normals); + EditorGUILayout.PropertyField(tangents); if (serializedObject.ApplyModifiedProperties() || (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") diff --git a/spine-unity/Assets/Spine/SkeletonComponent.cs b/spine-unity/Assets/Spine/SkeletonComponent.cs index 28638a8d2..af6b43eb7 100644 --- a/spine-unity/Assets/Spine/SkeletonComponent.cs +++ b/spine-unity/Assets/Spine/SkeletonComponent.cs @@ -35,15 +35,18 @@ public class SkeletonComponent : MonoBehaviour { public Skeleton skeleton; public String initialSkinName; public float timeScale = 1; + public bool calculateNormals; + public bool calculateTangents; private Mesh mesh; + private float[] vertexPositions = new float[8]; private int lastVertexCount; private Vector3[] vertices; private Color32[] colors; private Vector2[] uvs; - private float[] vertexPositions = new float[8]; + private Material[] sharedMaterials = new Material[0]; private List submeshMaterials = new List(); private List submeshIndexes = new List(); - private Material[] sharedMaterials = new Material[0]; + private Vector4[] tangents = new Vector4[0]; public virtual void Clear () { GetComponent().mesh = null; @@ -59,9 +62,6 @@ public class SkeletonComponent : MonoBehaviour { mesh.name = "Skeleton Mesh"; mesh.hideFlags = HideFlags.HideAndDontSave; mesh.MarkDynamic(); - - // BOZO - //renderer.sharedMaterial = skeletonDataAsset.atlasAsset.material; vertices = new Vector3[0]; @@ -80,6 +80,7 @@ public class SkeletonComponent : MonoBehaviour { public virtual void Update () { SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); + // Clear fields if missing information to render. if (skeletonDataAsset == null || skeletonData == null) { Clear(); @@ -180,9 +181,22 @@ public class SkeletonComponent : MonoBehaviour { mesh.vertices = vertices; mesh.colors32 = colors; mesh.uv = uvs; + mesh.subMeshCount = submeshMaterials.Count; for (int i = 0; i < mesh.subMeshCount; ++i) mesh.SetTriangles(submeshIndexes[i], i); + + if (calculateNormals) { + mesh.RecalculateNormals(); + if (calculateTangents) { + Vector4[] tangents = this.tangents; + int count = mesh.normals.Length; + if (tangents.Length != count) this.tangents = tangents = new Vector4[count]; + for (int i = 0; i < count; i++) + tangents[i] = new Vector4(1, 0, 0, 1); + mesh.tangents = tangents; + } + } } /** Adds a material. Adds submesh indexes if existing indexes aren't sufficient. */