Ejemplo n.º 1
0
    public override void OnCloudAnchorLocated(AnchorLocatedEventArgs args)
    {
        CloudSpatialAnchor cloudAnchor = args.Anchor;

        // callback is sometimes called multiple times for the same anchor, so we ensure only one object is instantiated per anchor ID
        if (!instantiatedAnchorIds.Contains(args.Identifier))
        {
            // load recording
            string        recordingId     = anchorStore.GetRecordingId(args.Identifier);
            HoloRecording loadedRecording = LoadHoloRecording(recordingId);

            // Instantiate anchored object - will be the parent object of hands recording and representation
            GameObject  anchoredObject = new GameObject();
            WorldAnchor wa             = anchoredObject.AddComponent <WorldAnchor>();
            wa.SetNativeSpatialAnchorPtr(cloudAnchor.LocalAnchor);

            // instantiate representation and pass the recording to it
            Vector3 newRepLocation = new Vector3(loadedRecording.positionXRep, loadedRecording.positionYRep, loadedRecording.positionZRep);
            InstantiateRecordingRepresentation(ref anchoredObject, atLocation: newRepLocation, atPalm: false);

            HoloPlayerBehaviour playerComponent = recordingRepresentationInstance.GetComponent <HoloPlayerBehaviour>();
            playerComponent.PutHoloRecordingIntoPlayer(recordingId, loadedRecording, anchoredObject, anchorStore, openKeyboard: false);

            // Mark already instantiated Anchor Ids so that nothing is instantiated more than once.
            instantiatedAnchorIds.Add(args.Identifier);
        }
    }
    // called by the recorder when he is done recording
    public void PutHoloRecordingIntoPlayer(string id, HoloRecording recording, GameObject anchoredObject, AnchorStore store, bool openKeyboard = true)
    {
        recordingId   = id;
        holoRecording = recording;
        anchorStore   = store;
        anchor        = anchoredObject;

        // update UI
        StartCoroutine(AddScreenshotToRepresentation(recording.pathToScreenshot)); // set the screenshot of the representation, done asynchronously because it loads from disk
        if (openKeyboard)
        {
            OpenSystemKeyboard();              // open keyboard to give the representation a title.
            instructionObject.SetActive(true); // the instructionobject tells the user that he has to type the title of the recording
            buttons.SetActive(false);
        }
        else
        {
            // If recording is loaded from anchors, open keyboard not needed
            buttons.SetActive(true);
            instructionObject.SetActive(false);
            titleOfRepresentation.text = recording.titleOfClip;
        }
        timerText.text = recording.lengthOfClip.ToString() + "s";
        InstantiateHandAndSetInactive(leftHand, ref instantiatedLeftHand, ref anchoredObject); // the hands should only become visible when the animation is running
        InstantiateHandAndSetInactive(rightHand, ref instantiatedRightHand, ref anchoredObject);

        // add animationclip to hand prefabs and audio clip of recording to the audiosource of the representation
        (AnimationClip leftHandClip, AnimationClip rightHandClip) = GetAnimationClipsFromAllKeyFrames(recording.allKeyFrames);
        Debug.Log("AnimationClips were loaded");
        instantiatedLeftHand.GetComponent <Animation>().AddClip(leftHandClip, "leftHand");
        instantiatedRightHand.GetComponent <Animation>().AddClip(rightHandClip, "rightHand");
    }
Ejemplo n.º 3
0
    public void StopRecordingAndPutRecordingIntoRepresentation()
    {
        // update UI
        whileRecordingMenu.SetActive(false);
        preRecordingMenu.SetActive(true);

        // Instantiate anchored object - will be the parent object of hands recording and representation
        GameObject anchoredObject = InstantiateAnchoredObject();

        // instantiate representation and pass the recording to it
        InstantiateRecordingRepresentation(ref anchoredObject, atLocation: Vector3.zero, atPalm: true);

        // get final length of recording in seconds
        int recordingLength = timerInstance.GetComponent <TimerBehaviour>().GetCurrentRecordingTime();

        // stop recording and get the recording object
        HoloRecording newRecording = StopRecording(recordingLength, recordingRepresentationInstance.transform.localPosition);

        audioRecorder.StopAndSaveRecording(numberOfRecording.ToString());

        HoloPlayerBehaviour playerComponent = recordingRepresentationInstance.GetComponent <HoloPlayerBehaviour>();

        playerComponent.PutHoloRecordingIntoPlayer(numberOfRecording.ToString(), newRecording, anchoredObject, anchorStore);

        // Save anchor to cloud
        //SaveObjectAnchorToCloud(anchoredObject, numberOfRecording.ToString());
    }
