Skip to content

Instantly share code, notes, and snippets.

@Arakade
Last active Aug 29, 2015
Embed
What would you like to do?
Patch for Unity3D Dynamic Bone asset to add debugging data to the OnDrawGizmos() call. http://forum.unity3d.com/threads/dynamic-bone-realistic-swaying-ponytail-and-bouncing-boobs.245418
diff --git "a/DynamicBone-e916f4c-left.cs" "b/Assets\\DynamicBone\\Scripts\\DynamicBone.cs"
index 9d2c66e..38dbf58 100644
--- "a/DynamicBone-e916f4c-left.cs"
+++ "b/\\Assets\\DynamicBone\\Scripts\\DynamicBone.cs"
@@ -57,6 +57,17 @@ public class DynamicBone : MonoBehaviour
public Vector3 m_EndOffset = Vector3.zero;
public Vector3 m_InitLocalPosition = Vector3.zero;
public Quaternion m_InitLocalRotation = Quaternion.identity;
+
+ public override string ToString()
+ {
+ return string.Format("boneLength:{0}, damping:{1}, elasticity:{2}, stiffness:{3}, radius:{4}, \"{6}\"",
+ m_BoneLength, m_Damping, m_Elasticity, m_Stiffness, m_Inert, m_Radius, m_Transform.name);
+ }
+ public string ToString(DynamicBone b)
+ {
+ float a = m_BoneLength / b.m_BoneTotalLength;
+ return a.ToString() + ": " + ToString();
+ }
}
List<Particle> m_Particles = new List<Particle>();
@@ -120,13 +131,18 @@ public class DynamicBone : MonoBehaviour
SetupParticles();
}
- Gizmos.color = Color.white;
+ var startColor = Color.green;
+ var endColor = Color.white;
+ float numParticles = m_Particles.Count;
+ float i = 0;
foreach (Particle p in m_Particles)
{
+ var pColor = Gizmos.color = Color.Lerp(startColor, endColor, i++ / numParticles);
if (p.m_ParentIndex >= 0)
{
Particle p0 = m_Particles[p.m_ParentIndex];
Gizmos.DrawLine(p.m_Position, p0.m_Position);
+ drawString(p.ToString(this), p.m_Position, pColor);
}
if (p.m_Radius > 0)
{
@@ -135,6 +151,17 @@ public class DynamicBone : MonoBehaviour
}
}
+ static void drawString(string text, Vector3 worldPos, Color? colour = null)
+ {
+ UnityEditor.Handles.BeginGUI();
+ if (colour.HasValue) GUI.color = colour.Value;
+ var view = UnityEditor.SceneView.currentDrawingSceneView;
+ Vector3 screenPos = view.camera.WorldToScreenPoint(worldPos);
+ Vector2 size = GUI.skin.label.CalcSize(new GUIContent(text));
+ GUI.Label(new Rect(screenPos.x - (size.x / 2), -screenPos.y + view.position.height + 4, size.x, size.y), text);
+ UnityEditor.Handles.EndGUI();
+ }
+
public void SetWeight(float w)
{
if (m_Weight != w)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment