public JointWrapper this[nuitrack.JointType jointType] { get { return new JointWrapper(serializedObject.FindProperty(jointMapFields[jointType]), serializedObject); } }
void DrawAssignedBones(Dictionary <nuitrack.JointType, Transform> includeBones) { foreach (KeyValuePair <nuitrack.JointType, Transform> jointTransform in includeBones) { nuitrack.JointType joint = jointTransform.Key; nuitrack.JointType parent = joint.GetParent(); Transform transform = jointTransform.Value; float dist = includeBones.ContainsKey(parent) ? Vector3.Distance(transform.position, includeBones[parent].position) : 0; List <Transform> childs = new List <Transform>(); Handles.color = SelectedJoint == joint?Color.Lerp(mainColor, select, 0.5f) : mainColor; if (childsList.ContainsKey(joint)) { foreach (nuitrack.JointType childJoint in childsList[joint]) { if (includeBones.ContainsKey(childJoint)) { Transform childTransform = includeBones[childJoint]; dist += Vector3.Distance(transform.position, childTransform.position); childs.Add(childTransform); } } } int countJoints = childs.Count + (includeBones.ContainsKey(parent) ? 2 : 1); dist = Math.Max(minSizeAssignBoneMark, dist / countJoints); int controlID = GUIUtility.GetControlID(root.name.GetHashCode(), FocusType.Passive); DrawBoneController(controlID, transform, childs, joint, dist * jointSphereMult); } }
void SkeletonMapper_OnSelected(nuitrack.JointType jointType) { if (jointType == nuitrack.JointType.None) { SelectedJoint = nuitrack.JointType.None; } else { if (poseWrapper[jointType].IsActive && SelectedJoint != jointType) { SelectedJoint = jointType; } else { if (poseWrapper[jointType].IsActive) { OnBoneDeactivated(jointType); } else { OnBoneActivated(jointType); } } } }
/// <summary> /// Adding distance between target and parent model bones /// </summary> void AddBoneScale(nuitrack.JointType targetJoint, nuitrack.JointType parentJoint) { Vector3 targetBonePos = jointsRigged[targetJoint].bone.position; Vector3 parentBonePos = jointsRigged[parentJoint].bone.position; jointsRigged[targetJoint].parentBone = jointsRigged[parentJoint].bone; jointsRigged[targetJoint].baseDistanceToParent = Vector3.Distance(parentBonePos, targetBonePos); }
private void RefreshBodyLocation(nuitrack.Skeleton skeleton, GameObject body) { nuitrack.JointType Anchor = nuitrack.JointType.Torso; Vector3 pos = Quaternion.Euler(0f, 180f, 0f) * (0.001f * skeleton.GetJoint(Anchor).ToVector3()); body.transform.position = pos; }
void SkeletonBonesView_OnRemoveBone(SkeletonBonesView.ViewMode viewMode, JointType jointType, Transform boneTransform) { switch (viewMode) { case SkeletonBonesView.ViewMode.AssignedBones: SkeletonMapper_onDrop(null, jointType); break; } }
void OnBoneActivated(nuitrack.JointType jointType) { if (!poseWrapper[jointType].IsActive) { poseWrapper[jointType].IsActive = true; } SelectedJoint = jointType; }
/// <summary> /// Get a shell object for the specified joint /// </summary> /// <param name="jointType">Joint type</param> /// <returns>Shell object <see cref="UserData.SkeletonData.Joint"/></returns> public UserData.SkeletonData.Joint GetJoint(nuitrack.JointType jointType) { if (!IsActive || ControllerUser.Skeleton == null) { return(null); } return(ControllerUser.Skeleton.GetJoint(jointType)); }
void SetJoint(Transform tr, JointType jointType) { ModelJoint modelJoint = new ModelJoint() { bone = tr, jointType = jointType }; modelJoints.Add(modelJoint); }
void EditJoint(JointType jointType, Transform objectTransform) { SerializedProperty jointProperty = GetJointProperty(jointType); if (jointProperty != null) { jointProperty.objectReferenceValue = objectTransform; serializedObject.ApplyModifiedProperties(); } }
/// <summary> /// Adding distance between the target and parent model bones /// </summary> void AddBoneScale(JointType targetJoint, JointType parentJoint) { //take the position of the model bone Vector3 targetBonePos = jointsRigged[targetJoint].bone.position; //take the position of the model parent bone Vector3 parentBonePos = jointsRigged[parentJoint].bone.position; jointsRigged[targetJoint].baseDistanceToParent = Vector3.Distance(parentBonePos, targetBonePos); //record the Transform of the model parent bone jointsRigged[targetJoint].parentBone = jointsRigged[parentJoint].bone; }
/// <summary> /// Returns the appropriate HumanBodyBones for nuitrack.JointType /// </summary> /// <param name="nuitrackJoint">nuitrack.JointType</param> /// <returns>HumanBodyBones</returns> public static HumanBodyBones ToUnityBones(this JointType nuitrackJoint) { if (nuitrackToUnity.ContainsKey(nuitrackJoint)) { return(nuitrackToUnity[nuitrackJoint]); } else { return(HumanBodyBones.LastBone); } }
public static JointType TryGetMirrored(this JointType joint) { JointType mirroredJoint = joint; if (NuitrackManager.DepthSensor.IsMirror() && mirroredJoints.ContainsKey(joint)) { mirroredJoints.TryGetValue(joint, out mirroredJoint); } return(mirroredJoint); }
public static JointType GetParent(this JointType jointType) { if (parentJoints.ContainsKey(jointType)) { return(parentJoints[jointType]); } else { return(JointType.None); } }
void OnBoneDeactivated(nuitrack.JointType jointType) { if (poseWrapper[jointType].IsActive) { poseWrapper[jointType].IsActive = false; if (!poseWrapper[jointType].IsActive && jointType == SelectedJoint) { SelectedJoint = nuitrack.JointType.None; } } }
public static Vector3 GetNormalDirection(this JointType jointType) { if (jointsDirections.ContainsKey(jointType)) { return(jointsDirections[jointType]); } else { Debug.LogError(string.Format("Direction is not defined for the joint {0}, Vector3.zero will be returned", jointType)); return(Vector3.zero); } }
static void FillChildRecursive(JointType jointType, ref List <JointType> jointsList) { if (childJoints.ContainsKey(jointType)) { List <JointType> childList = childJoints[jointType]; jointsList.AddRange(childList); foreach (JointType child in childList) { FillChildRecursive(child, ref jointsList); } } }
/// <summary> /// Adding distance between the target and parent model bones /// </summary> void AddBoneScale(nuitrack.JointType targetJoint, nuitrack.JointType parentJoint) { //take the position of the model bone Vector3 targetBonePos = jointsRigged[targetJoint].bone.position; //take the position of the model parent bone Vector3 parentBonePos = jointsRigged[parentJoint].bone.position; jointsRigged[targetJoint].baseDistanceToParent = Vector3.Distance(parentBonePos, targetBonePos); //record the Transform of the model parent bone jointsRigged[targetJoint].parentBone = jointsRigged[parentJoint].bone; //extract the parent bone from the hierarchy to make it independent jointsRigged[targetJoint].parentBone.parent = transform.root; }
void SkeletonMapper_onDrop(Transform newJoint, JointType jointType) { if (!jointFieldMap.ContainsKey(jointType)) { return; } EditJoint(jointType, newJoint); if (newJoint != null) { EditorGUIUtility.PingObject(newJoint); } }
void Update() { UserData user = ControllerUser; if (user == null || user.Skeleton == null) { return; } if (!initialized) { Init(); } foreach (KeyValuePair <nuitrack.JointType, RectTransform> jointsInfo in joints) { nuitrack.JointType jointType = jointsInfo.Key; RectTransform rectTransform = jointsInfo.Value; UserData.SkeletonData.Joint j = user.Skeleton.GetJoint(jointType); if (j.Confidence > JointConfidence) { rectTransform.gameObject.SetActive(true); rectTransform.anchoredPosition = j.AnchoredPoint(parentRect.rect, rectTransform); } else { rectTransform.gameObject.SetActive(false); } if (jointType.GetParent() != nuitrack.JointType.None) { RectTransform endJoint = joints[jointType.GetParent()]; if (rectTransform.gameObject.activeSelf && endJoint.gameObject.activeSelf) { connections[jointType].gameObject.SetActive(true); connections[jointType].anchoredPosition = rectTransform.anchoredPosition; connections[jointType].transform.right = endJoint.position - rectTransform.position; float distance = Vector3.Distance(endJoint.anchoredPosition, rectTransform.anchoredPosition); connections[jointType].transform.localScale = new Vector3(distance, 1f, 1f); } else { connections[jointType].gameObject.SetActive(false); } } } }
void SkeletonMapper_onSelected(JointType jointType) { SelectJoint = jointType; if (!jointFieldMap.ContainsKey(jointType)) { return; } Transform selectTransform = GetTransformFromField(jointType); if (selectTransform != null) { EditorGUIUtility.PingObject(selectTransform); } }
public static List <JointType> GetChilds(this JointType jointType, bool recursive = false) { if (childJoints.ContainsKey(jointType)) { if (!recursive) { return(childJoints[jointType]); } else { List <JointType> childs = new List <JointType>(); FillChildRecursive(jointType, ref childs); return(childs); } } else { return(new List <JointType>()); } }
private void OnDisable() { SceneView.duringSceneGui -= OnSceneGUI; skeletonMapper.OnSelected -= SkeletonMapper_OnSelected; skeletonMapper = null; SelectedJoint = nuitrack.JointType.None; skeletonPoseView.OnBoneSetActive -= OnBoneActivated; skeletonPoseView.OnBoneDelete -= OnBoneDeactivated; skeletonPoseView.OnBoneRotate -= SkeletonPoseView_OnBoneRotate; skeletonPoseView.OnBoneToleranceChanged -= SkeletonPoseView_OnBoneToleranceChanged; skeletonPoseView.Dispose(); skeletonPoseView = null; StageUtility.GoToMainStage(); }
void SkeletonPoseView_OnBoneRotate(nuitrack.JointType jointType, Quaternion rotation) { Quaternion deltaRotation = rotation * Quaternion.Inverse(poseWrapper[jointType].Orientation); poseWrapper[jointType].Orientation = rotation; if (!Mathf.Approximately(Quaternion.Dot(deltaRotation, Quaternion.identity), 1)) { List <nuitrack.JointType> childs = jointType.GetChilds(true); List <nuitrack.JointType> jointsMask = NuitrackPoseWrapper.JointsMask; foreach (nuitrack.JointType childJoint in childs) { if (jointsMask.Contains(childJoint)) { poseWrapper[childJoint].Orientation = deltaRotation * poseWrapper[childJoint].Orientation; } } } }
void SkeletonBonesView_OnBoneSelected(SkeletonBonesView.ViewMode viewMode, JointType jointType, Transform boneTransform) { switch (viewMode) { case SkeletonBonesView.ViewMode.ModelBones: if (SelectJoint != JointType.None) { SkeletonMapper_onDrop(boneTransform, SelectJoint); SkeletonMapper_onSelected(JointType.None); } if (boneTransform != null) { EditorGUIUtility.PingObject(boneTransform); } break; case SkeletonBonesView.ViewMode.AssignedBones: SkeletonMapper_onSelected(jointType); break; } }
public SkeletonBonesView(Transform root, ViewMode viewMode = ViewMode.AssignedBones) { CurrentViewMode = viewMode; this.root = root; validBones = SkeletonUtils.GetValidBones(root); childsList = new Dictionary <nuitrack.JointType, List <nuitrack.JointType> >(); foreach (nuitrack.JointType jointType in Enum.GetValues(typeof(nuitrack.JointType))) { nuitrack.JointType parent = jointType.GetParent(); if (parent != nuitrack.JointType.None) { if (!childsList.ContainsKey(parent)) { childsList.Add(parent, new List <nuitrack.JointType>()); } childsList[parent].Add(jointType); } } // UI toolbar elements GUIContent modelBonesContent = EditorGUIUtility.IconContent("scenepicking_pickable-mixed_hover"); modelBonesContent.text = "Model bones"; GUIContent assignBonesContent = EditorGUIUtility.IconContent("AvatarSelector"); assignBonesContent.text = "Assigned bones"; GUIContent noneContent = EditorGUIUtility.IconContent("animationvisibilitytoggleoff"); skeletonModeGuiContent = new GUIContent[] { modelBonesContent, assignBonesContent, noneContent }; }
/// <summary> /// Returns the appropriate HumanBodyBones for nuitrack.JointType /// </summary> /// <param name="nuitrackJoint">nuitrack.JointType</param> /// <returns>HumanBodyBones</returns> public static HumanBodyBones ToUnityBones(this JointType nuitrackJoint) { return(nuitrackToUnity[nuitrackJoint]); }
/// <summary> /// Get a wrapper object for the specified joint. Maybe null. /// </summary> /// <param name="jointType">Joint type <see cref="nuitrack.JointType"/></param> /// <returns>Shell object <see cref="Joint"/></returns> public Joint GetJoint(nuitrack.JointType jointType) { nuitrack.Joint joint = RawSkeleton.GetJoint(jointType); return(new Joint(joint)); }
void Update() { UserData user = ControllerUser; if (user == null || user.Skeleton == null) { return; } if (headTransform != null) { #if UNITY_IOS headTransform.position = headDirectionTransform.rotation * neckHMDOffset + (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * GetJoint(JointType.Neck).Position) + basePivotOffset; #else headTransform.position = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * GetJoint(JointType.Head).Position) + basePivotOffset; #endif basePivot = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * GetJoint(JointType.Waist).Position) + basePivotOffset; } if (!skeletonRoot.activeSelf) { skeletonRoot.SetActive(true); } for (int i = 0; i < jointsInfo.Length; i++) { UserData.SkeletonData.Joint j = user.Skeleton.GetJoint(jointsInfo[i]); if (j.Confidence > JointConfidence) { if (!joints[jointsInfo[i]].activeSelf) { joints[jointsInfo[i]].SetActive(true); } joints[jointsInfo[i]].transform.position = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * j.Position) + basePivotOffset; joints[jointsInfo[i]].transform.rotation = (rotate180 ? q180 : q0) * CalibrationInfo.SensorOrientation * j.RotationMirrored; leftHandPos = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * GetJoint(JointType.LeftHand).Position) + basePivotOffset; rightHandPos = (rotate180 ? q180 : q0) * (Vector3.up * CalibrationInfo.FloorHeight + CalibrationInfo.SensorOrientation * GetJoint(JointType.RightHand).Position) + basePivotOffset; } else { if (joints[jointsInfo[i]].activeSelf) { joints[jointsInfo[i]].SetActive(false); } } } for (int i = 0; i < jointsInfo.Length; i++) { JointType jointType = jointsInfo[i]; JointType parentType = jointsInfo[i].GetParent(); if (parentType != JointType.None) { if (joints[jointType].activeSelf && joints[parentType].activeSelf) { if (!connections[i].activeSelf) { connections[i].SetActive(true); } Vector3 diff = joints[parentType].transform.position - joints[jointType].transform.position; connections[i].transform.position = joints[jointType].transform.position; connections[i].transform.rotation = Quaternion.LookRotation(diff); connections[i].transform.localScale = new Vector3(1f, 1f, diff.magnitude); } else { if (connections[i].activeSelf) { connections[i].SetActive(false); } } } } }
SerializedProperty GetJointProperty(JointType jointType) { return(serializedObject.FindProperty(jointFieldMap[jointType])); }