Ejemplo n.º 4
0
    public void StopRecordingAndPutRecordingIntoRepresentation()
    {
        Debug.Log("StopRecordingAndPutRecordingIntoRepresentation");
        HoloRecording       newRecording    = holoRecorderBehaviour.StopRecording();
        HoloPlayerBehaviour playerComponent = recordingRepresentationInstance.GetComponent <HoloPlayerBehaviour>();

        playerComponent.PutHoloRecordingIntoPlayer(newRecording);
    }
Ejemplo n.º 5
0
    private HoloRecording StopRecording(int recordingLength, Vector3 posRep)
    {
        isRecording = false;
        Microphone.End(null);
        HoloRecording newRecording = SaveRecording(recordingLength, posRep);

        ResetRecorder();
        return(newRecording);
    }
Ejemplo n.º 6
0
    public HoloRecording StopRecording()
    {
        Debug.Log("StopRecording");
        isRecording = false;
        HoloRecording newRecording = SaveRecording();

        ResetRecorder();
        return(newRecording);
    }
 public void PutHoloRecordingIntoPlayer(HoloRecording holoRecording)
 {
     Debug.Log("PutHoloRecordingIntoPlayer");
     InstantiateRecordedObjectAndSetInactive();
     // There needs to be an AnimatorOverrideController for every animation clip to be played on the object with the Animator
     animatorOverrideController                   = CreateAndSaveAnimatorOverrideController(name: "AnimatorOverrideControllerFor" + holoRecording.animationClipName);
     animatorOverrideController["Recorded"]       = holoRecording.animationClip;
     animatorOfInstance.runtimeAnimatorController = animatorOverrideController;
     lengthOfAnimationInSeconds                   = holoRecording.animationClip.length;
 }
Ejemplo n.º 8
0
    private HoloRecording SaveRecording(int recordingLength, Vector3 posRep)
    {
        Debug.Log($"SaveRecording called");
        string animationClipName   = "AnimationClip" + numberOfRecording;
        string pathToAnimationClip = Application.persistentDataPath + $"/{animationClipName}.animationClip";
        // saving is uncommented to unclutter the hololens
        //SaveKeyframesAsynchronously(pathToAnimationClip);
        HoloRecording newRecording = new HoloRecording(pathToAnimationClip, animationClipName, allKeyFrames, pathToScreenshot, recordingLength, "", posRep, timesAndBoolsLeftHand, timesAndBoolsRightHand);

        return(newRecording);
    }
Ejemplo n.º 9
0
    private HoloRecording SaveRecording()
    {
        string animationClipName   = "AnimationClip" + GetRandomNumberBetween1and100000();
        string pathToAnimationClip = $"Assets/Animation/AnimationClips/{animationClipName}.anim";

        AssetDatabase.CreateAsset(currentlyRecordedAnimationClip, pathToAnimationClip);
        AssetDatabase.SaveAssets();
        gameObjectRecorder.SaveToClip(currentlyRecordedAnimationClip);
        HoloRecording newRecording = new HoloRecording(currentlyRecordedAnimationClip, pathToAnimationClip, animationClipName);

        return(newRecording);
    }
    // Serialize and save HoloRecording into persistent path
    public void StoreHoloRecording(string filePath, string recordingId, HoloRecording recording)
    {
        FileStream      fs = File.Open(filePath, FileMode.OpenOrCreate);
        BinaryFormatter bf = new BinaryFormatter();

        try
        {
            bf.Serialize(fs, recording);
            fs.Close();
        }
        catch (SerializationException e)
        {
            throw;
        }
        finally
        {
            fs.Close();
        }
    }
Ejemplo n.º 11
0
    public HoloRecording LoadHoloRecording(string recordingId)
    {
        string          filePath      = Application.persistentDataPath + "/" + "holorecording_" + recordingId + ".bin";
        FileStream      fs            = File.Open(filePath, FileMode.Open);
        BinaryFormatter bf            = new BinaryFormatter();
        HoloRecording   holoRecording = new HoloRecording();

        try
        {
            holoRecording = (HoloRecording)bf.Deserialize(fs);
        }
        catch (SerializationException e)
        {
            Debug.Log(" Failed to deserialize. Reason: " + e.Message);
            throw;
        }
        finally
        {
            fs.Close();
            Debug.Log("close filestream successfully \n");
        }
        return(holoRecording);
    }