Esempio n. 1
0
 public void StartRecording()
 {
     current_users_ids = new List <string>();
     saving_folder     = metagen_comp.dataManager.saving_folder;
     foreach (var item in metagen_comp.userMetaData)
     {
         User         user     = item.Key;
         UserMetadata metadata = item.Value;
         if (!metadata.isRecording || (metagen_comp.LocalUser == user && !metagen_comp.record_local_user))
         {
             continue;
         }
         RefID user_id = user.ReferenceID;
         current_users_ids.Add(user_id.ToString());
         AvatarAudioOutputManager comp = user.Root.Slot.GetComponentInChildren <AvatarAudioOutputManager>();
         AudioOutput audio_output      = comp.AudioOutput.Target;
         audio_outputs[user_id] = audio_output;
         if (audio_outputs[user_id] == null)
         {
             UniLog.Log("OwO: Audio output for user " + user_id.ToString() + " is null!");
         }
         else
         {
             UniLog.Log("Sample rate");
             UniLog.Log(metagen_comp.Engine.AudioSystem.Connector.SampleRate.ToString());
             audio_recorders[user_id] = new AudioRecorder(saving_folder + "/" + user_id.ToString() + "_voice_tmp", metagen_comp.Engine.AudioSystem.BufferSize, 1, metagen_comp.Engine.AudioSystem.SampleRate, 1);
             audio_recorders[user_id].StartWriting();
         }
     }
     isRecording = true;
 }
Esempio n. 2
0
 public void StartInteracting()
 {
     foreach (var item in metagen_comp.userMetaData)
     {
         User         user     = item.Key;
         UserMetadata metadata = item.Value;
         if (!(metadata.isRecording || metagen_comp.record_everyone))
         {
             continue;
         }
         UniLog.Log("Starting voice interaction for user " + user.UserName);
         RefID user_id = user.ReferenceID;
         current_users_ids.Add(user_id.ToString());
         AvatarAudioOutputManager comp = user.Root.Slot.GetComponentInChildren <AvatarAudioOutputManager>();
         AudioOutput audio_output      = comp.AudioOutput.Target;
         audio_outputs[user_id] = audio_output;
         isRecording[user_id]   = false;
         if (audio_outputs[user_id] == null)
         {
             UniLog.Log("OwO: Audio output for user " + user_id.ToString() + " is null!");
         }
         else
         {
             UniLog.Log("Sample rate");
             UniLog.Log(metagen_comp.Engine.AudioSystem.Connector.SampleRate.ToString());
         }
     }
     isInteracting = true;
 }
Esempio n. 3
0
 public void StartRecordingAvatars(Dictionary <RefID, Slot> avatar_roots, string override_filename = null)
 {
     foreach (var item in avatar_roots)
     {
         RefID user_id  = item.Key;
         Slot  rootSlot = item.Value;
         VRIK  comp     = rootSlot.GetComponentInChildren <VRIK>();
         if (comp != null)
         {
             IKSolverVR solver = (IKSolverVR)comp.Solver;
             boness[user_id] = solver.BoneReferences;
             string filename = "";
             if (override_filename != null)
             {
                 filename = saving_folder + "/" + override_filename + "_mocap.bvh";
             }
             else
             {
                 filename = saving_folder + "/" + user_id.ToString() + "_mocap.bvh";
             }
             fileWriters[user_id] = new System.IO.StreamWriter(filename);
             filenames[user_id]   = filename;
             BvhHeaderWrite(fileWriters[user_id], boness[user_id]);
         }
     }
     isRecording = true;
 }
Esempio n. 4
0
        public void StartRecording()
        {
            World currentWorld = metagen_comp.World;

            current_users_ids = new List <string>();
            currentWorld.RunSynchronously(() =>
            {
                foreach (var item in metagen_comp.userMetaData)
                {
                    User user             = item.Key;
                    UserMetadata metadata = item.Value;
                    if (!metadata.isRecording || (metagen_comp.LocalUser == user && !metagen_comp.record_local_user))
                    {
                        continue;
                    }
                    RefID user_id = user.ReferenceID;
                    current_users_ids.Add(user_id.ToString());
                    Slot localSlot            = user.Root.HeadSlot.AddLocalSlot("vision recorder camera");
                    FrooxEngine.Camera camera = localSlot.AttachComponent <FrooxEngine.Camera>();
                    camera.GetRenderSettings(camera_resolution);
                    camera.NearClipping.Value = 0.15f;
                    cameras[user_id]          = camera;
                    int fps = 30;
                    visual_recorders[user_id] = new VideoRecorder(Path.Combine(saving_folder, user_id.ToString() + "_vision_tmp.avi"), camera_resolution.x, camera_resolution.y, fps, metagen_comp);
                }
                UniLog.Log("Made visual recorder");
                isRecording = true;
            });
        }
