├── .gitignore ├── .gradle └── 1.4 │ └── taskArtifacts │ ├── cache.properties │ └── cache.properties.lock ├── 2DSkeletalAnimation.pdf ├── Assets └── SpritesAndBones │ ├── Gizmos │ ├── Pose icon.png │ └── man_icon.png │ ├── LICENSE │ ├── Scripts │ ├── AnimationWindowUtils.cs │ ├── Bone.cs │ ├── ControlPoint.cs │ ├── ControlPoints.cs │ ├── Editor │ │ ├── AnimationCurvesCopier.cs │ │ ├── AnimationEventCopier.cs │ │ ├── AnimationHierarchyEditor.cs │ │ ├── AnimationToPNGMenu.cs │ │ ├── BakePoseEditor.cs │ │ ├── BoneEditor.cs │ │ ├── ControlPointEditor.cs │ │ ├── InverseKinematicsEditor.cs │ │ ├── MeshCreator.cs │ │ ├── PoseEditor.cs │ │ ├── RemapMeshesEditor.cs │ │ ├── ReplaceControlPointsInClip.cs │ │ ├── ReplaceSpritesInClip.cs │ │ ├── SkeletonEditor.cs │ │ ├── Skin2DEditor.cs │ │ ├── SortLayerExposedEditor.cs │ │ ├── SortLayerMaterialEditor.cs │ │ ├── SortingLayerDrawer.cs │ │ ├── SortingLayerHelper.cs │ │ └── Weightpainter.cs │ ├── Helper.cs │ ├── InverseKinematics.cs │ ├── Perspective2DSortMode.cs │ ├── Pose.cs │ ├── ScriptableObjectUtility.cs │ ├── Skeleton.cs │ ├── Skin2D.cs │ ├── SortingLayerAttribute.cs │ ├── SortingLayerExposed.cs │ ├── Triangulation │ │ ├── Polygon │ │ │ ├── Polygon.cs │ │ │ ├── PolygonPoint.cs │ │ │ └── PolygonSet.cs │ │ ├── Triangle.NET │ │ │ ├── MeshRenderer.Core │ │ │ │ ├── BoundingBox.cs │ │ │ │ ├── ColorManager.cs │ │ │ │ ├── ExtensionMethods.cs │ │ │ │ ├── GDI │ │ │ │ │ ├── RenderControl.cs │ │ │ │ │ ├── TMeshRenderer.cs │ │ │ │ │ └── VoronoiRenderer.cs │ │ │ │ ├── IMeshRenderer.cs │ │ │ │ ├── RenderData.cs │ │ │ │ ├── RenderManager.cs │ │ │ │ └── Zoom.cs │ │ │ ├── Triangle │ │ │ │ ├── Algorithm │ │ │ │ │ ├── Dwyer.cs │ │ │ │ │ ├── ITriangulator.cs │ │ │ │ │ ├── Incremental.cs │ │ │ │ │ └── SweepLine.cs │ │ │ │ ├── BadTriQueue.cs │ │ │ │ ├── Behavior.cs │ │ │ │ ├── Carver.cs │ │ │ │ ├── Data │ │ │ │ │ ├── BadSubseg.cs │ │ │ │ │ ├── BadTriangle.cs │ │ │ │ │ ├── Osub.cs │ │ │ │ │ ├── Otri.cs │ │ │ │ │ ├── Segment.cs │ │ │ │ │ ├── Triangle.cs │ │ │ │ │ └── Vertex.cs │ │ │ │ ├── Enums.cs │ │ │ │ ├── Geometry │ │ │ │ │ ├── BoundingBox.cs │ │ │ │ │ ├── Edge.cs │ │ │ │ │ ├── EdgeEnumerator.cs │ │ │ │ │ ├── ISegment.cs │ │ │ │ │ ├── ITriangle.cs │ │ │ │ │ ├── InputGeometry.cs │ │ │ │ │ ├── Point.cs │ │ │ │ │ └── RegionPointer.cs │ │ │ │ ├── IO │ │ │ │ │ ├── DataReader.cs │ │ │ │ │ ├── DebugWriter.cs │ │ │ │ │ ├── FileReader.cs │ │ │ │ │ ├── FileWriter.cs │ │ │ │ │ ├── IGeometryFormat.cs │ │ │ │ │ ├── IMeshFormat.cs │ │ │ │ │ ├── InputTriangle.cs │ │ │ │ │ └── TriangleFormat.cs │ │ │ │ ├── Log │ │ │ │ │ ├── ILog.cs │ │ │ │ │ ├── ILogItem.cs │ │ │ │ │ ├── SimpleLog.cs │ │ │ │ │ └── SimpleLogItem.cs │ │ │ │ ├── Mesh.cs │ │ │ │ ├── NewLocation.cs │ │ │ │ ├── Primitives.cs │ │ │ │ ├── Properties │ │ │ │ │ └── AssemblyInfo.cs │ │ │ │ ├── Quality.cs │ │ │ │ ├── Sampler.cs │ │ │ │ ├── Smoothing │ │ │ │ │ ├── ISmoother.cs │ │ │ │ │ └── SimpleSmoother.cs │ │ │ │ ├── Tools │ │ │ │ │ ├── AdjacencyMatrix.cs │ │ │ │ │ ├── BoundedVoronoi.cs │ │ │ │ │ ├── CuthillMcKee.cs │ │ │ │ │ ├── IVoronoi.cs │ │ │ │ │ ├── QuadTree.cs │ │ │ │ │ ├── QualityMeasure.cs │ │ │ │ │ ├── RegionIterator.cs │ │ │ │ │ ├── Statistic.cs │ │ │ │ │ ├── Voronoi.cs │ │ │ │ │ └── VoronoiRegion.cs │ │ │ │ └── TriangleLocator.cs │ │ │ └── TriangleNetExtensions.cs │ │ ├── Triangulation │ │ │ ├── Delaunay │ │ │ │ ├── DelaunayTriangle.cs │ │ │ │ └── Sweep │ │ │ │ │ ├── AdvancingFront.cs │ │ │ │ │ ├── AdvancingFrontNode.cs │ │ │ │ │ ├── DTSweep.cs │ │ │ │ │ ├── DTSweepBasin.cs │ │ │ │ │ ├── DTSweepConstraint.cs │ │ │ │ │ ├── DTSweepContext.cs │ │ │ │ │ ├── DTSweepDebugContext.cs │ │ │ │ │ ├── DTSweepEdgeEvent.cs │ │ │ │ │ ├── DTSweepPointComparator.cs │ │ │ │ │ └── PointOnEdgeException.cs │ │ │ ├── ITriangulatable.cs │ │ │ ├── Orientation.cs │ │ │ ├── Sets │ │ │ │ ├── ConstrainedPointSet.cs │ │ │ │ └── PointSet.cs │ │ │ ├── TriangulationAlgorithm.cs │ │ │ ├── TriangulationConstraint.cs │ │ │ ├── TriangulationContext.cs │ │ │ ├── TriangulationDebugContext.cs │ │ │ ├── TriangulationMode.cs │ │ │ ├── TriangulationPoint.cs │ │ │ ├── TriangulationUtil.cs │ │ │ └── Util │ │ │ │ ├── PointGenerator.cs │ │ │ │ └── PolygonGenerator.cs │ │ └── Utility │ │ │ ├── FixedArray3.cs │ │ │ └── FixedBitArray3.cs │ └── Utils │ │ ├── AnimationToPNG.cs │ │ ├── BitmapHelper.cs │ │ ├── Bone2DWeight.cs │ │ ├── HSBColor.cs │ │ ├── MeshHelper.cs │ │ ├── PolygonMesh.cs │ │ ├── SimplifyTools.cs │ │ ├── SpriteMesh.cs │ │ ├── Triangulator.cs │ │ ├── Utils.cs │ │ └── Vertices.cs │ ├── Shader │ ├── LinesColoredBlended.shader │ ├── Sprites-Skeleton-Cutout.shader │ └── Sprites-Skeleton-Diffuse.shader │ ├── Textures │ ├── orc.png │ ├── sintel_tpose.png │ ├── spock_body.png │ └── spock_head.png │ └── license-attributions.txt ├── Bones.userprefs ├── LICENSE ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset ├── README.md ├── UnitySpritesAndBones.userprefs ├── build.gradle └── gradle.properties /.gitignore: -------------------------------------------------------------------------------- 1 | *.meta 2 | Temp/ 3 | *.csproj 4 | *.sln 5 | *.suo 6 | obj/ 7 | Library/ 8 | Assets/AssetStoreTools/ 9 | Gizmos/ 10 | Assets/GitSharp/ 11 | .gradle/ 12 | build/ -------------------------------------------------------------------------------- /.gradle/1.4/taskArtifacts/cache.properties: -------------------------------------------------------------------------------- 1 | #Sun Jan 26 10:25:29 CET 2014 2 | -------------------------------------------------------------------------------- /.gradle/1.4/taskArtifacts/cache.properties.lock: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /2DSkeletalAnimation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/2DSkeletalAnimation.pdf -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Gizmos/Pose icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/Assets/SpritesAndBones/Gizmos/Pose icon.png -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Gizmos/man_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/Assets/SpritesAndBones/Gizmos/man_icon.png -------------------------------------------------------------------------------- /Assets/SpritesAndBones/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Banbury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/AnimationWindowUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Banbury 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using UnityEngine; 25 | #if UNITY_EDITOR 26 | using UnityEditor; 27 | #endif 28 | using System; 29 | using System.Collections; 30 | using System.Collections.Generic; 31 | using System.Reflection; 32 | 33 | public static class AnimationWindowUtils { 34 | #if UNITY_EDITOR 35 | public static Assembly GetUnityEditorAssembly () 36 | { 37 | return typeof(AnimationUtility).Assembly; 38 | } 39 | 40 | 41 | public static object GetAnimationWindow() { 42 | Type animationWindow = GetUnityEditorAssembly().GetType("UnityEditor.AnimationWindow"); 43 | MethodInfo mi = animationWindow.GetMethod("GetAllAnimationWindows", BindingFlags.Static | BindingFlags.Public); 44 | IEnumerable windows = (IEnumerable)mi.Invoke(null, null); 45 | if (windows != null) { 46 | IEnumerator enu = windows.GetEnumerator(); 47 | if (enu.MoveNext()) { 48 | return enu.Current; 49 | } 50 | } 51 | return null; 52 | } 53 | 54 | public static float GetCurrentTime(object animationWindow) { 55 | Type animationWindowType = GetUnityEditorAssembly().GetType("UnityEditor.AnimationWindow"); 56 | PropertyInfo pi = animationWindowType.GetProperty("time"); 57 | return (float)pi.GetValue(animationWindow, null); 58 | } 59 | 60 | public static string GetPath(this Transform current) { 61 | if (current.parent == null) 62 | return "/" + current.name; 63 | return current.parent.GetPath() + "/" + current.name; 64 | } 65 | 66 | public static string GetPath(this Component component) { 67 | return component.transform.GetPath() + "/" + component.GetType().ToString(); 68 | } 69 | 70 | public static string GetPath(this GameObject gameObject) { 71 | return gameObject.transform.GetPath(); 72 | } 73 | #endif 74 | } 75 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/AnimationToPNGMenu.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | public class AnimationToPNGMenu { 6 | [MenuItem("Sprites And Bones/Animation To PNG")] 7 | public static void Create() { 8 | GameObject o = new GameObject("Animation To PNG"); 9 | Undo.RegisterCreatedObjectUndo(o, "Create skeleton"); 10 | o.AddComponent(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/BoneEditor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Banbury & Play-Em 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEditor; 27 | using System.Collections; 28 | 29 | [CustomEditor(typeof(Bone))] 30 | public class BoneEditor : Editor { 31 | private Bone bone; 32 | 33 | void OnEnable() { 34 | bone = (Bone)target; 35 | } 36 | 37 | public override void OnInspectorGUI() { 38 | DrawDefaultInspector(); 39 | 40 | EditorGUILayout.Separator(); 41 | if (GUILayout.Button("FlipY") && !bone.editMode) { 42 | bone.flipY = !bone.flipY; 43 | } 44 | else if(bone.editMode) { 45 | EditorGUILayout.HelpBox("Need to uncheck Edit in skeleton.", MessageType.Error); 46 | } 47 | 48 | if (GUILayout.Button("FlipX") && !bone.editMode) { 49 | bone.flipX = !bone.flipX; 50 | } 51 | else if (bone.editMode){ 52 | EditorGUILayout.HelpBox("Need to uncheck Edit in skeleton.", MessageType.Error); 53 | } 54 | EditorGUILayout.Separator(); 55 | 56 | GUILayout.BeginHorizontal(); 57 | 58 | if (GUILayout.Button("Add child")) { 59 | Bone.Create(); 60 | } 61 | if (GUILayout.Button("Split")) { 62 | Bone.Split(); 63 | } 64 | if (GUILayout.Button("Add IK")) { 65 | bone.AddIK(); 66 | } 67 | 68 | GUILayout.EndHorizontal(); 69 | } 70 | 71 | void OnSceneGUI() { 72 | Handles.color = Color.green; 73 | 74 | if (bone.editMode) { 75 | Event current = Event.current; 76 | 77 | if (bone.enabled && !current.control) { 78 | EditorGUI.BeginChangeCheck(); 79 | Vector3 v = Handles.FreeMoveHandle(bone.Head, Quaternion.identity, 0.1f, Vector3.zero, Handles.RectangleHandleCap); 80 | Undo.RecordObject(bone.transform, "Change bone transform"); 81 | Undo.RecordObject(bone, "Change bone"); 82 | bone.length = Vector2.Distance(v, bone.transform.position); 83 | bone.transform.up = (v - bone.transform.position).normalized; 84 | if (EditorGUI.EndChangeCheck()) { 85 | EditorUtility.SetDirty(bone); 86 | } 87 | } 88 | 89 | int controlID = GUIUtility.GetControlID(FocusType.Passive); 90 | 91 | if (current.control) { 92 | switch (current.GetTypeForControl(controlID)) { 93 | case EventType.MouseDown: 94 | current.Use(); 95 | break; 96 | case EventType.MouseUp: 97 | Undo.FlushUndoRecordObjects(); 98 | Bone b = Bone.Create(); 99 | Selection.activeGameObject = b.gameObject; 100 | 101 | Vector3 p = HandleUtility.GUIPointToWorldRay(current.mousePosition).origin; 102 | p = new Vector3(p.x, p.y); 103 | b.length = Vector3.Distance(p, bone.Head); 104 | b.transform.up = p - (Vector3)bone.Head; 105 | 106 | Event.current.Use(); 107 | break; 108 | case EventType.Layout: 109 | HandleUtility.AddDefaultControl(controlID); 110 | break; 111 | } 112 | } 113 | if (Event.current.control && Event.current.type == EventType.mouseDown) { 114 | } 115 | } 116 | else { 117 | var ik = bone.GetComponent(); 118 | if (bone.transform.parent != null && (ik == null || !ik.enabled || ik.influence == 0) && bone.snapToParent) { 119 | Transform parent = bone.transform.parent; 120 | float length = Vector2.Distance(parent.position, bone.transform.position); 121 | 122 | Bone parentBone = parent.GetComponent(); 123 | 124 | if (parentBone != null && Mathf.Abs(parentBone.length - length) > 0.0001) { 125 | bone.transform.parent = null; 126 | parent.up = (bone.transform.position - parent.position).normalized; 127 | parentBone.length = length; 128 | bone.transform.parent = parent; 129 | } 130 | } 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/ControlPointEditor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Play-Em 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEditor; 27 | using System.Collections; 28 | 29 | [CanEditMultipleObjects] 30 | [CustomEditor(typeof(ControlPoint))] 31 | public class ControlPointEditor : Editor { 32 | public override void OnInspectorGUI() { 33 | ControlPoint controlPoint = (ControlPoint)target; 34 | 35 | DrawDefaultInspector(); 36 | 37 | EditorGUILayout.Separator(); 38 | 39 | if (GUILayout.Button("Reset Position")) { 40 | controlPoint.ResetPosition(); 41 | } 42 | 43 | EditorGUILayout.Separator(); 44 | 45 | if (GUILayout.Button("Reset Name")) { 46 | controlPoint.Rename(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/InverseKinematicsEditor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 - 2015 Banbury & Play-Em & SirKurt 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | using UnityEditor; 27 | using System.Collections; 28 | 29 | [InitializeOnLoad] 30 | [CustomEditor(typeof(InverseKinematics))] 31 | public class InverseKinematicsEditor : Editor { 32 | 33 | private InverseKinematics ik; 34 | 35 | static InverseKinematicsEditor () 36 | { 37 | SceneView.onSceneGUIDelegate += OnScene; 38 | } 39 | 40 | void OnEnable() { 41 | ik = (InverseKinematics)target; 42 | } 43 | 44 | public override void OnInspectorGUI() { 45 | DrawDefaultInspector(); 46 | 47 | if (GUILayout.Button("Create Target Helper")) { 48 | CreateHelper(); 49 | } 50 | 51 | if (((InverseKinematics)target).target == null) { 52 | EditorGUILayout.HelpBox("Please select a target.", MessageType.Error); 53 | } 54 | } 55 | 56 | // [DrawGizmo(GizmoType.SelectedOrChild | GizmoType.NotSelected)] 57 | // static void DrawIKGizmo(InverseKinematics ik, GizmoType gizmoType) { 58 | // Handles.Label(ik.transform.position + new Vector3(0.1f, 0), "IK"); 59 | // } 60 | 61 | //Create a Helper for the IK Component and sets it as the IK's Target 62 | private void CreateHelper(){ 63 | //Create the Helper GameObject named after the bone 64 | GameObject o = new GameObject (ik.name + "_IK"); 65 | Undo.RegisterCreatedObjectUndo (o, "Create helper"); 66 | o.AddComponent(); 67 | o.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f); 68 | 69 | //set the helpers position to match the bones position 70 | Bone b = ik.GetComponent(); 71 | if (b != null) { 72 | o.transform.position = b.Head; 73 | } 74 | else { 75 | o.transform.position = ik.transform.position; 76 | } 77 | 78 | //set the helper as a child of the skeleton 79 | o.transform.parent = ik.skeleton.transform; 80 | 81 | //set the helper as the target 82 | ik.target = o.transform; 83 | 84 | //selects the transform of the Helper 85 | Selection.activeTransform = o.transform; 86 | } 87 | 88 | //Angle Limit code adapted from Veli-Pekka Kokkonen's SimpleCCDEditor http://goo.gl/6oSzDx 89 | 90 | // Scales scene view gizmo, feel free to change ;) 91 | const float gizmoSize = 0.5f; 92 | 93 | static void OnScene(SceneView sceneview) 94 | { 95 | var targets = GameObject.FindObjectsOfType(); 96 | 97 | foreach (var target in targets) 98 | { 99 | if (Selection.activeGameObject != null) 100 | { 101 | if (target.gameObject.Equals(Selection.activeGameObject)) 102 | { 103 | foreach (var node in target.angleLimits) 104 | { 105 | if (node.Transform == null) 106 | continue; 107 | 108 | Transform transform = node.Transform; 109 | Vector3 position = transform.position; 110 | 111 | float handleSize = HandleUtility.GetHandleSize(position); 112 | float discSize = handleSize * gizmoSize; 113 | 114 | 115 | Bone pb = transform.parent.GetComponent(); 116 | float parentRotation = pb ? pb.transform.eulerAngles.z : 0; 117 | 118 | Vector3 from = Quaternion.Euler(0, 0, Mathf.Min(node.from, node.to) + parentRotation) * Vector3.up; 119 | Vector3 to = Quaternion.Euler(0, 0, Mathf.Max(node.from, node.to) + parentRotation) * Vector3.up; 120 | 121 | Handles.color = new Color(0, 1, 0, 0.1f); 122 | Handles.DrawWireDisc(position, Vector3.back, discSize); 123 | Handles.DrawSolidArc(position, Vector3.forward, (node.from < node.to) ? from : to, (360 + node.to - node.from) % 360, discSize); 124 | 125 | Handles.color = Color.green; 126 | Handles.DrawLine(position, position + from * discSize); 127 | Handles.DrawLine(position, position + to * discSize); 128 | 129 | Vector3 toChild = transform.rotation * Vector3.up; 130 | Handles.DrawLine(position, position + toChild * discSize); 131 | } 132 | } 133 | } 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/PoseEditor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Banbury 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using UnityEngine; 25 | using UnityEditor; 26 | using System; 27 | using System.Collections; 28 | using System.Collections.Generic; 29 | 30 | [CustomEditor(typeof(Pose))] 31 | public class PoseEditor : Editor { 32 | private Skeleton previewSkeleton = null; 33 | 34 | public override void OnInspectorGUI() { 35 | DrawDefaultInspector(); 36 | GUILayout.Label("Rotations: " + ((Pose)target).rotations.Length); 37 | } 38 | 39 | public override bool HasPreviewGUI() { 40 | return true; 41 | } 42 | 43 | public override void OnPreviewGUI(Rect r, GUIStyle background) { 44 | Pose pose = (Pose)target; 45 | 46 | if (previewSkeleton != null) { 47 | var bones = previewSkeleton.GetComponentsInChildren(); 48 | 49 | GL.Begin(GL.LINES); 50 | 51 | foreach (Bone b in bones) { 52 | PositionValue pv = Array.Find(pose.positions, x => x.name == b.name); 53 | 54 | if (pv != null) { 55 | RotationValue rv = Array.Find(pose.rotations, x => x.name == b.name); 56 | 57 | Vector3 v = pv.position + (rv.rotation * new Vector3(0, 1, 0)) * b.length * 40; 58 | 59 | GL.Color(new Color(1, 0, 0, 1)); 60 | GL.Vertex(pv.position * 40 + (Vector3)r.center); 61 | GL.Vertex(v + (Vector3)r.center); 62 | } 63 | } 64 | 65 | GL.End(); 66 | } 67 | 68 | //GL.Begin(GL.LINES); 69 | 70 | //GameObject go = GameObject.Find("orc_3"); 71 | //SpriteRenderer sr = go.GetComponent(); 72 | //Texture2D tex = sr.sprite.texture; 73 | //Sprite spr = sr.sprite; 74 | //Rect source = new Rect(spr.rect.x / tex.width, spr.rect.y / tex.height, spr.rect.width / tex.width, spr.rect.height / tex.height); 75 | 76 | //GL.Color(Color.red); 77 | //GL.Vertex(new Vector3(r.x, r.y, 0)); 78 | //GL.Vertex(new Vector3(r.x + r.width, r.y + r.height, 0)); 79 | 80 | //GL.End(); 81 | //Graphics.DrawTexture(r, tex, source, 0, 0, 0, 0, sr.sharedMaterial); 82 | 83 | } 84 | 85 | public override void OnPreviewSettings() { 86 | previewSkeleton = (Skeleton)EditorGUILayout.ObjectField("Skeleton", previewSkeleton, typeof(Skeleton), true, null); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/RemapMeshesEditor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Play-Em 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using UnityEngine; 25 | #if UNITY_EDITOR 26 | using UnityEditor; 27 | using UnityEditorInternal; 28 | #endif 29 | using System; 30 | using System.Collections; 31 | 32 | public class RemapMeshesEditor : EditorWindow { 33 | [MenuItem("Sprites And Bones/Remap Meshes")] 34 | protected static void ShowRemapMeshesEditor() { 35 | var wnd = GetWindow(); 36 | wnd.titleContent.text = "Remap Meshes"; 37 | wnd.Show(); 38 | } 39 | 40 | private GameObject o; 41 | 42 | private bool remapMaterials = false; 43 | 44 | static public void Remap(GameObject o, bool remapMat) { 45 | #if UNITY_EDITOR 46 | Debug.Log("Remapping meshes for " + o.name); 47 | 48 | 49 | Skin2D[] children = o.GetComponentsInChildren(true); 50 | for(int i = 0; i < children.Length; i++) { 51 | if (children[i] != null) { 52 | children[i].AssignReferenceMesh(); 53 | 54 | if (children[i].skinnedMeshRenderer.sharedMesh == null 55 | && children[i].referenceMesh != null 56 | || children[i].skinnedMeshRenderer.sharedMesh != null 57 | && children[i].referenceMesh != null 58 | && children[i].skinnedMeshRenderer.sharedMesh != children[i].referenceMesh) { 59 | children[i].skinnedMeshRenderer.sharedMesh = children[i].referenceMesh; 60 | Debug.Log("Remapped " + children[i].skinnedMeshRenderer.sharedMesh.name); 61 | } 62 | if (remapMat) { 63 | children[i].AssignReferenceMaterial(); 64 | children[i].skinnedMeshRenderer.sharedMaterial = children[i].referenceMaterial; 65 | } 66 | } 67 | } 68 | #endif 69 | } 70 | 71 | public void OnGUI() { 72 | GUILayout.Label("Select a GameObject to remap Skin2D child meshes", EditorStyles.boldLabel); 73 | EditorGUILayout.Separator(); 74 | GUILayout.Label("GameObject", EditorStyles.boldLabel); 75 | 76 | EditorGUI.BeginChangeCheck(); 77 | 78 | if (Selection.activeGameObject != null) { 79 | o = Selection.activeGameObject; 80 | } 81 | EditorGUILayout.ObjectField(o, typeof(GameObject), true); 82 | EditorGUI.EndChangeCheck(); 83 | 84 | GUILayout.BeginHorizontal (); 85 | if (o != null) { 86 | if (GUILayout.Button("Remap Meshes")) { 87 | #if UNITY_EDITOR 88 | Remap(o, remapMaterials); 89 | #endif 90 | } 91 | remapMaterials = GUILayout.Toggle (remapMaterials, "Remap Materials"); 92 | } 93 | } 94 | 95 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/SortLayerExposedEditor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Nick Gravelyn. 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source 21 | * distribution. 22 | */ 23 | 24 | using System; 25 | using UnityEngine; 26 | using UnityEditor; 27 | 28 | namespace UnityToolbag 29 | { 30 | [CustomEditor(typeof(SortingLayerExposed))] 31 | public class SortingLayerExposedEditor : Editor 32 | { 33 | public override void OnInspectorGUI() 34 | { 35 | // Get the renderer from the target object 36 | var renderer = (target as SortingLayerExposed).gameObject.GetComponent(); 37 | 38 | // If there is no renderer, we can't do anything 39 | if (!renderer) { 40 | EditorGUILayout.HelpBox("SortingLayerExposed must be added to a game object that has a renderer.", MessageType.Error); 41 | return; 42 | } 43 | 44 | var sortingLayerNames = SortingLayerHelper.sortingLayerNames; 45 | 46 | // If we have the sorting layers array, we can make a nice dropdown. For stability's sake, if the array is null 47 | // we just use our old logic. This makes sure the script works in some fashion even if Unity changes the name of 48 | // that internal field we reflected. 49 | if (sortingLayerNames != null) { 50 | // Look up the layer name using the current layer ID 51 | string oldName = SortingLayerHelper.GetSortingLayerNameFromID(renderer.sortingLayerID); 52 | 53 | // Use the name to look up our array index into the names list 54 | int oldLayerIndex = Array.IndexOf(sortingLayerNames, oldName); 55 | 56 | // Show the popup for the names 57 | int newLayerIndex = EditorGUILayout.Popup("Sorting Layer", oldLayerIndex, sortingLayerNames); 58 | 59 | // If the index changes, look up the ID for the new index to store as the new ID 60 | if (newLayerIndex != oldLayerIndex) { 61 | Undo.RecordObject(renderer, "Edit Sorting Layer"); 62 | renderer.sortingLayerID = SortingLayerHelper.GetSortingLayerIDForIndex(newLayerIndex); 63 | EditorUtility.SetDirty(renderer); 64 | } 65 | } 66 | else { 67 | // Expose the sorting layer name 68 | string newSortingLayerName = EditorGUILayout.TextField("Sorting Layer Name", renderer.sortingLayerName); 69 | if (newSortingLayerName != renderer.sortingLayerName) { 70 | Undo.RecordObject(renderer, "Edit Sorting Layer Name"); 71 | renderer.sortingLayerName = newSortingLayerName; 72 | EditorUtility.SetDirty(renderer); 73 | } 74 | 75 | // Expose the sorting layer ID 76 | int newSortingLayerId = EditorGUILayout.IntField("Sorting Layer ID", renderer.sortingLayerID); 77 | if (newSortingLayerId != renderer.sortingLayerID) { 78 | Undo.RecordObject(renderer, "Edit Sorting Layer ID"); 79 | renderer.sortingLayerID = newSortingLayerId; 80 | EditorUtility.SetDirty(renderer); 81 | } 82 | } 83 | 84 | // Expose the manual sorting order 85 | int newSortingLayerOrder = EditorGUILayout.IntField("Sorting Layer Order", renderer.sortingOrder); 86 | if (newSortingLayerOrder != renderer.sortingOrder) { 87 | Undo.RecordObject(renderer, "Edit Sorting Order"); 88 | renderer.sortingOrder = newSortingLayerOrder; 89 | EditorUtility.SetDirty(renderer); 90 | } 91 | } 92 | } 93 | } 94 | 95 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/SortingLayerDrawer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Nick Gravelyn. 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source 21 | * distribution. 22 | */ 23 | 24 | using UnityEngine; 25 | using UnityEditor; 26 | using System; 27 | 28 | namespace UnityToolbag 29 | { 30 | [CustomPropertyDrawer(typeof(SortingLayerAttribute))] 31 | public class SortingLayerDrawer : PropertyDrawer 32 | { 33 | public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 34 | { 35 | var sortingLayerNames = SortingLayerHelper.sortingLayerNames; 36 | if (property.propertyType != SerializedPropertyType.Integer) { 37 | EditorGUI.HelpBox(position, string.Format("{0} is not an integer but has [SortingLayer].", property.name), MessageType.Error); 38 | } 39 | else if (sortingLayerNames != null) { 40 | EditorGUI.BeginProperty(position, label, property); 41 | 42 | // Look up the layer name using the current layer ID 43 | string oldName = SortingLayerHelper.GetSortingLayerNameFromID(property.intValue); 44 | 45 | // Use the name to look up our array index into the names list 46 | int oldLayerIndex = Array.IndexOf(sortingLayerNames, oldName); 47 | 48 | // Show the popup for the names 49 | int newLayerIndex = EditorGUI.Popup(position, label.text, oldLayerIndex, sortingLayerNames); 50 | 51 | // If the index changes, look up the ID for the new index to store as the new ID 52 | if (newLayerIndex != oldLayerIndex) { 53 | property.intValue = SortingLayerHelper.GetSortingLayerIDForIndex(newLayerIndex); 54 | } 55 | 56 | EditorGUI.EndProperty(); 57 | } 58 | else { 59 | EditorGUI.BeginProperty(position, label, property); 60 | int newValue = EditorGUI.IntField(position, label.text, property.intValue); 61 | if (newValue != property.intValue) { 62 | property.intValue = newValue; 63 | } 64 | EditorGUI.EndProperty(); 65 | } 66 | } 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Editor/SortingLayerHelper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Nick Gravelyn. 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source 21 | * distribution. 22 | */ 23 | 24 | using UnityEngine; 25 | using System; 26 | using System.Reflection; 27 | 28 | namespace UnityToolbag 29 | { 30 | // Helpers used by the different sorting layer classes. 31 | public static class SortingLayerHelper 32 | { 33 | private static Type _utilityType; 34 | private static PropertyInfo _sortingLayerNamesProperty; 35 | private static MethodInfo _getSortingLayerUserIdMethod; 36 | 37 | static SortingLayerHelper() 38 | { 39 | _utilityType = Type.GetType("UnityEditorInternal.InternalEditorUtility, UnityEditor"); 40 | _sortingLayerNamesProperty = _utilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); 41 | _getSortingLayerUserIdMethod = _utilityType.GetMethod("GetSortingLayerUserID", BindingFlags.Static | BindingFlags.NonPublic); 42 | } 43 | 44 | // Gets an array of sorting layer names. 45 | // Since this uses reflection, callers should check for 'null' which will be returned if the reflection fails. 46 | public static string[] sortingLayerNames 47 | { 48 | get 49 | { 50 | if (_sortingLayerNamesProperty == null) { 51 | return null; 52 | } 53 | 54 | return _sortingLayerNamesProperty.GetValue(null, null) as string[]; 55 | } 56 | } 57 | 58 | // Given the ID of a sorting layer, returns the sorting layer's name 59 | public static string GetSortingLayerNameFromID(int id) 60 | { 61 | string[] names = sortingLayerNames; 62 | if (names == null) { 63 | return null; 64 | } 65 | 66 | for (int i = 0; i < names.Length; i++) { 67 | if (GetSortingLayerIDForIndex(i) == id) { 68 | return names[i]; 69 | } 70 | } 71 | 72 | return null; 73 | } 74 | 75 | // Given the name of a sorting layer, returns the ID. 76 | public static int GetSortingLayerIDForName(string name) 77 | { 78 | string[] names = sortingLayerNames; 79 | if (names == null) { 80 | return 0; 81 | } 82 | 83 | return GetSortingLayerIDForIndex(Array.IndexOf(names, name)); 84 | } 85 | 86 | // Helper to convert from a sorting layer INDEX to a sorting layer ID. These are not the same thing. 87 | // IDs are based on the order in which layers were created and do not change when reordering the layers. 88 | // Thankfully there is a private helper we can call to get the ID for a layer given its index. 89 | public static int GetSortingLayerIDForIndex(int index) 90 | { 91 | if (_getSortingLayerUserIdMethod == null) { 92 | return 0; 93 | } 94 | 95 | return (int)_getSortingLayerUserIdMethod.Invoke(null, new object[] { index }); 96 | } 97 | } 98 | } 99 | 100 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Perspective2DSortMode.cs: -------------------------------------------------------------------------------- 1 | // Perspective2DSortMode.cs 2 | using UnityEngine; 3 | 4 | [RequireComponent(typeof(Camera))] 5 | [ExecuteInEditMode()] 6 | public class Perspective2DSortMode : MonoBehaviour { 7 | void Awake () { 8 | GetComponent().transparencySortMode = TransparencySortMode.Orthographic; 9 | } 10 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Pose.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Banbury & Play-Em 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using UnityEngine; 25 | using System; 26 | using System.Collections; 27 | using System.Collections.Generic; 28 | 29 | [Serializable] 30 | public class Pose : ScriptableObject { 31 | public RotationValue[] rotations = {}; 32 | public PositionValue[] positions = {}; 33 | public PositionValue[] controlPoints = {}; 34 | public PositionValue[] targets = {}; 35 | } 36 | 37 | [Serializable] 38 | public class RotationValue { 39 | public String name; 40 | public Quaternion rotation; 41 | 42 | public RotationValue(string name, Quaternion rotation) { 43 | this.name = name; 44 | this.rotation = rotation; 45 | } 46 | } 47 | 48 | [Serializable] 49 | public class PositionValue { 50 | public String name; 51 | public Vector3 position; 52 | 53 | public PositionValue(string name, Vector3 position) { 54 | this.name = name; 55 | this.position = position; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/ScriptableObjectUtility.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Banbury 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using UnityEngine; 25 | #if UNITY_EDITOR 26 | using UnityEditor; 27 | #endif 28 | using System.IO; 29 | 30 | public static class ScriptableObjectUtility 31 | { 32 | /// 33 | // This makes it easy to create, name and place unique new ScriptableObject asset files. 34 | /// 35 | #if UNITY_EDITOR 36 | public static void CreateAsset(Object asset) 37 | { 38 | CreateAsset(asset, "/New " + asset.GetType().ToString()); 39 | } 40 | 41 | public static void CreateAsset(Object asset, string filename) 42 | { 43 | string path = AssetDatabase.GetAssetPath(Selection.activeObject); 44 | if (path == "") 45 | { 46 | path = "Assets"; 47 | } 48 | else if (Path.GetExtension(path) != "") 49 | { 50 | path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); 51 | } 52 | 53 | string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + filename + ".asset"); 54 | 55 | AssetDatabase.CreateAsset(asset, assetPathAndName); 56 | 57 | 58 | AssetDatabase.SaveAssets(); 59 | 60 | Selection.activeObject = asset; 61 | } 62 | 63 | public static void CreateAsset() where T : ScriptableObject 64 | { 65 | T asset = ScriptableObject.CreateInstance(); 66 | 67 | string path = AssetDatabase.GetAssetPath(Selection.activeObject); 68 | if (path == "") 69 | { 70 | path = "Assets"; 71 | } 72 | else if (Path.GetExtension(path) != "") 73 | { 74 | path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); 75 | } 76 | 77 | string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset"); 78 | 79 | AssetDatabase.CreateAsset(asset, assetPathAndName); 80 | 81 | AssetDatabase.SaveAssets(); 82 | AssetDatabase.Refresh(); 83 | EditorUtility.FocusProjectWindow(); 84 | Selection.activeObject = asset; 85 | } 86 | #endif 87 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/SortingLayerAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Nick Gravelyn. 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source 21 | * distribution. 22 | */ 23 | 24 | using UnityEngine; 25 | 26 | namespace UnityToolbag 27 | { 28 | // Used to mark an 'int' field as a sorting layer so it will use the SortingLayerDrawer to display in the Inspector window. 29 | public class SortingLayerAttribute : PropertyAttribute 30 | { 31 | } 32 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/SortingLayerExposed.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014, Nick Gravelyn. 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * 8 | * Permission is granted to anyone to use this software for any purpose, 9 | * including commercial applications, and to alter it and redistribute it 10 | * freely, subject to the following restrictions: 11 | * 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 20 | * 3. This notice may not be removed or altered from any source 21 | * distribution. 22 | */ 23 | 24 | using UnityEngine; 25 | 26 | namespace UnityToolbag 27 | { 28 | // Component does nothing; editor script does all the magic 29 | [AddComponentMenu("UnityToolbag/Sorting Layer Exposed")] 30 | public class SortingLayerExposed : MonoBehaviour 31 | { 32 | } 33 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Polygon/PolygonPoint.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Replaced get/set Next/Previous with attributes 34 | /// Future possibilities 35 | /// Documentation! 36 | 37 | namespace Poly2Tri { 38 | public class PolygonPoint : TriangulationPoint { 39 | public PolygonPoint( double x, double y ) : base(x, y) { } 40 | 41 | public PolygonPoint Next { get; set; } 42 | public PolygonPoint Previous { get; set; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Polygon/PolygonSet.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Replaced getPolygons with attribute 34 | /// Future possibilities 35 | /// Replace Add(Polygon) with exposed container? 36 | /// Replace entire class with HashSet ? 37 | 38 | using System.Collections.Generic; 39 | 40 | namespace Poly2Tri { 41 | public class PolygonSet { 42 | protected List _polygons = new List(); 43 | 44 | public PolygonSet() {} 45 | 46 | public PolygonSet(Polygon poly) { 47 | _polygons.Add(poly); 48 | } 49 | 50 | public void Add(Polygon p) { 51 | _polygons.Add(p); 52 | } 53 | 54 | public IEnumerable Polygons { get { return _polygons; } } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/MeshRenderer.Core/BoundingBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | // NICO 6 | //using System.Drawing; 7 | using TriangleNet.Geometry; 8 | using UnityEngine; 9 | 10 | namespace TMeshRenderer.Core 11 | { 12 | public struct BoundingBox 13 | { 14 | public float Left; 15 | public float Right; 16 | public float Bottom; 17 | public float Top; 18 | 19 | public float Width 20 | { 21 | get { return this.Right - this.Left; } 22 | } 23 | 24 | public float Height 25 | { 26 | get { return this.Top - this.Bottom; } 27 | } 28 | 29 | public BoundingBox(float left, float right, float bottom, float top) 30 | { 31 | this.Left = left; 32 | this.Right = right; 33 | this.Bottom = bottom; 34 | this.Top = top; 35 | } 36 | 37 | public void Update(Point pt) 38 | { 39 | this.Update(pt.x, pt.y); 40 | } 41 | 42 | public void Update(Vector2 pt) 43 | { 44 | this.Update(pt.x, pt.y); 45 | } 46 | 47 | public void Update(double x, double y) 48 | { 49 | // Update bounding box 50 | if (this.Left > x) this.Left = (float)x; 51 | if (this.Right < x) this.Right = (float)x; 52 | if (this.Bottom > y) this.Bottom = (float)y; 53 | if (this.Top < y) this.Top = (float)y; 54 | } 55 | 56 | public void Reset() 57 | { 58 | this.Left = float.MaxValue; 59 | this.Right = -float.MaxValue; 60 | this.Bottom = float.MaxValue; 61 | this.Top = -float.MaxValue; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/MeshRenderer.Core/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // TODO: Update copyright text. 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TMeshRenderer.Core 8 | { 9 | using System; 10 | //using System.Drawing; 11 | using UnityEngine; 12 | 13 | /// 14 | /// Extension methods. 15 | /// 16 | public static class ExtensionMethods 17 | { 18 | #region Color extention methods 19 | 20 | /// 21 | /// Converts a Color to a float array containing normalized R, G ,B, A values. 22 | /// 23 | public static float[] ToFloatArray4(this Color color) 24 | { 25 | return new float[] { 26 | ((float)color.r) / 255.0f, 27 | ((float)color.g) / 255.0f, 28 | ((float)color.b) / 255.0f, 29 | ((float)color.a) / 255.0f 30 | }; 31 | } 32 | 33 | #endregion 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/MeshRenderer.Core/GDI/VoronoiRenderer.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Christian Woltering, Triangle.NET, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | /* 8 | namespace TMeshRenderer.Core.GDI 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Drawing; 13 | using System.Linq; 14 | using System.Text; 15 | using TriangleNet; 16 | using TriangleNet.Tools; 17 | 18 | /// 19 | /// Renders a (bounded) Voronoi diagram. 20 | /// 21 | public class VoronoiRenderer 22 | { 23 | RenderData data; 24 | ColorManager renderColors; 25 | 26 | /// 27 | /// Initializes a new instance of the class. 28 | /// 29 | public VoronoiRenderer(RenderData data) 30 | { 31 | this.data = data; 32 | } 33 | 34 | /// 35 | /// Renders the voronoi diagram. 36 | /// 37 | public void Render(Graphics g, Zoom zoom, ColorManager renderColors) 38 | { 39 | this.renderColors = renderColors; 40 | 41 | var points = data.VoronoiPoints; 42 | var edges = data.VoronoiEdges; 43 | 44 | if (points != null && edges != null) 45 | { 46 | uint k; 47 | Vector2 p0, p1; 48 | int n = edges.Length / 2; 49 | 50 | for (int i = 0; i < n; i++) 51 | { 52 | // First endpoint of voronoi edge 53 | k = edges[2 * i]; 54 | p0 = new Vector2(points[2 * k], points[2 * k + 1]); 55 | 56 | // Second endpoint of voronoi edge 57 | k = edges[2 * i + 1]; 58 | p1 = new Vector2(points[2 * k], points[2 * k + 1]); 59 | 60 | // Render the edge 61 | if (zoom.ViewportContains(p0.X, p0.Y) || 62 | zoom.ViewportContains(p1.X, p1.Y)) 63 | { 64 | p0 = zoom.WorldToScreen(p0.X, p0.Y); 65 | p1 = zoom.WorldToScreen(p1.X, p1.Y); 66 | 67 | g.DrawLine(renderColors.VoronoiLine, p0, p1); 68 | } 69 | } 70 | } 71 | } 72 | } 73 | } 74 | */ 75 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/MeshRenderer.Core/IMeshRenderer.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // TODO: Update copyright text. 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TMeshRenderer.Core 8 | { 9 | using System; 10 | 11 | /// 12 | /// TODO: Update summary. 13 | /// 14 | public interface IMeshRenderer 15 | { 16 | bool ShowVoronoi { get; set; } 17 | bool ShowRegions { get; set; } 18 | 19 | void Zoom(float x, float y, int delta); 20 | void HandleResize(); 21 | 22 | void Initialize(); 23 | 24 | void SetData(RenderData data); 25 | 26 | //void SetPoints(float[] points, int inputPoints); 27 | //void SetTriangles(uint[] triangles); 28 | //void SetSegments(uint[] segments); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/MeshRenderer.Core/RenderManager.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // TODO: Update copyright text. 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | /* 8 | namespace TMeshRenderer.Core 9 | { 10 | using System; 11 | using System.IO; 12 | using System.Linq; 13 | using System.Reflection; 14 | using System.Windows.Forms; 15 | 16 | /// 17 | /// This is a proxy to an actual IMeshRenderer instance. 18 | /// 19 | public class RenderManager : IMeshRenderer 20 | { 21 | IMeshRenderer renderer; 22 | 23 | public Control RenderControl 24 | { 25 | get { return (Control)renderer; } 26 | set 27 | { 28 | if (value is IMeshRenderer) 29 | { 30 | renderer = (IMeshRenderer)value; 31 | } 32 | } 33 | } 34 | 35 | public bool ShowVoronoi 36 | { 37 | get { return renderer.ShowVoronoi; } 38 | set { renderer.ShowVoronoi = value; } 39 | } 40 | 41 | public bool ShowRegions 42 | { 43 | get { return renderer.ShowRegions; } 44 | set { renderer.ShowRegions = value; } 45 | } 46 | 47 | public void Initialize() 48 | { 49 | renderer.Initialize(); 50 | } 51 | 52 | public void Zoom(float x, float y, int delta) 53 | { 54 | renderer.Zoom(x, y, delta); 55 | } 56 | 57 | public void HandleResize() 58 | { 59 | renderer.HandleResize(); 60 | } 61 | 62 | public void SetData(RenderData data) 63 | { 64 | renderer.SetData(data); 65 | } 66 | 67 | public void CreateDefaultControl() 68 | { 69 | this.RenderControl = new TMeshRenderer.Core.GDI.RenderControl(); 70 | } 71 | 72 | public bool CreateControl(string assemblyName) 73 | { 74 | return CreateControl(assemblyName, null); 75 | } 76 | 77 | public bool CreateControl(string assemblyName, string[] dependencies) 78 | { 79 | // Check if assembly exists 80 | if (!File.Exists(assemblyName)) 81 | { 82 | return false; 83 | } 84 | 85 | // Check if dependencies exists 86 | if (dependencies != null) 87 | { 88 | foreach (var item in dependencies) 89 | { 90 | if (!File.Exists(item)) 91 | { 92 | return false; 93 | } 94 | } 95 | } 96 | 97 | assemblyName = Path.GetFileNameWithoutExtension(assemblyName); 98 | 99 | // Try creating renderer instance. 100 | try 101 | { 102 | // Load the assembly into the current application domain. 103 | Assembly assembly = Assembly.Load(assemblyName); 104 | 105 | // Get all types implementing the IMeshRenderer interface. 106 | var type = typeof(IMeshRenderer); 107 | var types = assembly.GetTypes().Where(s => type.IsAssignableFrom(s)).ToArray(); 108 | 109 | if (types.Length > 0) 110 | { 111 | // Create an instance. 112 | renderer = (IMeshRenderer)Activator.CreateInstance(types[0]); 113 | } 114 | 115 | } 116 | catch (Exception) 117 | { 118 | return false; 119 | } 120 | 121 | // Return true if render control was successfully created. 122 | return (renderer != null); 123 | } 124 | } 125 | } 126 | 127 | */ 128 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Algorithm/ITriangulator.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Algorithm 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | /// 15 | /// TODO: Update summary. 16 | /// 17 | public interface ITriangulator 18 | { 19 | int Triangulate(Mesh mesh); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Data/BadSubseg.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html 4 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 5 | // 6 | // ----------------------------------------------------------------------- 7 | 8 | namespace TriangleNet.Data 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Text; 14 | 15 | /// 16 | /// A queue used to store encroached subsegments. 17 | /// 18 | /// 19 | /// Each subsegment's vertices are stored so that we can check whether a 20 | /// subsegment is still the same. 21 | /// 22 | class BadSubseg 23 | { 24 | private static int hashSeed = 0; 25 | internal int Hash; 26 | 27 | public Osub encsubseg; // An encroached subsegment. 28 | public Vertex subsegorg, subsegdest; // Its two vertices. 29 | 30 | public BadSubseg() 31 | { 32 | this.Hash = hashSeed++; 33 | } 34 | 35 | public override int GetHashCode() 36 | { 37 | return this.Hash; 38 | } 39 | 40 | public override string ToString() 41 | { 42 | return String.Format("B-SID {0}", encsubseg.seg.hash); 43 | } 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Data/BadTriangle.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html 4 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 5 | // 6 | // ----------------------------------------------------------------------- 7 | 8 | namespace TriangleNet.Data 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Text; 14 | 15 | /// 16 | /// A queue used to store bad triangles. 17 | /// 18 | /// 19 | /// The key is the square of the cosine of the smallest angle of the triangle. 20 | /// Each triangle's vertices are stored so that one can check whether a 21 | /// triangle is still the same. 22 | /// 23 | class BadTriangle 24 | { 25 | public static int OTID = 0; 26 | public int ID = 0; 27 | 28 | public Otri poortri; // A skinny or too-large triangle. 29 | public double key; // cos^2 of smallest (apical) angle. 30 | public Vertex triangorg, triangdest, triangapex; // Its three vertices. 31 | public BadTriangle nexttriang; // Pointer to next bad triangle. 32 | 33 | public BadTriangle() 34 | { 35 | ID = OTID++; 36 | } 37 | public override string ToString() 38 | { 39 | return String.Format("B-TID {0}", poortri.triangle.hash); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Data/Segment.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html 4 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 5 | // 6 | // ----------------------------------------------------------------------- 7 | 8 | namespace TriangleNet.Data 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Text; 14 | using TriangleNet.Geometry; 15 | 16 | /// 17 | /// The subsegment data structure. 18 | /// 19 | /// 20 | /// Each subsegment contains two pointers to adjoining subsegments, plus 21 | /// four pointers to vertices, plus two pointers to adjoining triangles, 22 | /// plus one boundary marker. 23 | /// 24 | public class Segment : ISegment 25 | { 26 | // Hash for dictionary. Will be set by mesh instance. 27 | internal int hash; 28 | 29 | internal Osub[] subsegs; 30 | internal Vertex[] vertices; 31 | internal Otri[] triangles; 32 | internal int boundary; 33 | 34 | public Segment() 35 | { 36 | // Initialize the two adjoining subsegments to be the omnipresent 37 | // subsegment. 38 | subsegs = new Osub[2]; 39 | subsegs[0].seg = Mesh.dummysub; 40 | subsegs[1].seg = Mesh.dummysub; 41 | 42 | // Four NULL vertices. 43 | vertices = new Vertex[4]; 44 | 45 | // Initialize the two adjoining triangles to be "outer space." 46 | triangles = new Otri[2]; 47 | triangles[0].triangle = Mesh.dummytri; 48 | triangles[1].triangle = Mesh.dummytri; 49 | 50 | // Set the boundary marker to zero. 51 | boundary = 0; 52 | } 53 | 54 | #region Public properties 55 | 56 | /// 57 | /// Gets the first endpoints vertex id. 58 | /// 59 | public int P0 60 | { 61 | get { return this.vertices[0].id; } 62 | } 63 | 64 | /// 65 | /// Gets the seconds endpoints vertex id. 66 | /// 67 | public int P1 68 | { 69 | get { return this.vertices[1].id; } 70 | } 71 | 72 | /// 73 | /// Gets the segment boundary mark. 74 | /// 75 | public int Boundary 76 | { 77 | get { return this.boundary; } 78 | } 79 | 80 | #endregion 81 | 82 | /// 83 | /// Gets the segments endpoint. 84 | /// 85 | public Vertex GetVertex(int index) 86 | { 87 | return this.vertices[index]; // TODO: Check range? 88 | } 89 | 90 | /// 91 | /// Gets an adjoining triangle. 92 | /// 93 | public ITriangle GetTriangle(int index) 94 | { 95 | return triangles[index].triangle == Mesh.dummytri ? null : triangles[index].triangle; 96 | } 97 | 98 | public override int GetHashCode() 99 | { 100 | return this.hash; 101 | } 102 | 103 | public override string ToString() 104 | { 105 | return String.Format("SID {0}", hash); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Data/Vertex.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html 4 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 5 | // 6 | // ----------------------------------------------------------------------- 7 | 8 | namespace TriangleNet.Data 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Text; 14 | using TriangleNet.Geometry; 15 | 16 | /// 17 | /// The vertex data structure. 18 | /// 19 | public class Vertex : Point 20 | { 21 | // Hash for dictionary. Will be set by mesh instance. 22 | internal int hash; 23 | 24 | internal VertexType type; 25 | internal Otri tri; 26 | 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | public Vertex() 31 | : this(0, 0, 0, 0) 32 | { 33 | } 34 | 35 | /// 36 | /// Initializes a new instance of the class. 37 | /// 38 | /// The x coordinate of the vertex. 39 | /// The y coordinate of the vertex. 40 | public Vertex(double x, double y) 41 | : this(x, y, 0, 0) 42 | { 43 | } 44 | 45 | /// 46 | /// Initializes a new instance of the class. 47 | /// 48 | /// The x coordinate of the vertex. 49 | /// The y coordinate of the vertex. 50 | /// The boundary mark. 51 | public Vertex(double x, double y, int mark) 52 | : this(x, y, mark, 0) 53 | { 54 | } 55 | 56 | /// 57 | /// Initializes a new instance of the class. 58 | /// 59 | /// The x coordinate of the vertex. 60 | /// The y coordinate of the vertex. 61 | /// The boundary mark. 62 | /// The number of point attributes. 63 | public Vertex(double x, double y, int mark, int attribs) 64 | : base(x, y, mark) 65 | { 66 | this.type = VertexType.InputVertex; 67 | 68 | if (attribs > 0) 69 | { 70 | this.attributes = new double[attribs]; 71 | } 72 | } 73 | 74 | #region Public properties 75 | 76 | /// 77 | /// Gets the vertex type. 78 | /// 79 | public VertexType Type 80 | { 81 | get { return this.type; } 82 | } 83 | 84 | /// 85 | /// Gets the specified coordinate of the vertex. 86 | /// 87 | /// Coordinate index. 88 | /// X coordinate, if index is 0, Y coordinate, if index is 1. 89 | public double this[int i] 90 | { 91 | get 92 | { 93 | if (i == 0) 94 | { 95 | return x; 96 | } 97 | 98 | if (i == 1) 99 | { 100 | return y; 101 | } 102 | 103 | throw new ArgumentOutOfRangeException("Index must be 0 or 1."); 104 | } 105 | } 106 | 107 | #endregion 108 | 109 | public override int GetHashCode() 110 | { 111 | return this.hash; 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Enums.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Original Triangle code by Jonathan Richard Shewchuk, http://www.cs.cmu.edu/~quake/triangle.html 4 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 5 | // 6 | // ----------------------------------------------------------------------- 7 | 8 | namespace TriangleNet 9 | { 10 | /// 11 | /// Implemented triangulation algorithms. 12 | /// 13 | public enum TriangulationAlgorithm 14 | { 15 | Dwyer, 16 | Incremental, 17 | SweepLine 18 | }; 19 | 20 | /// 21 | /// Labels that signify the result of point location. 22 | /// 23 | /// The result of a search indicates that the point falls in the 24 | /// interior of a triangle, on an edge, on a vertex, or outside the mesh. 25 | /// 26 | enum LocateResult { InTriangle, OnEdge, OnVertex, Outside }; 27 | 28 | /// 29 | /// Labels that signify the result of vertex insertion. 30 | /// 31 | /// The result indicates that the vertex was inserted with complete 32 | /// success, was inserted but encroaches upon a subsegment, was not inserted 33 | /// because it lies on a segment, or was not inserted because another vertex 34 | /// occupies the same location. 35 | /// 36 | enum InsertVertexResult { Successful, Encroaching, Violating, Duplicate }; 37 | 38 | /// 39 | /// Labels that signify the result of direction finding. 40 | /// 41 | /// The result indicates that a segment connecting the two query 42 | /// points falls within the direction triangle, along the left edge of the 43 | /// direction triangle, or along the right edge of the direction triangle. 44 | /// 45 | enum FindDirectionResult { Within, Leftcollinear, Rightcollinear }; 46 | 47 | /// 48 | /// The type of the mesh vertex. 49 | /// 50 | public enum VertexType { InputVertex, SegmentVertex, FreeVertex, DeadVertex, UndeadVertex }; 51 | 52 | /// 53 | /// Node renumbering algorithms. 54 | /// 55 | public enum NodeNumbering { None, Linear, CuthillMcKee }; 56 | } 57 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Geometry/BoundingBox.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Geometry 8 | { 9 | using System; 10 | 11 | /// 12 | /// A simple bounding box class. 13 | /// 14 | public class BoundingBox 15 | { 16 | double xmin, ymin, xmax, ymax; 17 | 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | public BoundingBox() 22 | { 23 | xmin = double.MaxValue; 24 | ymin = double.MaxValue; 25 | xmax = -double.MaxValue; 26 | ymax = -double.MaxValue; 27 | } 28 | 29 | /// 30 | /// Initializes a new instance of the class 31 | /// with predefined bounds. 32 | /// 33 | /// Minimum x value. 34 | /// Minimum y value. 35 | /// Maximum x value. 36 | /// Maximum y value. 37 | public BoundingBox(double xmin, double ymin, double xmax, double ymax) 38 | { 39 | this.xmin = xmin; 40 | this.ymin = ymin; 41 | this.xmax = xmax; 42 | this.ymax = ymax; 43 | } 44 | 45 | /// 46 | /// Gets the minimum x value (left boundary). 47 | /// 48 | public double Xmin 49 | { 50 | get { return xmin; } 51 | } 52 | 53 | /// 54 | /// Gets the minimum y value (bottom boundary). 55 | /// 56 | public double Ymin 57 | { 58 | get { return ymin; } 59 | } 60 | 61 | /// 62 | /// Gets the maximum x value (right boundary). 63 | /// 64 | public double Xmax 65 | { 66 | get { return xmax; } 67 | } 68 | 69 | /// 70 | /// Gets the maximum y value (top boundary). 71 | /// 72 | public double Ymax 73 | { 74 | get { return ymax; } 75 | } 76 | 77 | /// 78 | /// Gets the width of the bounding box. 79 | /// 80 | public double Width 81 | { 82 | get { return xmax - xmin; } 83 | } 84 | 85 | /// 86 | /// Gets the height of the bounding box. 87 | /// 88 | public double Height 89 | { 90 | get { return ymax - ymin; } 91 | } 92 | 93 | /// 94 | /// Update bounds. 95 | /// 96 | /// X coordinate. 97 | /// Y coordinate. 98 | public void Update(double x, double y) 99 | { 100 | xmin = Math.Min(xmin, x); 101 | ymin = Math.Min(ymin, y); 102 | xmax = Math.Max(xmax, x); 103 | ymax = Math.Max(ymax, y); 104 | } 105 | 106 | /// 107 | /// Scale bounds. 108 | /// 109 | /// Add dx to left and right bounds. 110 | /// Add dy to top and bottom bounds. 111 | public void Scale(double dx, double dy) 112 | { 113 | xmin -= dx; 114 | xmax += dx; 115 | ymin -= dy; 116 | ymax += dy; 117 | } 118 | 119 | /// 120 | /// Check if given point is inside bounding box. 121 | /// 122 | /// Point to check. 123 | /// Return true, if bounding box contains given point. 124 | public bool Contains(Point pt) 125 | { 126 | return ((pt.x >= xmin) && (pt.x <= xmax) && (pt.y >= ymin) && (pt.y <= ymax)); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Geometry/Edge.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Geometry 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using TriangleNet.Data; 14 | 15 | /// 16 | /// Represents a straight line segment in 2D space. 17 | /// 18 | public class Edge 19 | { 20 | /// 21 | /// Gets the first endpoints index. 22 | /// 23 | public int P0 24 | { 25 | get; 26 | private set; 27 | } 28 | 29 | /// 30 | /// Gets the second endpoints index. 31 | /// 32 | public int P1 33 | { 34 | get; 35 | private set; 36 | } 37 | 38 | /// 39 | /// Gets the segments boundary mark. 40 | /// 41 | public int Boundary 42 | { 43 | get; 44 | private set; 45 | } 46 | 47 | /// 48 | /// Initializes a new instance of the class. 49 | /// 50 | public Edge(int p0, int p1) 51 | : this(p0, p1, 0) 52 | { } 53 | 54 | /// 55 | /// Initializes a new instance of the class. 56 | /// 57 | public Edge(int p0, int p1, int boundary) 58 | { 59 | this.P0 = p0; 60 | this.P1 = p1; 61 | this.Boundary = boundary; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Geometry/EdgeEnumerator.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Geometry 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using TriangleNet.Data; 14 | 15 | /// 16 | /// Enumerates the edges of a triangulation. 17 | /// 18 | public class EdgeEnumerator : IEnumerator 19 | { 20 | IEnumerator triangles; 21 | Otri tri = default(Otri); 22 | Otri neighbor = default(Otri); 23 | Osub sub = default(Osub); 24 | Edge current; 25 | Vertex p1, p2; 26 | 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | public EdgeEnumerator(Mesh mesh) 31 | { 32 | triangles = mesh.triangles.Values.GetEnumerator(); 33 | triangles.MoveNext(); 34 | 35 | tri.triangle = triangles.Current; 36 | tri.orient = 0; 37 | } 38 | 39 | public Edge Current 40 | { 41 | get { return current; } 42 | } 43 | 44 | public void Dispose() 45 | { 46 | this.triangles.Dispose(); 47 | } 48 | 49 | object System.Collections.IEnumerator.Current 50 | { 51 | get { return current; } 52 | } 53 | 54 | public bool MoveNext() 55 | { 56 | if (tri.triangle == null) 57 | { 58 | return false; 59 | } 60 | 61 | current = null; 62 | 63 | while (current == null) 64 | { 65 | if (tri.orient == 3) 66 | { 67 | if (triangles.MoveNext()) 68 | { 69 | tri.triangle = triangles.Current; 70 | tri.orient = 0; 71 | } 72 | else 73 | { 74 | // Finally no more triangles 75 | return false; 76 | } 77 | } 78 | 79 | tri.Sym(ref neighbor); 80 | 81 | if ((tri.triangle.id < neighbor.triangle.id) || (neighbor.triangle == Mesh.dummytri)) 82 | { 83 | p1 = tri.Org(); 84 | p2 = tri.Dest(); 85 | 86 | tri.SegPivot(ref sub); 87 | 88 | // Boundary mark of dummysub is 0, so we don't need to worry about that. 89 | current = new Edge(p1.id, p2.id, sub.seg.boundary); 90 | } 91 | 92 | tri.orient++; 93 | } 94 | 95 | return true; 96 | } 97 | 98 | public void Reset() 99 | { 100 | this.triangles.Reset(); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Geometry/ISegment.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Geometry 8 | { 9 | using TriangleNet.Data; 10 | 11 | /// 12 | /// Interface for segment geometry. 13 | /// 14 | public interface ISegment 15 | { 16 | #region Public properties 17 | 18 | /// 19 | /// Gets the first endpoints vertex id. 20 | /// 21 | int P0 { get; } 22 | 23 | /// 24 | /// Gets the seconds endpoints vertex id. 25 | /// 26 | int P1 { get; } 27 | 28 | /// 29 | /// Gets the segment boundary mark. 30 | /// 31 | int Boundary { get; } 32 | 33 | /// 34 | /// Gets the segments endpoint. 35 | /// 36 | /// The vertex index (0 or 1). 37 | Vertex GetVertex(int index); 38 | 39 | /// 40 | /// Gets an adjoining triangle. 41 | /// 42 | /// The triangle index (0 or 1). 43 | ITriangle GetTriangle(int index); 44 | 45 | #endregion 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Geometry/ITriangle.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Geometry 8 | { 9 | using TriangleNet.Data; 10 | 11 | /// 12 | /// Triangle interface. 13 | /// 14 | public interface ITriangle 15 | { 16 | /// 17 | /// The triangle id. 18 | /// 19 | int ID { get; } 20 | 21 | /// 22 | /// First vertex id of the triangle. 23 | /// 24 | int P0 { get; } 25 | /// 26 | /// Second vertex id of the triangle. 27 | /// 28 | int P1 { get; } 29 | /// 30 | /// Third vertex id of the triangle. 31 | /// 32 | int P2 { get; } 33 | 34 | /// 35 | /// Gets a triangles vertex. 36 | /// 37 | /// The vertex index (0, 1 or 2). 38 | /// The vertex of the specified corner index. 39 | Vertex GetVertex(int index); 40 | 41 | /// 42 | /// True if the triangle implementation contains neighbor information. 43 | /// 44 | bool SupportsNeighbors { get; } 45 | 46 | /// 47 | /// First neighbor. 48 | /// 49 | int N0 { get; } 50 | /// 51 | /// Second neighbor. 52 | /// 53 | int N1 { get; } 54 | /// 55 | /// Third neighbor. 56 | /// 57 | int N2 { get; } 58 | 59 | /// 60 | /// Gets a triangles neighbor. 61 | /// 62 | /// The vertex index (0, 1 or 2). 63 | /// The neigbbor opposite of vertex with given index. 64 | ITriangle GetNeighbor(int index); 65 | 66 | /// 67 | /// Gets a triangles segment. 68 | /// 69 | /// The vertex index (0, 1 or 2). 70 | /// The segment opposite of vertex with given index. 71 | ISegment GetSegment(int index); 72 | 73 | /// 74 | /// Triangle area constraint. 75 | /// 76 | double Area { get; set; } 77 | 78 | /// 79 | /// Region ID the triangle belongs to. 80 | /// 81 | int Region { get; } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Geometry/Point.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Geometry 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | /// 15 | /// Represents a 2D point. 16 | /// 17 | public class Point : IComparable, IEquatable 18 | { 19 | internal int id; 20 | internal double x; 21 | internal double y; 22 | internal int mark; 23 | internal double[] attributes; 24 | 25 | public Point() 26 | : this(0, 0, 0) 27 | { 28 | } 29 | 30 | public Point(double x, double y) 31 | : this(x, y, 0) 32 | { 33 | } 34 | 35 | public Point(double x, double y, int mark) 36 | { 37 | this.x = x; 38 | this.y = y; 39 | this.mark = mark; 40 | } 41 | 42 | #region Public properties 43 | 44 | /// 45 | /// Gets the vertex id. 46 | /// 47 | public int ID 48 | { 49 | get { return this.id; } 50 | } 51 | 52 | /// 53 | /// Gets the vertex x coordinate. 54 | /// 55 | public double X 56 | { 57 | get { return this.x; } 58 | } 59 | 60 | /// 61 | /// Gets the vertex y coordinate. 62 | /// 63 | public double Y 64 | { 65 | get { return this.y; } 66 | } 67 | 68 | /// 69 | /// Gets the vertex boundary mark. 70 | /// 71 | public int Boundary 72 | { 73 | get { return this.mark; } 74 | } 75 | 76 | /// 77 | /// Gets the vertex attributes (may be null). 78 | /// 79 | public double[] Attributes 80 | { 81 | get { return this.attributes; } 82 | } 83 | 84 | #endregion 85 | 86 | #region Operator overloading / overriding Equals 87 | 88 | // Compare "Guidelines for Overriding Equals() and Operator ==" 89 | // http://msdn.microsoft.com/en-us/library/ms173147.aspx 90 | 91 | public static bool operator ==(Point a, Point b) 92 | { 93 | // If both are null, or both are same instance, return true. 94 | if (Object.ReferenceEquals(a, b)) 95 | { 96 | return true; 97 | } 98 | 99 | // If one is null, but not both, return false. 100 | if (((object)a == null) || ((object)b == null)) 101 | { 102 | return false; 103 | } 104 | 105 | return a.Equals(b); 106 | } 107 | 108 | public static bool operator !=(Point a, Point b) 109 | { 110 | return !(a == b); 111 | } 112 | 113 | public override bool Equals(object obj) 114 | { 115 | // If parameter is null return false. 116 | if (obj == null) 117 | { 118 | return false; 119 | } 120 | 121 | Point p = obj as Point; 122 | 123 | if ((object)p == null) 124 | { 125 | return false; 126 | } 127 | 128 | return (x == p.x) && (y == p.y); 129 | } 130 | 131 | public bool Equals(Point p) 132 | { 133 | // If vertex is null return false. 134 | if ((object)p == null) 135 | { 136 | return false; 137 | } 138 | 139 | // Return true if the fields match: 140 | return (x == p.x) && (y == p.y); 141 | } 142 | 143 | #endregion 144 | 145 | public int CompareTo(Point other) 146 | { 147 | if (x == other.x && y == other.y) 148 | { 149 | return 0; 150 | } 151 | 152 | return (x < other.x || (x == other.x && y < other.y)) ? -1 : 1; 153 | } 154 | 155 | public override int GetHashCode() 156 | { 157 | return x.GetHashCode() ^ y.GetHashCode(); 158 | } 159 | 160 | public override string ToString() 161 | { 162 | return String.Format("[{0},{1}]", x, y); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Geometry/RegionPointer.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Geometry 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | 12 | /// 13 | /// Pointer to a region in the mesh geometry. A region is a well-defined 14 | /// subset of the geomerty (enclosed by subsegments). 15 | /// 16 | public class RegionPointer 17 | { 18 | internal Point point; 19 | internal int id; 20 | 21 | /// 22 | /// Initializes a new instance of the class. 23 | /// 24 | /// X coordinate of the region. 25 | /// Y coordinate of the region. 26 | /// Region id. 27 | public RegionPointer(double x, double y, int id) 28 | { 29 | this.point = new Point(x, y); 30 | this.id = id; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/IO/IGeometryFormat.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.IO 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using TriangleNet.Geometry; 14 | 15 | /// 16 | /// Interface for geometry input. 17 | /// 18 | public interface IGeometryFormat 19 | { 20 | /// 21 | /// Read a file containing geometry information. 22 | /// 23 | /// The path of the file to read. 24 | /// An instance of the class. 25 | InputGeometry Read(string filename); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/IO/IMeshFormat.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.IO 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using TriangleNet.Geometry; 14 | 15 | /// 16 | /// Interface for mesh I/O. 17 | /// 18 | public interface IMeshFormat 19 | { 20 | /// 21 | /// Read a file containing a mesh. 22 | /// 23 | /// The path of the file to read. 24 | /// An instance of the class. 25 | Mesh Import(string filename); 26 | 27 | /// 28 | /// Save a mesh to disk. 29 | /// 30 | /// An instance of the class. 31 | /// The path of the file to save. 32 | void Write(Mesh mesh, string filename); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/IO/InputTriangle.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.IO 8 | { 9 | using TriangleNet.Data; 10 | using TriangleNet.Geometry; 11 | 12 | /// 13 | /// Simple triangle class for input. 14 | /// 15 | public class InputTriangle : ITriangle 16 | { 17 | internal int[] vertices; 18 | internal int region; 19 | internal double area; 20 | 21 | public InputTriangle(int p0, int p1, int p2) 22 | { 23 | this.vertices = new int[] { p0, p1, p2 }; 24 | } 25 | 26 | #region Public properties 27 | 28 | /// 29 | /// Gets the triangle id. 30 | /// 31 | public int ID 32 | { 33 | get { return 0; } 34 | } 35 | 36 | /// 37 | /// Gets the first corners vertex id. 38 | /// 39 | public int P0 40 | { 41 | get { return this.vertices[0]; } 42 | } 43 | 44 | /// 45 | /// Gets the seconds corners vertex id. 46 | /// 47 | public int P1 48 | { 49 | get { return this.vertices[1]; } 50 | } 51 | 52 | /// 53 | /// Gets the third corners vertex id. 54 | /// 55 | public int P2 56 | { 57 | get { return this.vertices[2]; } 58 | } 59 | 60 | /// 61 | /// Gets the specified corners vertex. 62 | /// 63 | public Vertex GetVertex(int index) 64 | { 65 | return null; // TODO: throw NotSupportedException? 66 | } 67 | 68 | public bool SupportsNeighbors 69 | { 70 | get { return false; } 71 | } 72 | 73 | public int N0 74 | { 75 | get { return -1; } 76 | } 77 | 78 | public int N1 79 | { 80 | get { return -1; } 81 | } 82 | 83 | public int N2 84 | { 85 | get { return -1; } 86 | } 87 | 88 | public ITriangle GetNeighbor(int index) 89 | { 90 | return null; 91 | } 92 | 93 | public ISegment GetSegment(int index) 94 | { 95 | return null; 96 | } 97 | 98 | /// 99 | /// Gets the triangle area constraint. 100 | /// 101 | public double Area 102 | { 103 | get { return area; } 104 | set { area = value; } 105 | } 106 | 107 | /// 108 | /// Region ID the triangle belongs to. 109 | /// 110 | public int Region 111 | { 112 | get { return region; } 113 | set { region = value; } 114 | } 115 | 116 | #endregion 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/IO/TriangleFormat.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.IO 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using TriangleNet.Geometry; 14 | using System.IO; 15 | 16 | /// 17 | /// Implements geometry and mesh file formats of the the original Triangle code. 18 | /// 19 | public class TriangleFormat : IGeometryFormat, IMeshFormat 20 | { 21 | public Mesh Import(string filename) 22 | { 23 | string ext = Path.GetExtension(filename); 24 | 25 | if (ext == ".node" || ext == ".poly" || ext == ".ele") 26 | { 27 | List triangles; 28 | InputGeometry geometry; 29 | 30 | FileReader.Read(filename, out geometry, out triangles); 31 | 32 | if (geometry != null && triangles != null) 33 | { 34 | Mesh mesh = new Mesh(); 35 | mesh.Load(geometry, triangles); 36 | 37 | return mesh; 38 | } 39 | } 40 | 41 | throw new NotSupportedException("Could not load '" + filename + "' file."); 42 | } 43 | 44 | public void Write(Mesh mesh, string filename) 45 | { 46 | FileWriter.WritePoly(mesh, Path.ChangeExtension(filename, ".poly")); 47 | FileWriter.WriteElements(mesh, Path.ChangeExtension(filename, ".ele")); 48 | } 49 | 50 | public InputGeometry Read(string filename) 51 | { 52 | string ext = Path.GetExtension(filename); 53 | 54 | if (ext == ".node") 55 | { 56 | return FileReader.ReadNodeFile(filename); 57 | } 58 | 59 | if (ext == ".poly") 60 | { 61 | return FileReader.ReadPolyFile(filename); 62 | } 63 | 64 | throw new NotSupportedException("File format '" + ext + "' not supported."); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Log/ILog.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Log 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | public enum LogLevel 15 | { 16 | Info = 0, 17 | Warning = 1, 18 | Error = 2 19 | } 20 | 21 | /// 22 | /// A basic log interface. 23 | /// 24 | public interface ILog where T : ILogItem 25 | { 26 | void Add(T item); 27 | void Clear(); 28 | 29 | void Info(string message); 30 | void Error(string message, string info); 31 | void Warning(string message, string info); 32 | 33 | IList Data { get; } 34 | 35 | LogLevel Level { get; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Log/ILogItem.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Log 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | /// 15 | /// A basic log item interface. 16 | /// 17 | public interface ILogItem 18 | { 19 | DateTime Time { get; } 20 | LogLevel Level { get; } 21 | string Message { get; } 22 | string Info { get; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Log/SimpleLog.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Log 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | /// 15 | /// A simple logger, which logs messages to a List. 16 | /// 17 | /// Using singleton pattern as proposed by Jon Skeet. 18 | /// http://csharpindepth.com/Articles/General/Singleton.aspx 19 | /// 20 | public sealed class SimpleLog : ILog 21 | { 22 | private List log = new List(); 23 | 24 | private LogLevel level = LogLevel.Info; 25 | 26 | #region Singleton pattern 27 | 28 | private static readonly SimpleLog instance = new SimpleLog(); 29 | 30 | // Explicit static constructor to tell C# compiler 31 | // not to mark type as beforefieldinit 32 | static SimpleLog() { } 33 | 34 | private SimpleLog() { } 35 | 36 | public static ILog Instance 37 | { 38 | get 39 | { 40 | return instance; 41 | } 42 | } 43 | 44 | #endregion 45 | 46 | public void Add(SimpleLogItem item) 47 | { 48 | log.Add(item); 49 | } 50 | 51 | public void Clear() 52 | { 53 | log.Clear(); 54 | } 55 | 56 | public void Info(string message) 57 | { 58 | log.Add(new SimpleLogItem(LogLevel.Info, message)); 59 | } 60 | 61 | public void Warning(string message, string location) 62 | { 63 | log.Add(new SimpleLogItem(LogLevel.Warning, message, location)); 64 | } 65 | 66 | public void Error(string message, string location) 67 | { 68 | log.Add(new SimpleLogItem(LogLevel.Error, message, location)); 69 | } 70 | 71 | public IList Data 72 | { 73 | get { return log; } 74 | } 75 | 76 | public LogLevel Level 77 | { 78 | get { return level; } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Log/SimpleLogItem.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Log 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | /// 15 | /// Represents an item stored in the log. 16 | /// 17 | public class SimpleLogItem : ILogItem 18 | { 19 | DateTime time; 20 | LogLevel level; 21 | string message; 22 | string info; 23 | 24 | public DateTime Time 25 | { 26 | get { return time; } 27 | } 28 | 29 | public LogLevel Level 30 | { 31 | get { return level; } 32 | } 33 | 34 | public string Message 35 | { 36 | get { return message; } 37 | } 38 | 39 | public string Info 40 | { 41 | get { return info; } 42 | } 43 | 44 | public SimpleLogItem(LogLevel level, string message) 45 | : this(level, message, "") 46 | { } 47 | 48 | public SimpleLogItem(LogLevel level, string message, string info) 49 | { 50 | this.time = DateTime.Now; 51 | this.level = level; 52 | this.message = message; 53 | this.info = info; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Triangle")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Triangle")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("96a540d0-1772-4bed-8d25-ef5fa23cd1bc")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Sampler.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | /// 15 | /// Used for triangle sampling in the Mesh.Locate method. 16 | /// 17 | class Sampler 18 | { 19 | static Random rand = new Random(DateTime.Now.Millisecond); 20 | 21 | // Number of random samples for point location (at least 1). 22 | int samples = 1; 23 | 24 | // Number of triangles in mesh. 25 | int triangleCount = 0; 26 | 27 | // Empirically chosen factor. 28 | static int samplefactor = 11; 29 | 30 | // Keys of the triangle dictionary. 31 | int[] keys; 32 | 33 | /// 34 | /// Reset the sampler. 35 | /// 36 | public void Reset() 37 | { 38 | this.samples = 1; 39 | this.triangleCount = 0; 40 | } 41 | 42 | /// 43 | /// Update sampling parameters if mesh changed. 44 | /// 45 | /// Current mesh. 46 | public void Update(Mesh mesh) 47 | { 48 | this.Update(mesh, false); 49 | } 50 | 51 | /// 52 | /// Update sampling parameters if mesh changed. 53 | /// 54 | /// Current mesh. 55 | public void Update(Mesh mesh, bool forceUpdate) 56 | { 57 | int count = mesh.triangles.Count; 58 | 59 | // TODO: Is checking the triangle count a good way to monitor mesh changes? 60 | if (triangleCount != count || forceUpdate) 61 | { 62 | triangleCount = count; 63 | 64 | // The number of random samples taken is proportional to the cube root of 65 | // the number of triangles in the mesh. The next bit of code assumes 66 | // that the number of triangles increases monotonically (or at least 67 | // doesn't decrease enough to matter). 68 | while (samplefactor * samples * samples * samples < count) 69 | { 70 | samples++; 71 | } 72 | 73 | // TODO: Is there a way not calling ToArray()? 74 | keys = mesh.triangles.Keys.ToArray(); 75 | } 76 | } 77 | 78 | /// 79 | /// Get a random sample set of triangle keys. 80 | /// 81 | /// Array of triangle keys. 82 | public int[] GetSamples(Mesh mesh) 83 | { 84 | // TODO: Using currKeys to check key availability? 85 | List randSamples = new List(samples); 86 | 87 | int range = triangleCount / samples; 88 | int key; 89 | 90 | for (int i = 0; i < samples; i++) 91 | { 92 | // Yeah, rand should be equally distributed, but just to make 93 | // sure, use a range variable... 94 | key = rand.Next(i * range, (i + 1) * range - 1); 95 | 96 | if (!mesh.triangles.Keys.Contains(keys[key])) 97 | { 98 | // Keys collection isn't up to date anymore! 99 | this.Update(mesh, true); 100 | i--; 101 | } 102 | else 103 | { 104 | randSamples.Add(keys[key]); 105 | } 106 | } 107 | 108 | return randSamples.ToArray(); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Smoothing/ISmoother.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Smoothing 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | 14 | /// 15 | /// Interface for mesh smoothers. 16 | /// 17 | public interface ISmoother 18 | { 19 | void Smooth(); 20 | } 21 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Smoothing/SimpleSmoother.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Smoothing 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using TriangleNet.Geometry; 14 | using TriangleNet.Tools; 15 | 16 | /// 17 | /// Simple mesh smoother implementation. 18 | /// 19 | /// 20 | /// Vertices wich should not move (e.g. segment vertices) MUST have a 21 | /// boundary mark greater than 0. 22 | /// 23 | public class SimpleSmoother : ISmoother 24 | { 25 | Mesh mesh; 26 | 27 | public SimpleSmoother(Mesh mesh) 28 | { 29 | this.mesh = mesh; 30 | } 31 | 32 | public void Smooth() 33 | { 34 | mesh.behavior.Quality = false; 35 | 36 | // Take a few smoothing rounds. 37 | for (int i = 0; i < 5; i++) 38 | { 39 | Step(); 40 | 41 | // Actually, we only want to rebuild, if mesh is no longer 42 | // Delaunay. Flipping edges could be the right choice instead 43 | // of re-triangulating... 44 | mesh.Triangulate(Rebuild()); 45 | } 46 | } 47 | 48 | /// 49 | /// Smooth all free nodes. 50 | /// 51 | private void Step() 52 | { 53 | BoundedVoronoi voronoi = new BoundedVoronoi(this.mesh, false); 54 | 55 | var cells = voronoi.Regions; 56 | 57 | double x, y; 58 | int n; 59 | 60 | foreach (var cell in cells) 61 | { 62 | n = 0; 63 | x = y = 0.0; 64 | foreach (var p in cell.Vertices) 65 | { 66 | n++; 67 | x += p.x; 68 | y += p.y; 69 | } 70 | 71 | cell.Generator.x = x / n; 72 | cell.Generator.y = y / n; 73 | } 74 | } 75 | 76 | /// 77 | /// Rebuild the input geometry. 78 | /// 79 | private InputGeometry Rebuild() 80 | { 81 | InputGeometry geometry = new InputGeometry(mesh.vertices.Count); 82 | 83 | foreach (var vertex in mesh.vertices.Values) 84 | { 85 | geometry.AddPoint(vertex.x, vertex.y, vertex.mark); 86 | } 87 | 88 | foreach (var segment in mesh.subsegs.Values) 89 | { 90 | geometry.AddSegment(segment.P0, segment.P1, segment.Boundary); 91 | } 92 | 93 | foreach (var hole in mesh.holes) 94 | { 95 | geometry.AddHole(hole.x, hole.y); 96 | } 97 | 98 | foreach (var region in mesh.regions) 99 | { 100 | geometry.AddRegion(region.point.x, region.point.y, region.id); 101 | } 102 | 103 | return geometry; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Tools/IVoronoi.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/ 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Tools 8 | { 9 | using System.Collections.Generic; 10 | using TriangleNet.Geometry; 11 | 12 | /// 13 | /// TODO: Update summary. 14 | /// 15 | public interface IVoronoi 16 | { 17 | /// 18 | /// Gets the list of Voronoi vertices. 19 | /// 20 | Point[] Points { get; } 21 | 22 | /// 23 | /// Gets the list of Voronoi regions. 24 | /// 25 | List Regions { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/Triangle/Tools/VoronoiRegion.cs: -------------------------------------------------------------------------------- 1 | // ----------------------------------------------------------------------- 2 | // 3 | // TODO: Update copyright text. 4 | // 5 | // ----------------------------------------------------------------------- 6 | 7 | namespace TriangleNet.Tools 8 | { 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text; 13 | using TriangleNet.Geometry; 14 | using TriangleNet.Data; 15 | 16 | /// 17 | /// Represents a region in the Voronoi diagram. 18 | /// 19 | public class VoronoiRegion 20 | { 21 | int id; 22 | Point generator; 23 | List vertices; 24 | bool bounded; 25 | 26 | /// 27 | /// Gets the Voronoi region id (which is the same as the generators vertex id). 28 | /// 29 | public int ID 30 | { 31 | get { return id; } 32 | } 33 | 34 | /// 35 | /// Gets the Voronoi regions generator. 36 | /// 37 | public Point Generator 38 | { 39 | get { return generator; } 40 | } 41 | 42 | /// 43 | /// Gets the Voronoi vertices on the regions boundary. 44 | /// 45 | //public ICollection Vertices 46 | // NICO 47 | public List Vertices 48 | { 49 | get { return vertices; } 50 | } 51 | 52 | /// 53 | /// Gets or sets whether the Voronoi region is bounded. 54 | /// 55 | public bool Bounded 56 | { 57 | get { return bounded; } 58 | set { bounded = value; } 59 | } 60 | 61 | public VoronoiRegion(Vertex generator) 62 | { 63 | this.id = generator.id; 64 | this.generator = generator; 65 | this.vertices = new List(); 66 | this.bounded = true; 67 | } 68 | 69 | public void Add(Point point) 70 | { 71 | this.vertices.Add(point); 72 | } 73 | 74 | public void Add(List points) 75 | { 76 | this.vertices.AddRange(points); 77 | } 78 | 79 | public override string ToString() 80 | { 81 | return String.Format("R-ID {0}", id); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangle.NET/TriangleNetExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using TriangleNet; 4 | using TriangleNet.Geometry; 5 | using TriangleNet.Data; 6 | using System.Collections.Generic; 7 | 8 | public static class TriangleNetExtensions{ 9 | /// Inserts points and segments of the given polygon to the input geometry 10 | static public void AddPolygon(this InputGeometry input, IList polygon){ 11 | int inputCount = input.Count; 12 | 13 | input.AddPoint(polygon[0].x, polygon[0].y); 14 | for(int i = 1, j = 0; i < polygon.Count; j = i++ ) { 15 | input.AddPoint(polygon[i].x, polygon[i].y); 16 | input.AddSegment(inputCount + j, inputCount + i); 17 | } 18 | input.AddSegment(input.Count - 1, inputCount); 19 | } 20 | 21 | /// Converts the triangle array returned from Triangle.Net to an index array for Unity Mesh triangles 22 | static public int[] ToUnityMeshTriangleIndices(this ICollection triangles) { 23 | int[] tris = new int[triangles.Count * 3]; 24 | int n = 0; 25 | foreach(var t in triangles) { 26 | tris[n++] = t.P1; 27 | tris[n++] = t.P0; 28 | tris[n++] = t.P2; 29 | } 30 | return tris; 31 | } 32 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Delaunay/Sweep/AdvancingFront.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Removed BST code, but not all artifacts of it 34 | /// Future possibilities 35 | /// Eliminate Add/RemoveNode ? 36 | /// Comments comments and more comments! 37 | 38 | using System.Text; 39 | using System; 40 | 41 | namespace Poly2Tri { 42 | /** 43 | * @author Thomas Åhlen (thahlen@gmail.com) 44 | */ 45 | public class AdvancingFront { 46 | public AdvancingFrontNode Head; 47 | public AdvancingFrontNode Tail; 48 | protected AdvancingFrontNode Search; 49 | 50 | public AdvancingFront( AdvancingFrontNode head, AdvancingFrontNode tail ) { 51 | this.Head = head; 52 | this.Tail = tail; 53 | this.Search = head; 54 | AddNode(head); 55 | AddNode(tail); 56 | } 57 | 58 | public void AddNode( AdvancingFrontNode node ) { } 59 | public void RemoveNode( AdvancingFrontNode node ) { } 60 | 61 | public override string ToString() { 62 | StringBuilder sb = new StringBuilder(); 63 | AdvancingFrontNode node = Head; 64 | while (node != Tail) { 65 | sb.Append(node.Point.X).Append("->"); 66 | node = node.Next; 67 | } 68 | sb.Append(Tail.Point.X); 69 | return sb.ToString(); 70 | } 71 | 72 | /// 73 | /// MM: This seems to be used by LocateNode to guess a position in the implicit linked list of AdvancingFrontNodes near x 74 | /// Removed an overload that depended on this being exact 75 | /// 76 | private AdvancingFrontNode FindSearchNode( double x ) { 77 | return Search; 78 | } 79 | 80 | /// 81 | /// We use a balancing tree to locate a node smaller or equal to given key value (in theory) 82 | /// 83 | public AdvancingFrontNode LocateNode( TriangulationPoint point ) { 84 | return LocateNode(point.X); 85 | } 86 | 87 | private AdvancingFrontNode LocateNode( double x ) { 88 | AdvancingFrontNode node = FindSearchNode(x); 89 | if (x < node.Value) { 90 | while ((node = node.Prev) != null) 91 | if (x >= node.Value) { 92 | Search = node; 93 | return node; 94 | } 95 | } else { 96 | while ((node = node.Next) != null) 97 | if (x < node.Value) { 98 | Search = node.Prev; 99 | return node.Prev; 100 | } 101 | } 102 | return null; 103 | } 104 | 105 | /// 106 | /// This implementation will use simple node traversal algorithm to find a point on the front 107 | /// 108 | public AdvancingFrontNode LocatePoint( TriangulationPoint point ) { 109 | double px = point.X; 110 | AdvancingFrontNode node = FindSearchNode(px); 111 | double nx = node.Point.X; 112 | 113 | if (px == nx) { 114 | if (point != node.Point) { 115 | // We might have two nodes with same x value for a short time 116 | if (point == node.Prev.Point) { 117 | node = node.Prev; 118 | } else if (point == node.Next.Point) { 119 | node = node.Next; 120 | } else { 121 | throw new Exception("Failed to find Node for given afront point"); 122 | } 123 | } 124 | } else if (px < nx) { 125 | while ((node = node.Prev) != null) if (point == node.Point) break; 126 | } else { 127 | while ((node = node.Next) != null) if (point == node.Point) break; 128 | } 129 | Search = node; 130 | return node; 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Delaunay/Sweep/AdvancingFrontNode.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Removed getters 34 | /// Has* turned into attributes 35 | /// Future possibilities 36 | /// Comments! 37 | 38 | namespace Poly2Tri { 39 | public class AdvancingFrontNode { 40 | public AdvancingFrontNode Next; 41 | public AdvancingFrontNode Prev; 42 | public double Value; 43 | public TriangulationPoint Point; 44 | public DelaunayTriangle Triangle; 45 | 46 | public AdvancingFrontNode(TriangulationPoint point) { 47 | this.Point = point; 48 | Value = point.X; 49 | } 50 | 51 | public bool HasNext { get { return Next != null; } } 52 | public bool HasPrev { get { return Prev != null; } } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Delaunay/Sweep/DTSweepBasin.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public class DTSweepBasin { 34 | public AdvancingFrontNode leftNode; 35 | public AdvancingFrontNode bottomNode; 36 | public AdvancingFrontNode rightNode; 37 | public double width; 38 | public bool leftHighest; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Delaunay/Sweep/DTSweepConstraint.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public class DTSweepConstraint : TriangulationConstraint { 34 | /// 35 | /// Give two points in any order. Will always be ordered so 36 | /// that q.y > p.y and q.x > p.x if same y value 37 | /// 38 | public DTSweepConstraint( TriangulationPoint p1, TriangulationPoint p2 ) { 39 | P = p1; 40 | Q = p2; 41 | if (p1.Y > p2.Y) { 42 | Q = p1; 43 | P = p2; 44 | } else if (p1.Y == p2.Y) { 45 | if (p1.X > p2.X) { 46 | Q = p1; 47 | P = p2; 48 | } else if (p1.X == p2.X) { 49 | // logger.info( "Failed to create constraint {}={}", p1, p2 ); 50 | // throw new DuplicatePointException( p1 + "=" + p2 ); 51 | // return; 52 | } 53 | } 54 | Q.AddEdge(this); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Delaunay/Sweep/DTSweepDebugContext.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public class DTSweepDebugContext : TriangulationDebugContext { 34 | /* 35 | * Fields used for visual representation of current triangulation 36 | */ 37 | 38 | public DelaunayTriangle PrimaryTriangle { get { return _primaryTriangle ; } set { _primaryTriangle = value; _tcx.Update("set PrimaryTriangle"); } } 39 | public DelaunayTriangle SecondaryTriangle { get { return _secondaryTriangle; } set { _secondaryTriangle = value; _tcx.Update("set SecondaryTriangle"); } } 40 | public TriangulationPoint ActivePoint { get { return _activePoint ; } set { _activePoint = value; _tcx.Update("set ActivePoint"); } } 41 | public AdvancingFrontNode ActiveNode { get { return _activeNode ; } set { _activeNode = value; _tcx.Update("set ActiveNode"); } } 42 | public DTSweepConstraint ActiveConstraint { get { return _activeConstraint ; } set { _activeConstraint = value; _tcx.Update("set ActiveConstraint"); } } 43 | 44 | public DTSweepDebugContext( DTSweepContext tcx ) : base(tcx) { } 45 | 46 | public bool IsDebugContext { get { return true; } } 47 | 48 | public override void Clear() { 49 | PrimaryTriangle = null; 50 | SecondaryTriangle = null; 51 | ActivePoint = null; 52 | ActiveNode = null; 53 | ActiveConstraint = null; 54 | } 55 | 56 | private DelaunayTriangle _primaryTriangle; 57 | private DelaunayTriangle _secondaryTriangle; 58 | private TriangulationPoint _activePoint; 59 | private AdvancingFrontNode _activeNode; 60 | private DTSweepConstraint _activeConstraint; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Delaunay/Sweep/DTSweepEdgeEvent.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /// Changes from the Java version 33 | /// Turned DTSweepEdgeEvent into a value type 34 | 35 | namespace Poly2Tri { 36 | public class DTSweepEdgeEvent { 37 | public DTSweepConstraint ConstrainedEdge; 38 | public bool Right; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Delaunay/Sweep/DTSweepPointComparator.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public class DTSweepPointComparator : IComparer { 36 | public int Compare(TriangulationPoint p1, TriangulationPoint p2) { 37 | if (p1.Y < p2.Y) { 38 | return -1; 39 | } else if (p1.Y > p2.Y) { 40 | return 1; 41 | } else { 42 | if (p1.X < p2.X) { 43 | return -1; 44 | } else if (p1.X > p2.X) { 45 | return 1; 46 | } else { 47 | return 0; 48 | } 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Delaunay/Sweep/PointOnEdgeException.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | 34 | namespace Poly2Tri { 35 | public class PointOnEdgeException : NotImplementedException { 36 | public readonly TriangulationPoint A,B,C; 37 | 38 | public PointOnEdgeException( string message, TriangulationPoint a, TriangulationPoint b, TriangulationPoint c ) 39 | : base(message) 40 | { 41 | A=a; 42 | B=b; 43 | C=c; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/ITriangulatable.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public interface Triangulatable { 36 | void Prepare(TriangulationContext tcx); 37 | 38 | IList Points { get; } // MM: Neither of these are used via interface (yet?) 39 | IList Triangles { get; } 40 | 41 | void AddTriangle(DelaunayTriangle t); 42 | void AddTriangles(IEnumerable list); 43 | void ClearTriangles(); 44 | 45 | TriangulationMode TriangulationMode { get; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Orientation.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public enum Orientation { 34 | CW, CCW, Collinear 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Sets/ConstrainedPointSet.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | namespace Poly2Tri { 34 | /* 35 | * Extends the PointSet by adding some Constraints on how it will be triangulated
36 | * A constraint defines an edge between two points in the set, these edges can not 37 | * be crossed. They will be enforced triangle edges after a triangulation. 38 | *

