void CreateOrUpdateHead(ARHumanBody arBody) { if (m_HeadPrefab == null) { Debug.Log("no prefab found"); return; } Transform rootTransform = arBody.transform; if (rootTransform == null) { Debug.Log("no root transform found for ARHumanBody"); return; } Transform headTransform; if (rootTransform.childCount <= 1) { GameObject go = Instantiate(m_HeadPrefab, rootTransform); headTransform = go.transform; } else { headTransform = rootTransform.GetChild(1); } XRHumanBodyJoint joint = arBody.joints[(int)JointIndices.head_joint]; headTransform.localScale = joint.anchorScale; headTransform.localRotation = joint.anchorPose.rotation; headTransform.localPosition = joint.anchorPose.position; }
public void ApplyBodyPose(ARHumanBody body) { var joints = body.joints; if (!joints.IsCreated) { return; } string txt = ""; for (int i = 0; i < k_NumSkeletonJoints; ++i) { XRHumanBodyJoint joint = joints[i]; var bone = m_BoneMapping[i]; if (bone != null) { bone.transform.localPosition = joint.localPose.position; bone.transform.localRotation = joint.localPose.rotation; var str1 = joint.localPose.position.x + "," + joint.localPose.position.y + "," + joint.localPose.position.z; var str2 = bone.transform.localEulerAngles.x + "," + bone.transform.localEulerAngles.y + "," + bone.transform.localEulerAngles.z; txt += str1 + "\n"; txt += str2 + "\n"; //string[] xyz = str1.Split(','); //bone.transform.localPosition = new Vector3(float.Parse(xyz[0]), float.Parse(xyz[1]), float.Parse(xyz[2])); //xyz = str2.Split(','); //bone.transform.localEulerAngles = new Vector3(float.Parse(xyz[0]), float.Parse(xyz[1]), float.Parse(xyz[2])); } else { txt += "null\n"; } } txt += "end\n"; if (logic == null) { logic = GameObject.FindGameObjectWithTag("MainLogic").GetComponent <MainLogic>(); if (logic == null) { logic = GetComponent <MainLogic>(); } Debug.Log("try to get logic"); return; } logic.SendText(txt); }
//Updates the positions of the Apparel when the user moves public void ApplyBodyPose(ARHumanBody body, Vector3 offset) { var joints = body.joints; if (!joints.IsCreated) //when the user leaves the frame { return; //it returns as there is no user to augment the apparel } for (int i = 0; i < k_NumSkeletonJoints; ++i) //traversing through all the joints of apparel { XRHumanBodyJoint joint = joints[i]; var bone = m_BoneMapping[i]; if (bone != null) { bone.transform.localPosition = joint.localPose.position + offset; //updates the position and rotation bone.transform.localRotation = joint.localPose.rotation; //of the apparel } } }
public void ApplyBodyPose(ARHumanBody body) { var joints = body.joints; if (!joints.IsCreated) { return; } for (int i = 0; i < k_NumSkeletonJoints; ++i) { XRHumanBodyJoint joint = joints[i]; var bone = m_BoneMapping[i]; if (bone != null) { bone.transform.localPosition = joint.localPose.position; bone.transform.localRotation = joint.localPose.rotation; } } }
private void UpdateJointTransform(Transform jointT, XRHumanBodyJoint bodyJoint) { jointT.localPosition = bodyJoint.anchorPose.position; jointT.localRotation = bodyJoint.anchorPose.rotation; jointT.localScale = bodyJoint.anchorScale * jointScaleModifier; }