Esempio n. 5
0
        void StartWritingFile(RefID user_id)
        {
            Guid g = Guid.NewGuid();

            audio_recorders[user_id] = new AudioRecorder(saving_folder + "/" + user_id.ToString() + "_voice_tmp_" + g.ToString(), metagen_comp.Engine.AudioSystem.BufferSize, 1, metagen_comp.Engine.AudioSystem.SampleRate, 1);
            audio_recorders[user_id].StartWriting();
            isRecording[user_id] = true;
        }
 private void ReadHeadings()
 {
     foreach (var item in pose_readers)
     {
         RefID         refID  = item.Key;
         BinaryReaderX reader = item.Value;
         //send heading bytes to GRPC
         byte[] byteArray = reader.ReadBytes((int)reader.BaseStream.Length);
         Google.Protobuf.ByteString byteString = Google.Protobuf.ByteString.CopyFrom(byteArray, 0, byteArray.Length);
         client.SendHeadingBytes(new Heading {
             RefId = refID.ToString(), Data = byteString
         });
     }
 }
Esempio n. 7
0
        public void RegisterUserStream(RefID user_id, string name)
        {
            Tuple <BitBinaryWriterX, BitBinaryReaderX> streams = RegisterStream(user_id.ToString() + "_" + name);
            BitBinaryWriterX bitBinaryWriter = streams.Item1;
            BitBinaryReaderX bitBinaryReader = streams.Item2;

            if (bitBinaryWriter != null)
            {
                output_writers[user_id] = bitBinaryWriter;
            }
            if (bitBinaryReader != null)
            {
                output_readers[user_id] = bitBinaryReader;
            }
        }
 public void InteractPoseStreams(float deltaT)
 {
     if (channel.State != ChannelState.Ready)
     {
         return;
     }
     try
     {
         //UniLog.Log("InteractPoseStreams");
         foreach (var item in pose_writers)
         {
             RefID        refID  = item.Key;
             BinaryWriter writer = item.Value;
             //read heading bytes from GRPC
             //byte[] bs = null;
             ByteString bs1 = client.GetFrameBytes(new RefIDMessage {
                 RefId = refID.ToString()
             }).Data;
             //writer.Write(bs1.ToByteArray());
             //writer.BaseStream.Write(bs1.ToByteArray(),(int) writer.BaseStream.Position, bs1.Length);
             UniLog.Log(writer.BaseStream.Position);
             writer.Write(bs1.ToByteArray());
             UniLog.Log(writer.BaseStream.Position);
             UniLog.Log(bs1.Length);
             writer.BaseStream.Position -= bs1.Length;
             //writer.Write(frame_bs);
         }
         metagen_comp.streamPlayer.PlayStreams();
         metagen_comp.metaRecorder.streamRecorder.RecordStreams(deltaT);
         foreach (var item in pose_readers)
         {
             RefID         refID  = item.Key;
             BinaryReaderX reader = item.Value;
             //send heading bytes to GRPC
             byte[] byteArray = reader.ReadBytes((int)reader.BaseStream.Length);
             Google.Protobuf.ByteString byteString = Google.Protobuf.ByteString.CopyFrom(byteArray, 0, byteArray.Length);
             client.SendFrameBytes(new Frame {
                 RefId = refID.ToString(), Data = byteString
             });
         }
     }
     catch (Exception e)
     {
         UniLog.Log("OwO: " + e.Message);
     }
 }
 private void WriteHeadings()
 {
     foreach (var item in pose_writers)
     {
         RefID        refID  = item.Key;
         BinaryWriter writer = item.Value;
         //read heading bytes from GRPC
         ByteString bs1 = client.GetHeadingBytes(new RefIDMessage {
             RefId = refID.ToString()
         }).Data;
         UniLog.Log(bs1.Length);
         //byte[] bs = new byte[bs1.Length];
         //bs1.CopyTo(bs, 0);
         //writer.BaseStream.Write(bs1.ToByteArray(),(int) writer.BaseStream.Position, bs1.Length);
         writer.Write(bs1.ToByteArray());
         writer.BaseStream.Position -= bs1.Length;
     }
 }