39 | * 40 | * 41 | * @author Thomas Åhlén, thahlen@gmail.com 42 | */ 43 | public class ConstrainedPointSet : PointSet { 44 | public int[] EdgeIndex { get; private set; } 45 | 46 | public ConstrainedPointSet(List points, int[] index) 47 | : base(points) { 48 | EdgeIndex = index; 49 | } 50 | 51 | public override TriangulationMode TriangulationMode { get { return TriangulationMode.Constrained; } } 52 | 53 | public override void Prepare(TriangulationContext tcx) { 54 | base.Prepare(tcx); 55 | for (int i = 0; i < EdgeIndex.Length; i += 2) { 56 | // XXX: must change!! 57 | tcx.NewConstraint(Points[EdgeIndex[i]], Points[EdgeIndex[i + 1]]); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Sets/PointSet.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public class PointSet : Triangulatable { 36 | public IList Points { get; private set; } 37 | public IList Triangles { get; private set; } 38 | 39 | public PointSet(List points) { 40 | Points = new List(points); 41 | } 42 | 43 | public virtual TriangulationMode TriangulationMode { get { return TriangulationMode.Unconstrained; }} 44 | 45 | public void AddTriangle(DelaunayTriangle t) { 46 | Triangles.Add(t); 47 | } 48 | 49 | public void AddTriangles(IEnumerable list) { 50 | foreach ( var tri in list ) Triangles.Add(tri); 51 | } 52 | 53 | public void ClearTriangles() { 54 | Triangles.Clear(); 55 | } 56 | 57 | public virtual void Prepare(TriangulationContext tcx) { 58 | if (Triangles == null) { 59 | Triangles = new List(Points.Count); 60 | } else { 61 | Triangles.Clear(); 62 | } 63 | tcx.Points.AddRange(Points); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/TriangulationAlgorithm.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public enum TriangulationAlgorithm { 34 | DTSweep 35 | } 36 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/TriangulationConstraint.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | /** 32 | * Forces a triangle edge between two points p and q 33 | * when triangulating. For example used to enforce 34 | * Polygon Edges during a polygon triangulation. 35 | * 36 | * @author Thomas Åhlén, thahlen@gmail.com 37 | */ 38 | 39 | namespace Poly2Tri { 40 | public class TriangulationConstraint { 41 | public TriangulationPoint P; 42 | public TriangulationPoint Q; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/TriangulationContext.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public abstract class TriangulationContext { 36 | public TriangulationDebugContext DebugContext { get; protected set; } 37 | 38 | public readonly List Triangles = new List(); 39 | public readonly List Points = new List(200); 40 | public TriangulationMode TriangulationMode { get; protected set; } 41 | public Triangulatable Triangulatable { get; private set; } 42 | 43 | public int StepCount { get; private set; } 44 | 45 | public void Done() { 46 | StepCount++; 47 | } 48 | 49 | public abstract TriangulationAlgorithm Algorithm { get; } 50 | 51 | public virtual void PrepareTriangulation(Triangulatable t) { 52 | Triangulatable = t; 53 | TriangulationMode = t.TriangulationMode; 54 | t.Prepare(this); 55 | } 56 | 57 | public abstract TriangulationConstraint NewConstraint(TriangulationPoint a, TriangulationPoint b); 58 | 59 | public void Update(string message) {} 60 | 61 | public virtual void Clear() { 62 | Points.Clear(); 63 | if (DebugContext != null) DebugContext.Clear(); 64 | StepCount = 0; 65 | } 66 | 67 | public virtual bool IsDebugEnabled { get; protected set; } 68 | 69 | public DTSweepDebugContext DTDebugContext { get { return DebugContext as DTSweepDebugContext; } } 70 | } 71 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/TriangulationDebugContext.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public abstract class TriangulationDebugContext { 34 | protected TriangulationContext _tcx; 35 | 36 | public TriangulationDebugContext(TriangulationContext tcx) { 37 | _tcx = tcx; 38 | } 39 | 40 | public abstract void Clear(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/TriangulationMode.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | public enum TriangulationMode { 34 | Unconstrained,Constrained,Polygon 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/TriangulationPoint.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System.Collections.Generic; 33 | 34 | namespace Poly2Tri { 35 | public class TriangulationPoint { 36 | // List of edges this point constitutes an upper ending point (CDT) 37 | public List Edges { get; private set; } 38 | 39 | public TriangulationPoint( double x, double y ) { X=x; Y=y; } 40 | 41 | public override string ToString() { 42 | return "[" + X + "," + Y + "]"; 43 | } 44 | 45 | public double X,Y; 46 | public float Xf { get { return (float)X; } set { X=value; } } 47 | public float Yf { get { return (float)Y; } set { Y=value; } } 48 | 49 | public void AddEdge(DTSweepConstraint e) { 50 | if (Edges == null) Edges = new List(); 51 | Edges.Add(e); 52 | } 53 | 54 | public bool HasEdges { get { return Edges != null; } } 55 | } 56 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/TriangulationUtil.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | namespace Poly2Tri { 33 | /** 34 | * @author Thomas Åhlén, thahlen@gmail.com 35 | */ 36 | public class TriangulationUtil { 37 | public static double EPSILON = 1e-12; 38 | ///

39 | /// Requirements: 40 | /// 1. a,b and c form a triangle. 41 | /// 2. a and d is know to be on opposite side of bc 42 | /// 43 | /// a 44 | /// + 45 | /// / \ 46 | /// / \ 47 | /// b/ \c 48 | /// +-------+ 49 | /// / B \ 50 | /// / \ 51 | /// 52 | /// Facts: 53 | /// d has to be in area B to have a chance to be inside the circle formed by a,b and c 54 | /// d is outside B if orient2d(a,b,d) or orient2d(c,a,d) is CW 55 | /// This preknowledge gives us a way to optimize the incircle test 56 | /// 57 | /// triangle point, opposite d 58 | /// triangle point 59 | /// triangle point 60 | /// point opposite a 61 | /// true if d is inside circle, false if on circle edge 62 | public static bool SmartIncircle( TriangulationPoint pa, TriangulationPoint pb, TriangulationPoint pc, TriangulationPoint pd ) { 63 | double pdx = pd.X; 64 | double pdy = pd.Y; 65 | double adx = pa.X - pdx; 66 | double ady = pa.Y - pdy; 67 | double bdx = pb.X - pdx; 68 | double bdy = pb.Y - pdy; 69 | 70 | double adxbdy = adx * bdy; 71 | double bdxady = bdx * ady; 72 | double oabd = adxbdy - bdxady; 73 | // oabd = orient2d(pa,pb,pd); 74 | if (oabd <= 0) return false; 75 | 76 | double cdx = pc.X - pdx; 77 | double cdy = pc.Y - pdy; 78 | 79 | double cdxady = cdx * ady; 80 | double adxcdy = adx * cdy; 81 | double ocad = cdxady - adxcdy; 82 | // ocad = orient2d(pc,pa,pd); 83 | if (ocad <= 0) return false; 84 | 85 | double bdxcdy = bdx * cdy; 86 | double cdxbdy = cdx * bdy; 87 | 88 | double alift = adx * adx + ady * ady; 89 | double blift = bdx * bdx + bdy * bdy; 90 | double clift = cdx * cdx + cdy * cdy; 91 | 92 | double det = alift * (bdxcdy - cdxbdy) + blift * ocad + clift * oabd; 93 | 94 | return det > 0; 95 | } 96 | 97 | public static bool InScanArea( TriangulationPoint pa, TriangulationPoint pb, TriangulationPoint pc, TriangulationPoint pd ) { 98 | double pdx = pd.X; 99 | double pdy = pd.Y; 100 | double adx = pa.X - pdx; 101 | double ady = pa.Y - pdy; 102 | double bdx = pb.X - pdx; 103 | double bdy = pb.Y - pdy; 104 | 105 | double adxbdy = adx * bdy; 106 | double bdxady = bdx * ady; 107 | double oabd = adxbdy - bdxady; 108 | // oabd = orient2d(pa,pb,pd); 109 | if (oabd <= 0) { 110 | return false; 111 | } 112 | 113 | double cdx = pc.X - pdx; 114 | double cdy = pc.Y - pdy; 115 | 116 | double cdxady = cdx * ady; 117 | double adxcdy = adx * cdy; 118 | double ocad = cdxady - adxcdy; 119 | // ocad = orient2d(pc,pa,pd); 120 | if (ocad <= 0) { 121 | return false; 122 | } 123 | return true; 124 | } 125 | 126 | /// Forumla to calculate signed area 127 | /// Positive if CCW 128 | /// Negative if CW 129 | /// 0 if collinear 130 | /// A[P1,P2,P3] = (x1*y2 - y1*x2) + (x2*y3 - y2*x3) + (x3*y1 - y3*x1) 131 | /// = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) 132 | public static Orientation Orient2d( TriangulationPoint pa, TriangulationPoint pb, TriangulationPoint pc ) { 133 | double detleft = (pa.X - pc.X) * (pb.Y - pc.Y); 134 | double detright = (pa.Y - pc.Y) * (pb.X - pc.X); 135 | double val = detleft - detright; 136 | if (val > -EPSILON && val < EPSILON) { 137 | return Orientation.Collinear; 138 | } else if (val > 0) { 139 | return Orientation.CCW; 140 | } 141 | return Orientation.CW; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Util/PointGenerator.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections.Generic; 34 | 35 | namespace Poly2Tri { 36 | public class PointGenerator { 37 | static readonly Random RNG = new Random(); 38 | 39 | public static List UniformDistribution(int n, double scale) { 40 | List points = new List(); 41 | for (int i = 0; i < n; i++) points.Add(new TriangulationPoint(scale * (0.5 - RNG.NextDouble()), scale * (0.5 - RNG.NextDouble()))); 42 | return points; 43 | } 44 | 45 | public static List UniformGrid(int n, double scale) { 46 | double x = 0; 47 | double size = scale / n; 48 | double halfScale = 0.5 * scale; 49 | 50 | List points = new List(); 51 | for (int i = 0; i < n + 1; i++) { 52 | x = halfScale - i * size; 53 | for (int j = 0; j < n + 1; j++) points.Add(new TriangulationPoint(x, halfScale - j * size)); 54 | } 55 | return points; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Triangulation/Util/PolygonGenerator.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | 34 | namespace Poly2Tri { 35 | public class PolygonGenerator { 36 | static readonly Random RNG = new Random(); 37 | 38 | private static double PI_2 = 2.0 * Math.PI; 39 | 40 | public static Polygon RandomCircleSweep(double scale, int vertexCount) { 41 | PolygonPoint point; 42 | PolygonPoint[] points; 43 | double radius = scale / 4; 44 | 45 | points = new PolygonPoint[vertexCount]; 46 | for (int i = 0; i < vertexCount; i++) { 47 | do { 48 | if (i % 250 == 0) { 49 | radius += scale / 2 * (0.5 - RNG.NextDouble()); 50 | } else if (i % 50 == 0) { 51 | radius += scale / 5 * (0.5 - RNG.NextDouble()); 52 | } else { 53 | radius += 25 * scale / vertexCount * (0.5 - RNG.NextDouble()); 54 | } 55 | radius = radius > scale / 2 ? scale / 2 : radius; 56 | radius = radius < scale / 10 ? scale / 10 : radius; 57 | } while (radius < scale / 10 || radius > scale / 2); 58 | point = new PolygonPoint(radius * Math.Cos((PI_2 * i) / vertexCount), 59 | radius * Math.Sin((PI_2 * i) / vertexCount)); 60 | points[i] = point; 61 | } 62 | return new Polygon(points); 63 | } 64 | 65 | public static Polygon RandomCircleSweep2(double scale, int vertexCount) { 66 | PolygonPoint point; 67 | PolygonPoint[] points; 68 | double radius = scale / 4; 69 | 70 | points = new PolygonPoint[vertexCount]; 71 | for (int i = 0; i < vertexCount; i++) { 72 | do { 73 | radius += scale / 5 * (0.5 - RNG.NextDouble()); 74 | radius = radius > scale / 2 ? scale / 2 : radius; 75 | radius = radius < scale / 10 ? scale / 10 : radius; 76 | } while (radius < scale / 10 || radius > scale / 2); 77 | point = new PolygonPoint(radius * Math.Cos((PI_2 * i) / vertexCount), 78 | radius * Math.Sin((PI_2 * i) / vertexCount)); 79 | points[i] = point; 80 | } 81 | return new Polygon(points); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Utility/FixedArray3.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections; 34 | using System.Collections.Generic; 35 | 36 | namespace Poly2Tri { 37 | public struct FixedArray3 : IEnumerable where T:class { 38 | public T _0, _1, _2; 39 | public T this[ int index ] { get { 40 | switch ( index ) { 41 | case 0: return _0; 42 | case 1: return _1; 43 | case 2: return _2; 44 | default: throw new IndexOutOfRangeException(); 45 | } 46 | } set { 47 | switch ( index ) { 48 | case 0: _0 = value; break; 49 | case 1: _1 = value; break; 50 | case 2: _2 = value; break; 51 | default: throw new IndexOutOfRangeException(); 52 | } 53 | }} 54 | public bool Contains( T value ) { 55 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) return true; 56 | return false; 57 | } 58 | public int IndexOf( T value ) { 59 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) return i; 60 | return -1; 61 | } 62 | public void Clear() { 63 | _0=_1=_2=null; 64 | } 65 | public void Clear( T value ) { 66 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) this[i] = null; 67 | } 68 | 69 | private IEnumerable Enumerate() { 70 | for ( int i=0 ; i<3 ; ++i ) yield return this[i]; 71 | } 72 | public IEnumerator GetEnumerator() { return Enumerate().GetEnumerator(); } 73 | IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Triangulation/Utility/FixedBitArray3.cs: -------------------------------------------------------------------------------- 1 | /* Poly2Tri 2 | * Copyright (c) 2009-2010, Poly2Tri Contributors 3 | * http://code.google.com/p/poly2tri/ 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * * Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * * Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * * Neither the name of Poly2Tri nor the names of its contributors may be 16 | * used to endorse or promote products derived from this software without specific 17 | * prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | using System; 33 | using System.Collections; 34 | using System.Collections.Generic; 35 | 36 | namespace Poly2Tri { 37 | public struct FixedBitArray3 : IEnumerable { 38 | public bool _0, _1, _2; 39 | public bool this[ int index ] { get { 40 | switch ( index ) { 41 | case 0: return _0; 42 | case 1: return _1; 43 | case 2: return _2; 44 | default: throw new IndexOutOfRangeException(); 45 | } 46 | } set { 47 | switch ( index ) { 48 | case 0: _0 = value; break; 49 | case 1: _1 = value; break; 50 | case 2: _2 = value; break; 51 | default: throw new IndexOutOfRangeException(); 52 | } 53 | }} 54 | public bool Contains( bool value ) { 55 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) return true; 56 | return false; 57 | } 58 | public int IndexOf( bool value ) { 59 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) return i; 60 | return -1; 61 | } 62 | public void Clear() { 63 | _0=_1=_2=false; 64 | } 65 | public void Clear( bool value ) { 66 | for ( int i = 0 ; i < 3 ; ++i ) if ( this[i]==value ) this[i] = false; 67 | } 68 | 69 | private IEnumerable Enumerate() { 70 | for ( int i=0 ; i<3 ; ++i ) yield return this[i]; 71 | } 72 | public IEnumerator GetEnumerator() { return Enumerate().GetEnumerator(); } 73 | IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Utils/Bone2DWeight.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Banbury 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | using UnityEngine; 25 | using System.Collections; 26 | using System.Collections.Generic; 27 | using System.Linq; 28 | 29 | [System.Serializable] 30 | public class Bone2DWeights { 31 | public Bone2DWeight[] weights = new Bone2DWeight[] {}; 32 | 33 | public Bone2DWeight[] this[string name] { 34 | get { 35 | return weights.Where(b => b.boneName == name).ToArray(); 36 | } 37 | } 38 | 39 | public int Count { 40 | get { 41 | return weights.Length; 42 | } 43 | } 44 | 45 | public string[] GetBones() { 46 | return weights.Select(b => b.boneName).ToArray(); 47 | } 48 | 49 | public float GetWeight(int vertex, string bone) { 50 | return weights.Where(b => b.boneName == bone && b.vertex == vertex).First().weight; 51 | } 52 | 53 | public void SetWeight(int vertex, string bone, int index, float weight) { 54 | Bone2DWeight bw = weights.Where(b => b.boneName == bone && b.vertex == vertex).FirstOrDefault(); 55 | if (bw != null) { 56 | bw.weight = weight; 57 | } 58 | else { 59 | bw = new Bone2DWeight(bone, index, vertex, weight); 60 | 61 | List w = new List(weights); 62 | w.Add(bw); 63 | weights = w.ToArray(); 64 | } 65 | } 66 | 67 | public BoneWeight[] GetUnityBoneWeights() { 68 | List bweights = new List(); 69 | 70 | var groups = weights.GroupBy(bw => bw.vertex); 71 | 72 | foreach (var g in groups) { 73 | var wv = g.Where(w => w.weight > 0).ToList(); 74 | 75 | float max = wv.Sum(bw => bw.weight); 76 | 77 | if (max > 1.0f) { 78 | wv.ForEach(bw => bw.weight = bw.weight / max); 79 | } 80 | 81 | int i = 0; 82 | 83 | BoneWeight bweight = new BoneWeight(); 84 | 85 | foreach (Bone2DWeight w in wv) { 86 | switch (i) { 87 | case 0: 88 | bweight.boneIndex0 = w.index; 89 | bweight.weight0 = w.weight; 90 | break; 91 | case 1: 92 | bweight.boneIndex1 = w.index; 93 | bweight.weight1 = w.weight; 94 | break; 95 | case 2: 96 | bweight.boneIndex2 = w.index; 97 | bweight.weight2 = w.weight; 98 | break; 99 | case 3: 100 | bweight.boneIndex3 = w.index; 101 | bweight.weight3 = w.weight; 102 | break; 103 | } 104 | i++; 105 | } 106 | 107 | bweights.Add(bweight); 108 | } 109 | 110 | return bweights.ToArray(); 111 | } 112 | } 113 | 114 | [System.Serializable] 115 | public class Bone2DWeight { 116 | public int index; 117 | public string boneName; 118 | public int vertex; 119 | public float weight; 120 | 121 | public Bone2DWeight(string name, int index, int vertex, float weight) { 122 | this.boneName = name; 123 | this.index = index; 124 | this.vertex = vertex; 125 | this.weight = weight; 126 | } 127 | 128 | public override string ToString() { 129 | return string.Format("{0}: {1} {2} {3}", index, boneName, vertex, weight); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Utils/SpriteMesh.cs: -------------------------------------------------------------------------------- 1 | /* 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2014 Play-Em 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | using UnityEngine; 26 | #if UNITY_EDITOR 27 | using UnityEditor; 28 | using System.IO; 29 | #endif 30 | using System; 31 | using System.Collections; 32 | using System.Linq; 33 | 34 | public class SpriteMesh { 35 | #if UNITY_EDITOR 36 | 37 | public SpriteRenderer spriteRenderer; 38 | 39 | public void CreateSpriteMesh() 40 | { 41 | if (spriteRenderer != null && spriteRenderer.sprite != null) 42 | { 43 | // Unparent the skin temporarily before adding the mesh 44 | Transform spriteRendererParent = spriteRenderer.transform.parent; 45 | spriteRenderer.transform.parent = null; 46 | 47 | // Reset the rotation before creating the mesh so the UV's will align properly 48 | Quaternion localRotation = spriteRenderer.transform.localRotation; 49 | spriteRenderer.transform.localRotation = Quaternion.identity; 50 | 51 | // Reset the scale before creating the mesh so the UV's will align properly 52 | Vector3 localScale = spriteRenderer.transform.localScale; 53 | spriteRenderer.transform.localScale = Vector3.one; 54 | 55 | Vector2[] vertices2D = spriteRenderer.sprite.vertices; 56 | int[] indices = spriteRenderer.sprite.triangles.Select(element => (int)element).ToArray(); 57 | 58 | // Create the Vector3 vertices 59 | Vector3[] vertices = new Vector3[vertices2D.Length]; 60 | for (int i=0; i m_points) { 11 | List indices = new List(); 12 | 13 | int n = m_points.Count; 14 | if (n < 3) 15 | return indices.ToArray(); 16 | 17 | int[] V = new int[n]; 18 | if (Area(m_points) > 0) { 19 | for (int v = 0; v < n; v++) 20 | V[v] = v; 21 | } 22 | else { 23 | for (int v = 0; v < n; v++) 24 | V[v] = (n - 1) - v; 25 | } 26 | 27 | int nv = n; 28 | int count = 2 * nv; 29 | for (int m = 0, v = nv - 1; nv > 2; ) { 30 | if ((count--) <= 0) 31 | return indices.ToArray(); 32 | 33 | int u = v; 34 | if (nv <= u) 35 | u = 0; 36 | v = u + 1; 37 | if (nv <= v) 38 | v = 0; 39 | int w = v + 1; 40 | if (nv <= w) 41 | w = 0; 42 | 43 | if (Snip(m_points, u, v, w, nv, V)) { 44 | int a, b, c, s, t; 45 | a = V[u]; 46 | b = V[v]; 47 | c = V[w]; 48 | indices.Add(a); 49 | indices.Add(b); 50 | indices.Add(c); 51 | m++; 52 | for (s = v, t = v + 1; t < nv; s++, t++) 53 | V[s] = V[t]; 54 | nv--; 55 | count = 2 * nv; 56 | } 57 | } 58 | 59 | indices.Reverse(); 60 | return indices.ToArray(); 61 | } 62 | 63 | private static float Area(IList m_points) { 64 | int n = m_points.Count; 65 | float A = 0.0f; 66 | for (int p = n - 1, q = 0; q < n; p = q++) { 67 | Vector2 pval = m_points[p]; 68 | Vector2 qval = m_points[q]; 69 | A += pval.x * qval.y - qval.x * pval.y; 70 | } 71 | return (A * 0.5f); 72 | } 73 | 74 | private static bool Snip(IList m_points, int u, int v, int w, int n, int[] V) { 75 | int p; 76 | Vector2 A = m_points[V[u]]; 77 | Vector2 B = m_points[V[v]]; 78 | Vector2 C = m_points[V[w]]; 79 | if (Mathf.Epsilon > (((B.x - A.x) * (C.y - A.y)) - ((B.y - A.y) * (C.x - A.x)))) 80 | return false; 81 | for (p = 0; p < n; p++) { 82 | if ((p == u) || (p == v) || (p == w)) 83 | continue; 84 | Vector2 P = m_points[V[p]]; 85 | if (InsideTriangle(A, B, C, P)) 86 | return false; 87 | } 88 | return true; 89 | } 90 | 91 | private static bool InsideTriangle(Vector2 A, Vector2 B, Vector2 C, Vector2 P) { 92 | float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy; 93 | float cCROSSap, bCROSScp, aCROSSbp; 94 | 95 | ax = C.x - B.x; ay = C.y - B.y; 96 | bx = A.x - C.x; by = A.y - C.y; 97 | cx = B.x - A.x; cy = B.y - A.y; 98 | apx = P.x - A.x; apy = P.y - A.y; 99 | bpx = P.x - B.x; bpy = P.y - B.y; 100 | cpx = P.x - C.x; cpy = P.y - C.y; 101 | 102 | aCROSSbp = ax * bpy - ay * bpx; 103 | cCROSSap = cx * apy - cy * apx; 104 | bCROSScp = bx * cpy - by * cpx; 105 | 106 | return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); 107 | } 108 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Scripts/Utils/Utils.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public static class Utils { 4 | public static float ClampAngle(float x) { 5 | return x - 360 * Mathf.Floor(x / 360); 6 | } 7 | 8 | public static float GetWeight(this BoneWeight bw, int index) { 9 | if (bw.boneIndex0 == index && bw.weight0 > 0) { 10 | return bw.weight0; 11 | } 12 | if (bw.boneIndex1 == index && bw.weight1 > 0) { 13 | return bw.weight1; 14 | } 15 | if (bw.boneIndex2 == index && bw.weight2 > 0) { 16 | return bw.weight2; 17 | } 18 | if (bw.boneIndex3 == index && bw.weight3 > 0) { 19 | return bw.weight3; 20 | } 21 | return 0; 22 | } 23 | 24 | public static BoneWeight SetWeight(this BoneWeight bw, int index, float value) { 25 | if (bw.boneIndex0 == index || bw.weight0 == 0) { 26 | bw.boneIndex0 = index; 27 | bw.weight0 = value; 28 | } 29 | else if (bw.boneIndex1 == index || bw.weight1 == 0) { 30 | bw.boneIndex1 = index; 31 | bw.weight1 = value; 32 | } 33 | else if (bw.boneIndex2 == index || bw.weight2 == 0) { 34 | bw.boneIndex2 = index; 35 | bw.weight2 = value; 36 | } 37 | else if (bw.boneIndex3 == index || bw.weight3 == 0) { 38 | bw.boneIndex3 = index; 39 | bw.weight3 = value; 40 | } 41 | else { 42 | bw.boneIndex0 = index; 43 | bw.weight0 = value; 44 | } 45 | 46 | float max = bw.weight0 + bw.weight1 + bw.weight2 + bw.weight3; 47 | if (max > 1) { 48 | bw.weight0 /= max; 49 | bw.weight1 /= max; 50 | bw.weight2 /= max; 51 | bw.weight3 /= max; 52 | } 53 | 54 | return bw; 55 | } 56 | 57 | public static void Log(this BoneWeight bw) { 58 | Debug.Log( 59 | "Index0: " + bw.boneIndex0 + " Weight0: " + bw.weight0 + "\n" + 60 | "Index1: " + bw.boneIndex1 + " Weight1: " + bw.weight1 + "\n" + 61 | "Index2: " + bw.boneIndex2 + " Weight2: " + bw.weight2 + "\n" + 62 | "Index3: " + bw.boneIndex3 + " Weight3: " + bw.weight3 63 | ); 64 | } 65 | 66 | public static Mesh Clone(this Mesh m) { 67 | Mesh copy = new Mesh(); 68 | 69 | copy.vertices = m.vertices; 70 | copy.triangles = m.triangles; 71 | copy.normals = m.normals; 72 | copy.bindposes = m.bindposes; 73 | copy.bounds = m.bounds; 74 | copy.uv = m.uv; 75 | copy.uv2 = m.uv2; 76 | copy.boneWeights = m.boneWeights; 77 | //copy.colors = m.colors; 78 | copy.tangents = m.tangents; 79 | 80 | return copy; 81 | } 82 | 83 | public static BoneWeight Clone(this BoneWeight bw) { 84 | BoneWeight ret = new BoneWeight(); 85 | ret.boneIndex0 = bw.boneIndex0; 86 | ret.boneIndex1 = bw.boneIndex1; 87 | ret.boneIndex2 = bw.boneIndex2; 88 | ret.boneIndex3 = bw.boneIndex3; 89 | ret.weight0 = bw.weight0; 90 | ret.weight1 = bw.weight1; 91 | ret.weight2 = bw.weight2; 92 | ret.weight3 = bw.weight3; 93 | 94 | return ret; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Shader/LinesColoredBlended.shader: -------------------------------------------------------------------------------- 1 | Shader "Lines/Colored Blended" { 2 | Properties { 3 | _Color("Color & Transparency", Color) = (0, 0, 0, 1.0) 4 | } 5 | 6 | SubShader { 7 | ColorMaterial AmbientAndDiffuse 8 | Pass { 9 | Blend SrcAlpha OneMinusSrcAlpha 10 | ZWrite On 11 | Cull Off 12 | Fog { Mode Off } 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Shader/Sprites-Skeleton-Cutout.shader: -------------------------------------------------------------------------------- 1 | Shader "Sprites/Skeleton-CutOut" 2 | { 3 | Properties 4 | { 5 | [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} 6 | [PerRendererData] _Color ("Tint", Color) = (1,1,1,1) 7 | [PerRendererData] _Normal ("Normal", vector) = (0,0,-1, 0) // Normals set by script 8 | [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 9 | _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.5 10 | } 11 | 12 | SubShader 13 | { 14 | Tags 15 | { 16 | "Queue"="Transparent" 17 | "IgnoreProjector"="True" 18 | "RenderType"="TransparentCutOut" 19 | "PreviewType"="Plane" 20 | "CanUseSpriteAtlas"="True" 21 | } 22 | 23 | Cull Off 24 | Lighting On 25 | ZWrite On 26 | Offset -1, -1 27 | Fog { Mode Off } 28 | Blend One OneMinusSrcAlpha 29 | 30 | CGPROGRAM 31 | #pragma surface surf Lambert alpha:blend addshadow vertex:vert fullforwardshadows 32 | #pragma multi_compile DUMMY PIXELSNAP_ON 33 | #pragma multi_compile_instancing 34 | 35 | sampler2D _MainTex; 36 | fixed4 _Color; 37 | float3 _Normal; 38 | 39 | struct Input 40 | { 41 | float2 uv_MainTex; 42 | fixed4 color; 43 | }; 44 | 45 | void vert (inout appdata_full v, out Input o) 46 | { 47 | #if defined(PIXELSNAP_ON) && !defined(SHADER_API_FLASH) 48 | v.vertex = UnityPixelSnap (v.vertex); 49 | #endif 50 | v.normal = _Normal; 51 | 52 | UNITY_INITIALIZE_OUTPUT(Input, o); 53 | o.color = v.color * _Color; 54 | } 55 | 56 | void surf (Input IN, inout SurfaceOutput o) 57 | { 58 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color; 59 | o.Albedo = c.rgb; 60 | o.Alpha = c.a; 61 | } 62 | ENDCG 63 | } 64 | 65 | Fallback "Transparent/Cutout/VertexLit" 66 | } 67 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Shader/Sprites-Skeleton-Diffuse.shader: -------------------------------------------------------------------------------- 1 | Shader "Sprites/Skeleton-Diffuse" 2 | { 3 | Properties 4 | { 5 | [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} 6 | [PerRendererData] _Color ("Tint", Color) = (1,1,1,1) 7 | [PerRendererData] _Normal ("Normal", vector) = (0,0,-1, 0) // Normals set by script 8 | [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 9 | } 10 | 11 | SubShader 12 | { 13 | Tags 14 | { 15 | "Queue"="Transparent" 16 | "IgnoreProjector"="True" 17 | "RenderType"="Transparent" 18 | "PreviewType"="Plane" 19 | "CanUseSpriteAtlas"="True" 20 | } 21 | 22 | Cull Off 23 | Lighting Off 24 | ZWrite Off 25 | Fog { Mode Off } 26 | Blend One OneMinusSrcAlpha 27 | 28 | CGPROGRAM 29 | #pragma surface surf Lambert vertex:vert 30 | #pragma multi_compile DUMMY PIXELSNAP_ON 31 | #pragma multi_compile_instancing 32 | 33 | sampler2D _MainTex; 34 | fixed4 _Color; 35 | float3 _Normal; 36 | 37 | struct Input 38 | { 39 | float2 uv_MainTex; 40 | fixed4 color; 41 | }; 42 | 43 | void vert (inout appdata_full v, out Input o) 44 | { 45 | #if defined(PIXELSNAP_ON) && !defined(SHADER_API_FLASH) 46 | v.vertex = UnityPixelSnap (v.vertex); 47 | #endif 48 | v.normal = _Normal; 49 | 50 | UNITY_INITIALIZE_OUTPUT(Input, o); 51 | o.color = v.color * _Color; 52 | } 53 | 54 | void surf (Input IN, inout SurfaceOutput o) 55 | { 56 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color; 57 | o.Albedo = c.rgb * c.a; 58 | o.Alpha = c.a; 59 | } 60 | ENDCG 61 | } 62 | 63 | Fallback "Transparent/VertexLit" 64 | } 65 | -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Textures/orc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/Assets/SpritesAndBones/Textures/orc.png -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Textures/sintel_tpose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/Assets/SpritesAndBones/Textures/sintel_tpose.png -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Textures/spock_body.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/Assets/SpritesAndBones/Textures/spock_body.png -------------------------------------------------------------------------------- /Assets/SpritesAndBones/Textures/spock_head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/Assets/SpritesAndBones/Textures/spock_head.png -------------------------------------------------------------------------------- /Assets/SpritesAndBones/license-attributions.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/Assets/SpritesAndBones/license-attributions.txt -------------------------------------------------------------------------------- /Bones.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Banbury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Banbury/UnitySpritesAndBones/e1afe4313b979fd0818772cf1a6e24a2eb0c8a56/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Unity Sprites And Bones 2 | ======================= 3 | 4 | This is an addon for Unity 3D to create 2D skeletal sprite animations. With the addon its possible to add bone hierarchies directly in the Unity Editor. Sprites can the parented to the bones. The bones can be animated like any other GameObject in the animator window. Inverse Kinematics is also available and animatable. The bones can also be used to animate any GameObject other than sprites like meshes or particle systems. 5 | 6 | ## Features 7 | 8 | * Skeletons and Bones. 9 | * Mesh deformation 10 | * Inverse Kinematics with targets. 11 | * IK Helper objects. 12 | * IK Angle Constraints. 13 | * Bones and IK are fully animatable. 14 | * Bones can be added by holding Ctrl and left clicking. 15 | * Bone splitting (Subdivision). 16 | * Flip Skeletons and Bones on X or Y Axis at the push of a button. 17 | * Mesh creation for Skinnable Meshes using custom mesh creation tools. Meshes are saved as assets. 18 | * Free Form Deformation using control points. 19 | * Shaders that support shadows and z-zorting (can be customized per Skeleton). 20 | * Scaling of root object of Skeleton. 21 | * Saving and loading of poses. Poses are saved as assets. 22 | * Helper tools to sort render layers, copy positions and rotations between objects, and create materials for renderers. 23 | * 2D Ragdoll creation. 24 | * Fully integrated in the Unity Editor. 25 | * Undo-Support 26 | * Lots of gizmos! 27 | * Did I mention Inverse Kinematics? 28 | * Free and Opensource 29 | 30 | 31 | Screenshots: 32 | * http://postimg.org/image/r5s36j053 33 | * http://postimg.org/image/g7dd50agv/ 34 | 35 | Forum thread: 36 | * http://forum.unity3d.com/threads/219915-Release-Free-Unity-Sprites-And-Bones-2D-skeleton-animation 37 | 38 | 39 | ## Tutorial read the 2DSkeletalAnimation.pdf for an explanation of how to set up and use this tool. 40 | 41 | 42 | Demo of how to use sprites and bones with this fork: 43 | 44 | * https://www.youtube.com/watch?feature=player_embedded&v=9QK4h9IocZU 45 | 46 | * https://www.youtube.com/watch?feature=player_embedded&v=bsd8lpesiTE 47 | 48 | 49 | ## Installation 50 | After importing into a new project, the Gizmo folder has to be moved to the Asset folder. Otherwise some icons won't show up in the editor and the hierarchy. 51 | -------------------------------------------------------------------------------- /UnitySpritesAndBones.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | task pack(type:Exec) { 2 | workingDir '.' 3 | commandLine unityPath, '-batchmode', '-nographics', '-exportPackage', 'Assets\\SpritesAndBones', 'SpritesAndBones.unitypackage', '-quit' 4 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | unityPath=c:\\Program Files (x86)\\Unity\\Editor\\unity.exe --------------------------------------------------------------------------------