Exemple #1
0
 void ApplyChangesToCurve(HumanBoneController humanBoneController)
 {
     if (curveTimeSlider != null && minVertexDistanceSlider != null)
     {
         trailRenderer = humanBoneController.GetComponentInChildren <TrailRenderer>();
         trailRenderer.minVertexDistance = minVertexDistanceSlider.value;
         trailRenderer.time = curveTimeSlider.value;
     }
     else
     {
         Debug.LogError("Curve Time Slider and Min Vertex Distance Slider need to be set");
     }
 }
    void OnHumanBodiesChanged(ARHumanBodiesChangedEventArgs eventArgs)
    {
        HumanBoneController[] humanBoneController;  //declaring an array of `HumanBoneController` class objects

        humanBoneController = new HumanBoneController[dress.Length];

        //Added events is triggered when the User is detected inside the frame of sight
        foreach (var humanBody in eventArgs.added) // Iterating through The list of ARHumanBodys added since the last event
        {
            for (int i = 0; i < dress.Length; i++)
            {
                //Caching the Human Body trackables
                if (!skeletonTracker[i].TryGetValue(humanBody.trackableId, out humanBoneController[i]))//Adds a new key to the skeleton tracker
                //if there is a new trackable found
                {
                    Debug.Log($"Adding a new skeleton [{humanBody.trackableId}].");

                    //Creates a clone of the apparel
                    var newSkeletonGO = Instantiate(dress[i].apparel, humanBody.transform);

                    clone_temp_var[i].apparel = newSkeletonGO;

                    //Gets the HumanBoneController script
                    humanBoneController[i] = newSkeletonGO.GetComponent <HumanBoneController>();

                    // The offset is set to (0,0,0), this ensures that the Apparel gets superimposed onto the user
                    humanBoneController[i].transform.position = humanBoneController[i].transform.position +
                                                                new Vector3(skeletonOffsetX, skeletonOffsetY, skeletonOffsetZ);

                    //adds the newly tracked joint to the dictionary
                    skeletonTracker[i].Add(humanBody.trackableId, humanBoneController[i]);
                }

                humanBoneController[i].InitializeSkeletonJoints();             // initalizes the newly added skeleton joints

                humanBoneController[i].ApplyBodyPose(humanBody, Vector3.zero); //Positioning the apparel w.r.t to the user
            }
        }

        //Update event is triggered if the User moves or rotates
        foreach (var humanBody in eventArgs.updated)
        {
            for (int i = 0; i < dress.Length; i++)
            {
                if (skeletonTracker[i].TryGetValue(humanBody.trackableId, out humanBoneController[i])) //if the trackables are present in dictionary
                {                                                                                      //then it updates the positions of the apparel
                    humanBoneController[i].ApplyBodyPose(humanBody, Vector3.zero);                     //Positioning the apparel w.r.t to the user
                }
            }
        }
        //Removed events is triggered if the user leaves the frame of sight
        foreach (var humanBody in eventArgs.removed)
        {
            for (int i = 0; i < dress.Length; i++)
            {
                //Deallocating the dictionary and destroying all the apparels when the user leaves the frame
                if (skeletonTracker[i].TryGetValue(humanBody.trackableId, out humanBoneController[i]))
                {
                    Destroy(humanBoneController[i].gameObject);
                    skeletonTracker[i].Remove(humanBody.trackableId);
                }
            }
        }
    }