Esempio n. 10
0
        private async void StartPlayingInternal()
        {
            try
            {
                if (generateAnimation)
                {
                    metagen_comp.World.RunSynchronously(() =>
                    {
                        animationRecorder = metagen_comp.Slot.AttachComponent <RecordingTool>();
                        animationRecorder.metagen_comp = metagen_comp;
                    });
                }
                //Dictionary<RefID, User>.ValueCollection users = metagen_comp.World.AllUsers;
                avatarManager = new metagen.AvatarManager();
                List <UserMetadata> userMetadatas = new List <UserMetadata>();
                userMetadatas.Add(new UserMetadata {
                    userId = "U-test", bodyNodes = "", devices = "", headDevice = "", isPublic = true, isRecording = true, platform = "", userRefId = "ID2B00"
                });
                Dictionary <RefID, AudioOutput> audio_outputs = new Dictionary <RefID, AudioOutput>();
                foreach (UserMetadata user in userMetadatas)
                {
                    if (!user.isRecording || !user.isPublic)
                    {
                        continue;                                      //at the moment we only allow playing back of public recording, for privacy reasons. In the future, we'll allow private access to the data
                    }
                    RefID user_id = RefID.Parse(user.userRefId);
                    UniLog.Log(user_id.ToString());
                    user_ids.Add(user_id);
                    channel = new Channel("127.0.0.1:" + (40052).ToString(), ChannelCredentials.Insecure);
                    client  = new DataComm.DataCommClient(channel);

                    output_readers[user_id]         = client.GetPose(new Empty()).ResponseStream;
                    fake_proxies[user_id]           = new List <Tuple <BodyNode, AvatarObjectSlot> >();
                    avatar_pose_nodes[user_id]      = new List <Tuple <BodyNode, IAvatarObject> >();
                    avatar_stream_channels[user_id] = new Dictionary <BodyNode, Tuple <bool, bool, bool> >();
                    proxy_slots[user_id]            = new Dictionary <BodyNode, Slot>();
                    if (avatarManager.avatar_template == null && avatar_template != null)
                    {
                        avatarManager.avatar_template = avatar_template;
                    }
                    Slot avatar = await avatarManager.GetAvatar();

                    UniLog.Log("AVATAR");
                    UniLog.Log(avatar.ToString());
                    avatars[user_id] = avatar;
                    List <IAvatarObject>    components = avatar.GetComponentsInChildren <IAvatarObject>();
                    List <AvatarObjectSlot> root_comps = avatar.GetComponentsInChildren <AvatarObjectSlot>();
                    boness[user_id] = avatar.GetComponentInChildren <Rig>()?.Bones.ToList();
                    VRIKAvatar avatarIK = avatar.GetComponentInChildren <VRIKAvatar>();

                    //READ absolute time
                    //output_readers[user_id].ReadSingle();
                    //READ number of body nodes
                    int numBodyNodes = 28; //TODO CHECK
                    for (int i = 0; i < numBodyNodes; i++)
                    {
                        //READ body node type
                        //int nodeInt =
                        //READ if scale stream exists
                        bool scale_exists = true;
                        //READ if position stream exists
                        bool pos_exists = true;
                        //READ if rotation stream exists
                        bool     rot_exists   = true;
                        BodyNode bodyNodeType = VNetcBodyNodeConverter[i];

                        bool node_found = false;
                        foreach (IAvatarObject comp in components)
                        {
                            foreach (AvatarObjectSlot comp2 in root_comps)
                            {
                                if (comp.Node == bodyNodeType && comp2.Node == bodyNodeType)
                                {
                                    UniLog.Log((comp.Node, scale_exists, pos_exists, rot_exists));
                                    if (bodyNodeType == BodyNode.Root)
                                    {
                                        proxy_slots[user_id][bodyNodeType] = avatar;
                                    }
                                    else
                                    {
                                        proxy_slots[user_id][bodyNodeType] = comp.Slot;
                                    }
                                    comp.Equip(comp2);
                                    if (bodyNodeType != BodyNode.Root)
                                    {
                                        SyncRef <Slot> sourceField = (SyncRef <Slot>)comp.GetType().GetField("_source", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(comp);
                                        sourceField.Target = null;
                                        FieldDrive <float3> posField = (FieldDrive <float3>)comp.GetType().GetField("_position", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(comp);
                                        posField.Target = null;
                                        FieldDrive <floatQ> rotField = (FieldDrive <floatQ>)comp.GetType().GetField("_rotation", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(comp);
                                        rotField.Target = null;
                                    }
                                    fake_proxies[user_id].Add(new Tuple <BodyNode, AvatarObjectSlot>(bodyNodeType, comp2));
                                    avatar_pose_nodes[user_id].Add(new Tuple <BodyNode, IAvatarObject>(comp.Node, comp));
                                    comp2.IsTracking.Value = true;
                                    if (bodyNodeType == BodyNode.LeftFoot || bodyNodeType == BodyNode.RightFoot)
                                    {
                                        avatarIK.ForceUseFeetProxies.Value = true;
                                    }
                                    if (bodyNodeType == BodyNode.LeftLowerLeg || bodyNodeType == BodyNode.RightLowerLeg)
                                    {
                                        avatarIK.ForceUseKneeProxies.Value = true;
                                    }
                                    if (bodyNodeType == BodyNode.LeftLowerArm || bodyNodeType == BodyNode.RightLowerArm)
                                    {
                                        avatarIK.ForceUseElbowProxies.Value = true;
                                    }
                                    if (bodyNodeType == BodyNode.Chest)
                                    {
                                        avatarIK.ForceUseChestProxy.Value = true;
                                    }
                                    if (bodyNodeType == BodyNode.Hips)
                                    {
                                        avatarIK.ForceUsePelvisProxy.Value = true;
                                    }
                                    node_found = true;
                                    break;
                                }
                                if (node_found)
                                {
                                    break;
                                }
                            }
                        }
                        //if (!node_found) throw new Exception("Node " + bodyNodeType.ToString() + " not found in avatar!");
                        if (!node_found)
                        {
                            fake_proxies[user_id].Add(new Tuple <BodyNode, AvatarObjectSlot>(bodyNodeType, null));
                            avatar_pose_nodes[user_id].Add(new Tuple <BodyNode, IAvatarObject>(bodyNodeType, null));
                        }
                        avatar_stream_channels[user_id][bodyNodeType] = new Tuple <bool, bool, bool>(scale_exists, pos_exists, rot_exists);
                    }
                    Slot avatarRootSlot = avatar.GetComponentInChildren <AvatarRoot>()?.Slot;
                    if (avatarRootSlot != null)
                    {
                        avatarRootSlot.LocalPosition = new float3(0, 0, 0);
                        avatarRootSlot.LocalRotation = new floatQ(0, 0, 0, 1);
                    }
                    //READ whether hands are being tracked
                    hands_are_tracked[user_id] = false;
                    //READ whether metacarpals are being tracked
                    //output_readers[user_id].ReadBoolean();

                    List <HandPoser> these_hand_posers = avatar.GetComponentsInChildren <HandPoser>(null, excludeDisabled: false, includeLocal: false);
                    UniLog.Log("getting finger rotation vars");
                    finger_slots[user_id]         = new Dictionary <BodyNode, Slot>();
                    hand_posers[user_id]          = new Dictionary <Chirality, HandPoser>();
                    finger_compensations[user_id] = new Dictionary <BodyNode, floatQ>();
                    foreach (HandPoser hand_poser in these_hand_posers)
                    {
                        UniLog.Log("HI");
                        hand_posers[user_id][hand_poser.Side] = hand_poser;
                        BodyNode side1 = BodyNode.LeftThumb_Metacarpal.GetSide((Chirality)hand_poser.Side);
                        BodyNode side2 = BodyNode.LeftPinky_Tip.GetSide((Chirality)hand_poser.Side);
                        for (BodyNode nodee = side1; nodee <= side2; ++nodee)
                        {
                            int                     index             = nodee - side1;
                            FingerType              fingerType        = nodee.GetFingerType();
                            FingerSegmentType       fingerSegmentType = nodee.GetFingerSegmentType();
                            HandPoser.FingerSegment fingerSegment     = hand_poser[fingerType][fingerSegmentType];
                            if (fingerSegment != null && fingerSegment.Root.Target != null)//&& fingerSegment.RotationDrive.IsLinkValid)
                            {
                                UniLog.Log(nodee.ToString());
                                finger_slots[user_id][nodee]         = fingerSegment.Root.Target;
                                proxy_slots[user_id][nodee]          = fingerSegment.Root.Target;
                                finger_compensations[user_id][nodee] = fingerSegment.CoordinateCompensation.Value;
                                fingerSegment.RotationDrive.Target   = (IField <floatQ>)null;
                            }
                        }
                    }
                    UniLog.Log("got finger rotation vars");
                    //AUDIO PLAY
                    audio_outputs[user_id] = null;
                    //UniLog.Log("Setting up audio!");
                    //avatar.GetComponentInChildren<AudioOutput>().Source.Target = null;
                    //for (int i = 0; i < 2; i++)
                    //{
                    //    string audio_file;
                    //    if (i==0)
                    //    {
                    //        if (!play_hearing) continue;
                    //        string[] files = Directory.GetFiles(reading_directory, user_id.ToString() + "*_hearing.ogg");
                    //        audio_file = files.Length > 0 ? files[0] : null;
                    //    } else
                    //    {
                    //        if (!play_voice) continue;
                    //        string[] files = Directory.GetFiles(reading_directory, user_id.ToString() + "*_voice.ogg");
                    //        audio_file = files.Length > 0 ? files[0] : null;
                    //    }
                    //    if (File.Exists(audio_file))
                    //    {
                    //        AudioOutput audio_output = avatar.GetComponentInChildren<AudioOutput>();
                    //        if (audio_output.Source.Target != null) audio_output = audio_output.Slot.AttachComponent<AudioOutput>();
                    //        VisemeAnalyzer visemeAnalyzer = avatar.GetComponentInChildren<VisemeAnalyzer>();
                    //        audio_output.Volume.Value = 1f;
                    //        audio_output.Enabled = true;
                    //        //audio_outputs[user_id] = audio_output;
                    //        //AudioX audioData = new AudioX(reading_directory + "/" + user_id.ToString() + "_audio.wav");
                    //        //AssetRef<AudioClip> audioClip = new AssetRef<AudioClip>();
                    //        Uri uri = this.World.Engine.LocalDB.ImportLocalAsset(audio_file, LocalDB.ImportLocation.Original, (string)null);
                    //        //ToWorld thing = new ToWorld();
                    //        //var awaiter = thing.GetAwaiter();
                    //        //awaiter.GetResult();
                    //        StaticAudioClip audioClip = audio_output.Slot.AttachAudioClip(uri);
                    //        AudioClipPlayer player = audio_output.Slot.AttachComponent<AudioClipPlayer>();
                    //        if (visemeAnalyzer != null)
                    //        {
                    //            visemeAnalyzer.Source.Target = player;
                    //        }
                    //        UniLog.Log("attaching clip to player");
                    //        player.Clip.Target = (IAssetProvider<AudioClip>) audioClip;
                    //        UniLog.Log("attaching player to audio output");
                    //        audio_output.Source.Target = (IAudioSource) player;
                    //        audio_output.Slot.AttachComponent<AudioMetadata>(true, (Action<AudioMetadata>)null).SetFromCurrentWorld();
                    //        player.Play();
                    //    }
                    //}
                }
                avatars_finished_loading = true;
                isPlaying = true;
                if (generateAnimation)
                {
                    animationRecorder.StartRecordingAvatars(avatars, audio_outputs);
                }
                if (generateBvh)
                {
                    bvhRecorder.StartRecordingAvatars(avatars);
                }
            }
            catch (Exception e)
            {
                UniLog.Log("TwT: " + e.Message);
                UniLog.Log(e.StackTrace);
            }
        }