public void searchNodes() { Transform[] children = gameObject.GetComponentsInChildren <Transform>(); Nodes = new Transform[(int)HandBoneIndex.Count]; foreach (Transform child in children) { try { HandBoneIndex index = (HandBoneIndex)System.Enum.Parse(typeof(HandBoneIndex), child.name, true); Nodes[(int)index] = child; } catch (System.ArgumentException) { } } for (HandBoneIndex i = HandBoneIndices.Begin; i < HandBoneIndices.End; ++i) { if (!Nodes[(int)i]) { Debug.LogError("HandRig: Node of not found: " + i.ToString()); } } Debug.Log("HandRig: nodes load."); }
public override void OnInspectorGUI() { HandController t = target as HandController; if (t.Gears.Count == 0) { t.createGears(); } EditorGUILayout.LabelField("Gears:"); { EditorGUI.indentLevel++; foreach (var entry in t.Gears) { entry.Value.angle = EditorGUILayout.FloatField(entry.Key.ToString().ToLower(), entry.Value.angle); } EditorGUI.indentLevel--; } EditorGUILayout.Space(); if (GUILayout.Button("Generate Skeleton")) { Transform parent = t.transform; for (HandBoneIndex i = HandBoneIndices.WristStart; i < HandBoneIndices.WristEnd; ++i) { parent = createBoneNode(parent, i); } Transform thumb = parent, index = parent, middle = parent, ring = parent, pinky = parent; for (HandBoneIndex i = HandBoneIndices.ThumbStart; i < HandBoneIndices.ThumbEnd; ++i) { thumb = createBoneNode(thumb, i); } for (HandBoneIndex i = HandBoneIndices.IndexStart; i < HandBoneIndices.IndexEnd; ++i) { index = createBoneNode(index, i); } for (HandBoneIndex i = HandBoneIndices.MiddleStart; i < HandBoneIndices.MiddleEnd; ++i) { middle = createBoneNode(middle, i); } for (HandBoneIndex i = HandBoneIndices.RingStart; i < HandBoneIndices.RingEnd; ++i) { ring = createBoneNode(ring, i); } for (HandBoneIndex i = HandBoneIndices.PinkyStart; i < HandBoneIndices.PinkyEnd; ++i) { pinky = createBoneNode(pinky, i); } HandRig rig = t.GetComponent <HandRig>(); if (rig) { rig.searchNodes(); } } }
private Transform createBoneNode(Transform parent, HandBoneIndex name) { string sname = ((HandBoneIndex)(int)name).ToString().ToLower(); Transform trans = parent.Find(sname); if (trans == null) { GameObject obj; if (name > HandBoneIndices.WristEnd && System.Array.IndexOf(HandBoneIndices.Positions, name + 1) >= 0 && System.Array.IndexOf(HandBoneIndices.Tips, name) < 0) { obj = GameObject.Instantiate(Resources.Load <GameObject>("Prefabs/bone")); obj.name = sname; } else { obj = new GameObject(sname); } obj.transform.parent = parent; trans = obj.transform; BoneMarker marker = parent.GetComponent <BoneMarker>(); if (marker) { marker.Tip = trans; } } return(trans); }
public YAMLNode ExportYAML(IExportContainer container) { YAMLMappingNode node = new YAMLMappingNode(); node.Add(HandBoneIndexName, HandBoneIndex.ExportYAML(true)); return(node); }
public Gear(Transform trans, HandBoneIndex bone, HandRig rig, GearMoving onMoving_) { transform = trans; axis = HandBoneIndices.RotationAxies[(int)bone]; int index = System.Array.IndexOf(HandBoneIndices.RangedAngles, bone); range = rig.Data.RangedAngles[index]; onMoving = onMoving_; }
void onGearMoving(HandBoneIndex bone, float angle) { //Debug.Log("onGearMoving: " + bone.ToString()); HandBoneIndex linkage; if (HandBoneIndices.Linkages.TryGetValue(bone, out linkage)) { int sourceIndex = System.Array.IndexOf(HandBoneIndices.RangedAngles, bone); HandRigData.Range sourceRange = Rig.Data.RangedAngles[sourceIndex]; float amplitude = (angle - sourceRange.low) / (sourceRange.high - sourceRange.low); int targetIndex = System.Array.IndexOf(HandBoneIndices.RangedAngles, linkage); HandRigData.Range targetRange = Rig.Data.RangedAngles[targetIndex]; float targetAmp = (Gears[linkage].angle - targetRange.low) / (targetRange.high - targetRange.low); if (Mathf.Abs(targetAmp - amplitude) > 0.05f) { Gears[linkage].angle = targetRange.low + (targetRange.high - targetRange.low) * amplitude; } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { //HandRigData data = attribute as HandRigData; HandRigData data = fieldInfo.GetValue(property.serializedObject.targetObject) as HandRigData; EditorGUI.BeginProperty(position, label, property); float y = position.y; showPositions = EditorGUI.Foldout(new Rect(position.x, y, position.width, LINE_HEIGHT), showPositions, "Positions:"); y += LINE_HEIGHT; if (showPositions) { EditorGUI.indentLevel++; for (int i = 0; i < HandBoneIndices.Positions.Length; ++i) { HandBoneIndex index = HandBoneIndices.Positions[i]; data.Positions[i] = EditorGUI.Vector3Field(new Rect(position.x, y, position.width, LINE_HEIGHT), index.ToString().ToLower(), data.Positions[i]); y += LINE_HEIGHT; } EditorGUI.indentLevel--; } showOrientations = EditorGUI.Foldout(new Rect(position.x, y, position.width, LINE_HEIGHT), showOrientations, "FixedAngles:"); y += LINE_HEIGHT; if (showOrientations) { EditorGUI.indentLevel++; for (int i = 0; i < HandBoneIndices.FixedAngles.Length; ++i) { HandBoneIndex index = HandBoneIndices.FixedAngles[i]; data.FixedAngles[i] = EditorGUI.FloatField(new Rect(position.x, y, position.width, LINE_HEIGHT), index.ToString().ToLower(), data.FixedAngles[i]); y += LINE_HEIGHT; } EditorGUI.indentLevel--; } showRanges = EditorGUI.Foldout(new Rect(position.x, y, position.width, LINE_HEIGHT), showRanges, "RangedAngles:"); y += LINE_HEIGHT; if (showRanges) { EditorGUI.indentLevel++; for (int i = 0; i < HandBoneIndices.RangedAngles.Length; ++i) { HandBoneIndex index = HandBoneIndices.RangedAngles[i]; EditorGUI.LabelField(new Rect(position.x, y, position.width * 0.3f, LINE_HEIGHT), index.ToString().ToLower()); data.RangedAngles[i].low = EditorGUI.FloatField(new Rect(position.x + position.width * 0.3f, y, position.width * 0.35f, LINE_HEIGHT), "", data.RangedAngles[i].low); data.RangedAngles[i].high = EditorGUI.FloatField(new Rect(position.x + position.width * 0.65f, y, position.width * 0.35f, LINE_HEIGHT), "", data.RangedAngles[i].high); y += LINE_HEIGHT; } EditorGUI.indentLevel--; } //Debug.Log("position: " + position.ToString()); EditorGUI.EndProperty(); }