protected void Setup() { UniLog.Log("Setup"); //This records the audio from an audiolistener. Unfortunately we can only have one audiolistener in an Unity scene:/ //It starts/stops recording upon pressing the key R. //TODO: make below work in VR mode too //TODO: sync between audios and videos is not right!! //UniLog.Log("Adding Audio Listener"); //GameObject gameObject = GameObject.Find("AudioListener"); //if (!(LocalUser.HeadDevice == HeadOutputDevice.Screen)) //must be on VR mode //{ // UniLog.Log("VR mode!"); // //gameObject = GameObject.Find("Camera (ears)"); // default_record_local_user = true; // is_in_VR_mode = true; //} //hearingRecorder = gameObject.AddComponent<UnityNeos.AudioRecorderNeos>(); UniLog.Log("FrooxEngine.Engine.Current.WorldManager.FocusedWorld"); UniLog.Log(FrooxEngine.Engine.Current.WorldManager.FocusedWorld); World currentWorld = FrooxEngine.Engine.Current.WorldManager.FocusedWorld; current_session_id = currentWorld.SessionId; FrooxEngine.Engine.Current.WorldManager.WorldRemoved += RemoveWorld; FrooxEngine.Engine.Current.WorldManager.WorldFocused += FocusedWorld; if (!is_in_VR_mode) { FrooxEngine.Engine.Current.Cloud.Messages.OnMessageReceived += ProcessMessage; } FrooxEngine.Engine.Current.Cloud.Friends.FriendAdded += ProcessFriendRequest; FrooxEngine.Engine.Current.Cloud.Friends.FriendRequestCountChanged += ProcessFriendRequest2; FrooxEngine.Engine.Current.Cloud.Friends.FriendRemoved += ProcessFriendRemoved; dataBase = new DataBase(); has_run_setup = true; }
public async Task<Slot> SpawnAvatar(String neosdb) { World currentWorld = FrooxEngine.Engine.Current.WorldManager.FocusedWorld; //Job<Slot> task = new Job<Slot>(); TaskCompletionSource<Slot> task = new TaskCompletionSource<Slot>(); currentWorld.RunSynchronously(async () => { Engine engine = FrooxEngine.Engine.Current; Uri uri = new Uri(neosdb); //await slot.LoadObjectAsync(uri, (Slot)null, (ReferenceTranslator)null); //ValueTaskAwaiter<string> gatherAwaiter = engine.AssetManager.RequestGather(uri, Priority.Urgent).GetAwaiter(); string nodeString = await engine.AssetManager.RequestGather(uri, Priority.Urgent); //string nodeString = gatherAwaiter.GetResult(); DataTreeDictionary node = DataTreeConverter.Load(nodeString, uri); UniLog.Log("slot"); UniLog.Log(holder_slot.ToString()); holder_slot.LoadObject(node); Slot slot = holder_slot.GetComponent<InventoryItem>((Predicate<InventoryItem>)null, false)?.Unpack((List<Slot>)null) ?? holder_slot; Slot fake_root = PrepareAvatar(slot); task.SetResult(fake_root); //avatars.Add(slot); //avatars[avatars.Count - 1].AttachComponent<AvatarPuppeteer>(); }); return await task.Task.ConfigureAwait(false); }
void InitPool() { UniLog.CCAssert(m_availabilityElements.Count == 0, "Can not initialized pool, because this pool is not empty"); UniLog.CCAssert(m_prefab != null, "Found error when initialize pool, case by prefab is null"); if (m_availabilityElements == null) { m_availabilityElements = new List <UniPooledObject>(); } for (int i = 0; i < m_minCapacity; i++) { var obj = Instantiate(m_prefab, transform); obj.SetActive(false); UniPooledObject t = null; if (t = obj.GetComponent <UniPooledObject>()) { t.Pool = this; m_availabilityElements.Add(t); } } }
private void ResetHearingUser() { World world = FrooxEngine.Engine.Current.WorldManager.FocusedWorld; UniLog.Log("Reset hearing user for world " + world.CorrespondingWorldId); Dictionary <RefID, User> .ValueCollection users = world.AllUsers; recording_hearing_user = world.LocalUser; if (!is_in_VR_mode || !default_record_local_user) { foreach (User user in users) { if (user.UserID != null) { MetaGenUser user_data = dataBase.GetUserData(user.UserID); if (user != world.LocalUser && user_data.default_public && user_data.default_recording) { recording_hearing_user = user; break; } } } } SetHearingUser(recording_hearing_user); }
protected override void OnAttach() { base.OnAttach(); if (this.LocalUser.UserID == "U-guillefix") { UniLog.Log("Getting users list"); Dictionary <RefID, User> .ValueCollection users = FrooxEngine.Engine.Current.WorldManager.FocusedWorld.AllUsers; //List<string> left_leg_joint_names = ["Left_upper _leg", "Left_lower_leg", "Left_foot", "Left_foot_end"]; //List<string> right_leg_joint_names = ["Right_upper_leg", "Right_lower_leg", "Right_foot", "Right_foot_end"]; //List<string> spine_joint_names = ["Spine", "chest", "Neck"]; //List<string> left_arm_joint_names = ["Left_shoulder", "Left_upper_arm", "Left_lower_arm", "Left_Hand"]; //List<string> right_arm_joint_names = ["Right_shoulder", "Right_upper_arm", "Right_lower_arm", "Right_Hand"]; //List<string> all_joints = ["Hips"]; UniLog.Log("Creating list of joints"); List <string> left_leg_joint_names = new List <string> { "LeftUpLeg", "LeftLeg", "LeftFoot", "LeftToeBase" }; List <string> right_leg_joint_names = new List <string> { "RightUpLeg", "RightLeg", "RightFoot", "RightToeBase" }; List <string> spine_joint_names = new List <string> { "Spine", "Spine1", "Spine2", "Neck" }; List <string> left_arm_joint_names = new List <string> { "LeftShoulder", "LeftArm", "LeftForeArm", "LeftHand" }; List <string> right_arm_joint_names = new List <string> { "RightShoulder", "RightArm", "RightForeArm", "RightHand" }; List <string> all_joints = new List <string> { "Hips" }; all_joints.AddRange(right_leg_joint_names); all_joints.AddRange(left_leg_joint_names); all_joints.AddRange(spine_joint_names); all_joints.AddRange(right_arm_joint_names); all_joints.AddRange(left_arm_joint_names); all_joints = all_joints.Select(x => "mixamorig:" + x).ToList(); //UniLog.Log("Adding Audio Listener"); //GameObject gameObject = GameObject.Find("AudioListener"); //UnityNeos.AudioRecorderNeos recorder = gameObject.AddComponent<UnityNeos.AudioRecorderNeos>(); //GameObject gameObject2 = new GameObject("HIII"); //gameObject2.AddComponent<AudioListener>(); //gameObject2.AddComponent<UnityNeos.AudioRecorderNeos>(); //recorder.StartWriting("test.wav"); UniLog.Log("Getting user joint slots"); foreach (User user in users) { List <Slot> temp_list = new List <Slot>(); bool has_compatible_avatar = true; Slot root_slot = user.Root.Slot; for (int i = 0; i < all_joints.Count; i++) { Slot joint_slot = root_slot.FindChild(s => s.Name == all_joints[i]); if (joint_slot == null) { has_compatible_avatar = false; break; } else { temp_list.Add(joint_slot); } } if (has_compatible_avatar) { joint_slots[user] = temp_list.ToList(); } } UniLog.Log("Creating output file"); output_file = new System.IO.StreamWriter("test.txt"); //FileStream fs = new FileStream("savingFile.dat", FileMode.Create, FileAccess.ReadWrite); //writer = new BinaryWriter(fs); } }
static void WalkDirectoryTree(System.IO.DirectoryInfo root, string media_type) { try { System.IO.FileInfo[] files = null; System.IO.DirectoryInfo[] subDirs = null; // First, process all the files directly under this folder try { //files = root.GetFiles("*_vision.avi"); if (media_type == "video") { files = root.GetFiles("*_vision.avi"); } else if (media_type == "audio") { FileInfo[] files_audio = root.GetFiles("*_voice.wav"); FileInfo[] files_hearing = root.GetFiles("*_hearing.wav"); files = new FileInfo[files_audio.Length + files_hearing.Length]; files_audio.CopyTo(files, 0); files_hearing.CopyTo(files, files_audio.Length); } else { UniLog.Log("OwO: Type of media conversion not supported in the Media Converter"); } } // This is thrown if even one of the files requires permissions greater // than the application provides. catch (UnauthorizedAccessException e) { // This code just writes out the message and continues to recurse. // You may decide to do something different here. For example, you // can try to elevate your privileges and access the file again. log.Add(e.Message); } catch (System.IO.DirectoryNotFoundException e) { UniLog.Log(e.Message); } if (files != null) { foreach (System.IO.FileInfo fi in files) { string ffmpgCmdText = ""; UniLog.Log("converting " + fi.FullName); if (media_type == "video") { string new_name = fi.FullName.Substring(0, fi.FullName.Length - 3) + "mp4"; ffmpgCmdText = "-hide_banner -loglevel warning -y -i \"" + fi.FullName + "\" \"" + new_name + "\""; } else if (media_type == "audio") { string new_name = fi.FullName.Substring(0, fi.FullName.Length - 3) + "ogg"; ffmpgCmdText = "-hide_banner -loglevel warning -y -i \"" + fi.FullName + "\" \"" + new_name + "\""; } else { UniLog.Log("OwO: Type of media conversion not supported in the Media Converter"); break; } Process ffmpegProcess = new System.Diagnostics.Process(); //processes.Add(ffmpegProcess); ProcessStartInfo processInfo = new ProcessStartInfo(); #if NOHL processInfo.FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "ffmpeg" : "ffmpeg.exe"; #else //processInfo.FileName = "ffmpeg.exe"; processInfo.FileName = "ffmpeg"; #endif processInfo.Arguments = ffmpgCmdText; ffmpegProcess.StartInfo = processInfo; ffmpegProcess.EnableRaisingEvents = true; ffmpegProcess.Exited += (object sender, EventArgs target) => DeleteFile((string)fi.FullName.Clone()); ffmpegProcess.Start(); ffmpegProcess.WaitForExit(); //ffmpegProcess.ErrorDataReceived += (object sender, DataReceivedEventArgs target) => DeleteFile((string) fi.FullName.Clone()); //ffmpegProcess.Disposed += (object sender, EventArgs target) => { DeleteFile(fi.FullName); }; } // Now find all the subdirectories under this directory. subDirs = root.GetDirectories(); foreach (System.IO.DirectoryInfo dirInfo in subDirs) { // Resursive call for each subdirectory. WalkDirectoryTree(dirInfo, media_type); } } } catch (Exception e) { UniLog.Log("OwO: " + e.Message); UniLog.Log(e.StackTrace); } }
public void StopRecording() { bool wait_streams = false; bool wait_controller_streams = false; bool wait_eye_streams = false; bool wait_mouth_streams = false; bool wait_voices = false; bool wait_hearing = false; bool wait_vision = false; bool wait_anim = false; //STREAMS if (streamRecorder.isRecording) { streamRecorder.StopRecording(); wait_streams = true; } //CONTROLLER STREAMS if (controllerRecorder.isRecording) { controllerRecorder.StopRecording(); wait_controller_streams = true; } //EYE STREAMS if (eyeRecorder.isRecording) { eyeRecorder.StopRecording(); wait_eye_streams = true; } //MOUTH STREAMS if (mouthRecorder.isRecording) { mouthRecorder.StopRecording(); wait_mouth_streams = true; } //VOICES if (voiceRecorder.isRecording) { voiceRecorder.StopRecording(); wait_voices = true; } //HEARING if (metagen_comp.hearingRecorder != null && metagen_comp.hearingRecorder.isRecording) { metagen_comp.hearingRecorder.StopRecording(); wait_hearing = true; } //VISION if (visionRecorder.isRecording) { visionRecorder.StopRecording(); wait_vision = true; } //BVH if (bvhRecorder.isRecording) { bvhRecorder.StopRecording(); } try { if (animationRecorder.isRecording) { animationRecorder.PreStopRecording(); wait_anim = true; } } catch (Exception e) { UniLog.Log(">w< animation stopping failed"); } Task task = Task.Run(() => { try { //STREAMS if (wait_streams) { streamRecorder.WaitForFinish(); wait_streams = false; } //CONTROLLER STREAMS if (wait_controller_streams) { controllerRecorder.WaitForFinish(); wait_controller_streams = false; } //EYE STREAMS if (wait_eye_streams) { eyeRecorder.WaitForFinish(); wait_eye_streams = false; } //MOUTH STREAMS if (wait_mouth_streams) { mouthRecorder.WaitForFinish(); wait_mouth_streams = false; } //VOICES if (wait_voices) { UniLog.Log("Waiting voices"); voiceRecorder.WaitForFinish(); wait_voices = false; UniLog.Log("Waited voices"); } //HEARING if (wait_hearing) { metagen_comp.hearingRecorder.WaitForFinish(); wait_hearing = false; } //VISION if (wait_vision) { visionRecorder.WaitForFinish(); wait_vision = false; } metagen.Util.MediaConverter.WaitForFinish(); //ANIMATION if (wait_anim) { animationRecorder.StopRecording(); animationRecorder.WaitForFinish(); metagen_comp.World.RunSynchronously(() => { metagen_comp.Slot.RemoveComponent(animationRecorder); }); wait_anim = false; } } catch (Exception e) { UniLog.Log("OwO error in waiting task when stopped recording: " + e.Message); UniLog.Log(e.StackTrace); } finally { UniLog.Log("FINISHED STOPPING RECORDING"); metagen_comp.recording_state = OutputState.Stopped; metagen_comp.dataManager.StopSection(); } }); //task.ContinueWith((Task t) => //{ // UniLog.Log("FINISHED STOPPING RECORDING"); // this.recording_state = OutputState.Stopped; // dataManager.StopSection(); //}); isRecording = false; }
public void FileWriterLoop() { try { writer = new AviWriter(fileName) { FramesPerSecond = frameRate, // Emitting AVI v1 index in addition to OpenDML index (AVI v2) // improves compatibility with some software, including // standard Windows programs like Media Player and File Explorer EmitIndex1 = true }; var stream = writer.AddVideoStream(); //var codecs = Mpeg4VideoEncoderVcm.GetAvailableCodecs(); //UniLog.Log(codecs.ToString()); //FourCC selectedCodec = KnownFourCCs.Codecs.MotionJpeg; //var encoder = new Mpeg4VideoEncoderVcm(width, height, // frameRate, // frame rate // 0, // number of frames, if known beforehand, or zero // 70 // quality, though usually ignored :( // ); //var encoder = new SingleThreadedVideoEncoderWrapper(() => new Mpeg4VideoEncoderVcm(width, height, // frameRate, // frame rate // 0, // number of frames, if known beforehand, or zero // 70, // quality, though usually ignored :( // selectedCodec // codecs preference // )); //var stream = writer.AddEncodingVideoStream(encoder, width: width, height: height); //var stream = writer.AddMpeg4VideoStream(width, height, frameRate, 0, 70, selectedCodec, false); //var stream = writer.AddMotionJpegVideoStream(width, height, 70); stream.Height = height; stream.Width = width; stream.Codec = KnownFourCCs.Codecs.Uncompressed; stream.BitsPerPixel = BitsPerPixel.Bpp32; byte[] frame; while (true) { //UniLog.Log("writerloop"); if (should_finish) { writer.Close(); break; } if (framesQueue.TryDequeue(out frame)) { //UniLog.Log("Writing"); //Bitmap bmp = ToBitmap(frame); //Bitmap bmpReduced = ReduceBitmap(bmp, width, height); //System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width,height,System.Drawing.Imaging.PixelFormat.Format32bppArgb); //var bits = bitmap.LockBits(new Rectangle(0, 0, width,height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //Marshal.Copy(frame, 0, bits.Scan0, frame.Length); //bitmap.UnlockBits(bits); //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); //using (var gr = Graphics.FromImage(bmp)) // gr.DrawImage(bitmap, new Rectangle(0, 0, width, height)); //var buffer = new byte[width * height * 4];//(widght - _ - height - _ - 4); //var bits2 = bmp.LockBits(new Rectangle(0, 0, stream.Width, stream.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb); //Marshal.Copy(bits2.Scan0, buffer, 0, buffer.Length); //bitmap.UnlockBits(bits2); stream.WriteFrame(true, frame, 0, frame.Length); } } //loop_finished = true; writtingThreadFinnishEvent.Set(); } catch (Exception e) { UniLog.Log("OwO: " + e.Message); UniLog.Log(e.StackTrace); } finally { writtingThreadFinnishEvent.Set(); } }
//private void OpenErrorPage(string error) //{ // UIBuilder uiBuilder = this.SwapPanel(NeosSwapCanvasPanel.Slide.Left, 0.5f); // uiBuilder.VerticalLayout(4f, 0.0f, new Alignment?()); // uiBuilder.Style.PreferredHeight = 32f; // uiBuilder.Style.MinHeight = 32f; // uiBuilder.Style.FlexibleHeight = 100f; // LocaleString text1 = (LocaleString)error; // uiBuilder.Text(in text1, true, new Alignment?(), true, (string)null); // uiBuilder.Style.FlexibleHeight = -1f; // LocaleString text2 = "CameraControl.OBS.ReturnToConnect".AsLocaleKey((string)null, true, (Dictionary<string, IField>)null); // uiBuilder.Button(in text2, new ButtonEventHandler(this.OnReturnToConnect)); //} public void LinkUISlot() { UniLog.Log("Linking UI slot"); //Slot slot = UISlot.Duplicate(); Slot slot = UISlot ?? _uiTemplateRefField.Target.Reference.Target; UniLog.Log(slot); DynamicVariableSpace space = slot.FindSpace("UIVariables"); if (space == null) { return; } UniLog.Log("Found dynamic variable space"); ////Recording checkbox //Checkbox recording_checkbox; //space.TryReadValue<Checkbox>("recording_checkbox", out recording_checkbox); //this._recordUserCheckbox.Target = recording_checkbox; ////Data submission checkbox //Checkbox public_checkbox; //space.TryReadValue<Checkbox>("public_checkbox", out public_checkbox); //this._publicDomainCheckbox.Target = public_checkbox; //Recording time Text recording_time_text; space.TryReadValue <Text>("recording_time_text", out recording_time_text); this._recordingTime.Target = recording_time_text; //Animation checkbox Checkbox animation_checkbox; space.TryReadValue <Checkbox>("animation_checkbox", out animation_checkbox); this._animationsCheckbox.Target = animation_checkbox; //Generate Bvh checkbox Checkbox generate_bvh_checkbox; space.TryReadValue <Checkbox>("generate_bvh_checkbox", out generate_bvh_checkbox); this._generateBvhCheckbox.Target = generate_bvh_checkbox; //Record voices checkbox Checkbox record_voices_checkbox; space.TryReadValue <Checkbox>("record_voices_checkbox", out record_voices_checkbox); this._recordVoicesCheckbox.Target = record_voices_checkbox; #if NOHL //Record voices checkbox Checkbox record_hearing_checkbox; space.TryReadValue <Checkbox>("record_hearing_checkbox", out record_hearing_checkbox); this._recordHearingCheckbox.Target = record_hearing_checkbox; #endif #if NOHL //Video checkbox Checkbox video_checkbox; space.TryReadValue <Checkbox>("video_checkbox", out video_checkbox); this._videoCheckbox.Target = video_checkbox; #endif //Record button Button record_button; space.TryReadValue <Button>("record_button", out record_button); this._recordButton.Target = record_button; //Recording index TextField recording_index; space.TryReadValue <TextField>("recording_index", out recording_index); this._recordIndexField.Target = recording_index; //Voices checkbox Checkbox voices_checkbox; space.TryReadValue <Checkbox>("voices_checkbox", out voices_checkbox); this._voicesCheckbox.Target = voices_checkbox; //Hearing checkbox Checkbox hearing_checkbox; space.TryReadValue <Checkbox>("hearing_checkbox", out hearing_checkbox); this._hearingCheckbox.Target = hearing_checkbox; //External source checkbox Checkbox external_source_checkbox; space.TryReadValue <Checkbox>("external_source_checkbox", out external_source_checkbox); this._externalSourceCheckbox.Target = external_source_checkbox; //Animation checkbox2 Checkbox animation_checkbox2; space.TryReadValue <Checkbox>("animation_checkbox2", out animation_checkbox2); this._animationsCheckbox2.Target = animation_checkbox2; //Generate Bvh checkbox Checkbox generate_bvh_checkbox2; space.TryReadValue <Checkbox>("generate_bvh_checkbox2", out generate_bvh_checkbox2); this._generateBvhCheckbox2.Target = generate_bvh_checkbox2; //Avatar ref ReferenceField <Slot> avatar_ref_field; space.TryReadValue <ReferenceField <Slot> >("avatar_ref_field", out avatar_ref_field); this._avatarRefField.Target = avatar_ref_field; //Play button Button play_button; space.TryReadValue <Button>("play_button", out play_button); this._playButton.Target = play_button; UniLog.Log("Finished linking UI slot"); }
public void StopPlaying() { Task.Run(async() => await channel.ShutdownAsync()); output_readers = new Dictionary <RefID, IAsyncStreamReader <Bones> >(); fake_proxies = new Dictionary <RefID, List <Tuple <BodyNode, AvatarObjectSlot> > >(); avatar_stream_channels = new Dictionary <RefID, Dictionary <BodyNode, Tuple <bool, bool, bool> > >(); hands_are_tracked = new Dictionary <RefID, bool>(); proxy_slots = new Dictionary <RefID, Dictionary <BodyNode, Slot> >(); user_ids = new List <RefID>(); avatarManager.avatar_template = null; avatarManager.has_prepared_avatar = false; if (generateAnimation || generateBvh) { if (generateBvh) { bvhRecorder.StopRecording(); } if (generateAnimation) { animationRecorder.PreStopRecording(); metagen_comp.World.RunSynchronously(() => { animationRecorder.StopRecording(); }); } Task.Run(() => { if (generateAnimation) { animationRecorder.WaitForFinish(); } metagen_comp.World.RunSynchronously(() => { UniLog.Log("AVATARS COUNT KEK"); UniLog.Log(avatars.Count); if (generateAnimation) { metagen_comp.Slot.RemoveComponent(animationRecorder); } foreach (var item in avatars) { Slot slot = item.Value; slot.Destroy(); } avatars = new Dictionary <RefID, Slot>(); finger_slots = new Dictionary <RefID, Dictionary <BodyNode, Slot> >(); hand_posers = new Dictionary <RefID, Dictionary <Chirality, HandPoser> >(); finger_compensations = new Dictionary <RefID, Dictionary <BodyNode, floatQ> >(); }); }); } else { UniLog.Log("AVATARS COUNT KEK"); UniLog.Log(avatars.Count); foreach (var item in avatars) { Slot slot = item.Value; slot.Destroy(); } avatars = new Dictionary <RefID, Slot>(); finger_slots = new Dictionary <RefID, Dictionary <BodyNode, Slot> >(); hand_posers = new Dictionary <RefID, Dictionary <Chirality, HandPoser> >(); finger_compensations = new Dictionary <RefID, Dictionary <BodyNode, floatQ> >(); } isPlaying = false; }
public void StartInteracting() { UniLog.Log("Start Field interaction"); UniLog.Log("Attaching component"); client = metagen_comp.interaction_slot.GetComponent <WebsocketClient>(); if (client == null) { client = metagen_comp.interaction_slot.AttachComponent <WebsocketClient>(); } UniLog.Log("Attached component"); client.TextMessageReceived += OnTextMessageReceived; client.BinaryMessageReceived += OnBinaryMessageReceived; client.HandlingUser.Target = FrooxEngine.Engine.Current.WorldManager.FocusedWorld.LocalUser; client.URL.Value = new Uri("ws://localhost:8766"); //Input fields Slot input_field_holders = metagen_comp.input_interaction_fields_slot; List <Slot> inputFieldsHolders = input_field_holders?.GetAllChildren(); if (inputFieldsHolders != null) { foreach (Slot s in inputFieldsHolders) { List <ReferenceField <IField> > referenceSources = s.GetComponentsInChildren <ReferenceField <IField> >(); foreach (ReferenceField <IField> referenceSource in referenceSources) { IField field = referenceSource.Reference.Target; string name = referenceSource.Slot.Name; Type type = field.ValueType; if (field == null) { continue; } ; if (type == typeof(float)) { ((Sync <float>)field).OnValueChange += new SyncFieldEvent <float>((SyncField <float> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(float2)) { ((Sync <float2>)field).OnValueChange += new SyncFieldEvent <float2>((SyncField <float2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(float2x2)) { ((Sync <float2x2>)field).OnValueChange += new SyncFieldEvent <float2x2>((SyncField <float2x2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(float3)) { ((Sync <float3>)field).OnValueChange += new SyncFieldEvent <float3>((SyncField <float3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(float3x3)) { ((Sync <float3x3>)field).OnValueChange += new SyncFieldEvent <float3x3>((SyncField <float3x3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(float4)) { ((Sync <float4>)field).OnValueChange += new SyncFieldEvent <float4>((SyncField <float4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(float4x4)) { ((Sync <float4x4>)field).OnValueChange += new SyncFieldEvent <float4x4>((SyncField <float4x4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(int)) { ((Sync <int>)field).OnValueChange += new SyncFieldEvent <int>((SyncField <int> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(int2)) { ((Sync <int2>)field).OnValueChange += new SyncFieldEvent <int2>((SyncField <int2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(int3)) { ((Sync <int3>)field).OnValueChange += new SyncFieldEvent <int3>((SyncField <int3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(int4)) { ((Sync <int4>)field).OnValueChange += new SyncFieldEvent <int4>((SyncField <int4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(bool)) { ((Sync <bool>)field).OnValueChange += new SyncFieldEvent <bool>((SyncField <bool> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(bool2)) { ((Sync <bool2>)field).OnValueChange += new SyncFieldEvent <bool2>((SyncField <bool2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(bool3)) { ((Sync <bool3>)field).OnValueChange += new SyncFieldEvent <bool3>((SyncField <bool3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(bool4)) { ((Sync <bool4>)field).OnValueChange += new SyncFieldEvent <bool4>((SyncField <bool4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(floatQ)) { ((Sync <floatQ>)field).OnValueChange += new SyncFieldEvent <floatQ>((SyncField <floatQ> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(ulong)) { ((Sync <ulong>)field).OnValueChange += new SyncFieldEvent <ulong>((SyncField <ulong> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(ulong2)) { ((Sync <ulong2>)field).OnValueChange += new SyncFieldEvent <ulong2>((SyncField <ulong2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(ulong3)) { ((Sync <ulong3>)field).OnValueChange += new SyncFieldEvent <ulong3>((SyncField <ulong3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(ulong4)) { ((Sync <ulong4>)field).OnValueChange += new SyncFieldEvent <ulong4>((SyncField <ulong4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(long)) { ((Sync <long>)field).OnValueChange += new SyncFieldEvent <long>((SyncField <long> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(long2)) { ((Sync <long2>)field).OnValueChange += new SyncFieldEvent <long2>((SyncField <long2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(long3)) { ((Sync <long3>)field).OnValueChange += new SyncFieldEvent <long3>((SyncField <long3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(long4)) { ((Sync <long4>)field).OnValueChange += new SyncFieldEvent <long4>((SyncField <long4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(double)) { ((Sync <double>)field).OnValueChange += new SyncFieldEvent <double>((SyncField <double> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(double2)) { ((Sync <double2>)field).OnValueChange += new SyncFieldEvent <double2>((SyncField <double2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(double2x2)) { ((Sync <double2x2>)field).OnValueChange += new SyncFieldEvent <double2x2>((SyncField <double2x2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(double3)) { ((Sync <double3>)field).OnValueChange += new SyncFieldEvent <double3>((SyncField <double3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(double3x3)) { ((Sync <double3x3>)field).OnValueChange += new SyncFieldEvent <double3x3>((SyncField <double3x3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(double4)) { ((Sync <double4>)field).OnValueChange += new SyncFieldEvent <double4>((SyncField <double4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(double4x4)) { ((Sync <double4x4>)field).OnValueChange += new SyncFieldEvent <double4x4>((SyncField <double4x4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(doubleQ)) { ((Sync <doubleQ>)field).OnValueChange += new SyncFieldEvent <doubleQ>((SyncField <doubleQ> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(uint)) { ((Sync <uint>)field).OnValueChange += new SyncFieldEvent <uint>((SyncField <uint> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(uint2)) { ((Sync <uint2>)field).OnValueChange += new SyncFieldEvent <uint2>((SyncField <uint2> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(uint3)) { ((Sync <uint3>)field).OnValueChange += new SyncFieldEvent <uint3>((SyncField <uint3> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(uint4)) { ((Sync <uint4>)field).OnValueChange += new SyncFieldEvent <uint4>((SyncField <uint4> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(string)) { ((Sync <string>)field).OnValueChange += new SyncFieldEvent <string>((SyncField <string> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(color)) { ((Sync <color>)field).OnValueChange += new SyncFieldEvent <color>((SyncField <color> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(short)) { ((Sync <short>)field).OnValueChange += new SyncFieldEvent <short>((SyncField <short> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(ushort)) { ((Sync <ushort>)field).OnValueChange += new SyncFieldEvent <ushort>((SyncField <ushort> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(byte)) { ((Sync <byte>)field).OnValueChange += new SyncFieldEvent <byte>((SyncField <byte> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(sbyte)) { ((Sync <sbyte>)field).OnValueChange += new SyncFieldEvent <sbyte>((SyncField <sbyte> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(char)) { ((Sync <char>)field).OnValueChange += new SyncFieldEvent <char>((SyncField <char> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(colorX)) { ((Sync <colorX>)field).OnValueChange += new SyncFieldEvent <colorX>((SyncField <colorX> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(TimeSpan)) { ((Sync <TimeSpan>)field).OnValueChange += new SyncFieldEvent <TimeSpan>((SyncField <TimeSpan> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(DateTime)) { ((Sync <DateTime>)field).OnValueChange += new SyncFieldEvent <DateTime>((SyncField <DateTime> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } if (type == typeof(Decimal)) { ((Sync <Decimal>)field).OnValueChange += new SyncFieldEvent <Decimal>((SyncField <Decimal> f) => OnInputFieldChanged(name, type.ToString(), f.Value.ToString())); } input_fields[name] = field; } } } //Output fields Slot output_field_holders = metagen_comp.output_interaction_fields_slot; List <Slot> outputFieldsHolders = output_field_holders?.GetAllChildren(); if (outputFieldsHolders != null) { foreach (Slot s in outputFieldsHolders) { List <ReferenceField <IField> > referenceSources = s.GetComponentsInChildren <ReferenceField <IField> >(); foreach (ReferenceField <IField> referenceSource in referenceSources) { IField field = referenceSource.Reference.Target; string name = referenceSource.Slot.Name; output_fields[name] = field; } } } isInteracting = true; }
public void RecordStreams(float deltaT) { UniLog.Log(current_tracked_users); foreach (RefID user_id in current_tracked_users) { //UniLog.Log("Recording controller streams for " + user_id.ToString()); //Encode the streams UniLog.Log(user_id); UniLog.Log(output_writers[user_id]); UniLog.Log(primaryStreams[user_id].Item1); UniLog.Log(primaryStreams[user_id].Item2); UniLog.Log(primaryBlockedStreams[user_id].Item1); UniLog.Log(primaryBlockedStreams[user_id].Item2); BinaryWriterX writer = output_writers[user_id]; //WRITE deltaT writer.Write(deltaT); //float //WRITE primaryStreams //UniLog.Log("write primaryStreams"); writer.Write(primaryStreams[user_id].Item1.Value); //Left writer.Write(primaryStreams[user_id].Item2.Value); //Right //WRITE secondaryStreams //UniLog.Log("write secondaryStreams"); writer.Write(secondaryStreams[user_id].Item1.Value); //Left writer.Write(secondaryStreams[user_id].Item2.Value); //Right //WRITE grabStreams writer.Write(grabStreams[user_id].Item1.Value); //Left writer.Write(grabStreams[user_id].Item2.Value); //Right //WRITE menuStreams writer.Write(menuStreams[user_id].Item1.Value); //Left writer.Write(menuStreams[user_id].Item2.Value); //Right //WRITE strengthStreams writer.Write(strengthStreams[user_id].Item1.Value); //Left writer.Write(strengthStreams[user_id].Item2.Value); //Right //WRITE axisStreams writer.Write(axisStreams[user_id].Item1.Value); //Left writer.Write(axisStreams[user_id].Item2.Value); //Right //WRITE primaryBlockedStreams writer.Write(primaryBlockedStreams[user_id].Item1.Value); //Left writer.Write(primaryBlockedStreams[user_id].Item2.Value); //Right //WRITE secondaryBlockedStreams writer.Write(secondaryBlockedStreams[user_id].Item1.Value); //Left writer.Write(secondaryBlockedStreams[user_id].Item2.Value); //Right //WRITE laserActiveStreams writer.Write(laserActiveStreams[user_id].Item1.Value); //Left writer.Write(laserActiveStreams[user_id].Item2.Value); //Right //WRITE showLaserToOthersStreams writer.Write(showLaserToOthersStreams[user_id].Item1.Value); //Left writer.Write(showLaserToOthersStreams[user_id].Item2.Value); //Right //WRITE laserTargetStreams writer.Write(laserTargetStreams[user_id].Item1.Value); //Left writer.Write(laserTargetStreams[user_id].Item2.Value); //Right //WRITE grabDistanceStreams writer.Write(grabDistanceStreams[user_id].Item1.Value); //Left writer.Write(grabDistanceStreams[user_id].Item2.Value); //Right } }
public void StartRecording() { source_type = Source.FILE; //NEED to run this world-sycnrhonously World currentWorld = metagen_comp.World; int currentTotalUpdates = currentWorld.TotalUpdates; Slot logix_slot = metagen_comp.World.RootSlot.AddSlot("temporary logix slot"); bool added_logix = false; currentWorld.RunSynchronously(() => { foreach (var userItem in metagen_comp.userMetaData) { User user = userItem.Key; UserMetadata metadata = userItem.Value; if (!metadata.isRecording || (metagen_comp.LocalUser == user && !metagen_comp.record_local_user)) { continue; } RefID user_id = user.ReferenceID; current_tracked_users.Add(user_id); ReferenceRegister <User> userRegister = logix_slot.AttachComponent <ReferenceRegister <User> >(); userRegister.Target.Target = user; StandardController standardControllerLeft = logix_slot.AttachComponent <FrooxEngine.LogiX.Input.StandardController>(); EnumInput <Chirality> nodeEnum = logix_slot.AttachComponent <EnumInput <Chirality> >(); nodeEnum.Value.Value = Chirality.Left; standardControllerLeft.User.Target = userRegister; standardControllerLeft.Node.Target = nodeEnum; SyncRef <ValueStream <bool> > _primaryStreamLeft = (SyncRef <ValueStream <bool> >) typeof(StandardController).GetField("_primaryStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerLeft); SyncRef <ValueStream <bool> > _secondaryStreamLeft = (SyncRef <ValueStream <bool> >) typeof(StandardController).GetField("_secondaryStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerLeft); SyncRef <ValueStream <bool> > _grabStreamLeft = (SyncRef <ValueStream <bool> >) typeof(StandardController).GetField("_grabStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerLeft); SyncRef <ValueStream <bool> > _menuStreamLeft = (SyncRef <ValueStream <bool> >) typeof(StandardController).GetField("_menuStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerLeft); SyncRef <ValueStream <float> > _strengthStreamLeft = (SyncRef <ValueStream <float> >) typeof(StandardController).GetField("_strengthStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerLeft); SyncRef <ValueStream <float2> > _axisStreamLeft = (SyncRef <ValueStream <float2> >) typeof(StandardController).GetField("_axisStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerLeft); StandardController standardControllerRight = logix_slot.AttachComponent <FrooxEngine.LogiX.Input.StandardController>(); EnumInput <Chirality> nodeEnum2 = logix_slot.AttachComponent <EnumInput <Chirality> >(); nodeEnum2.Value.Value = Chirality.Right; standardControllerRight.User.Target = userRegister; standardControllerRight.Node.Target = nodeEnum2; SyncRef <ValueStream <bool> > _primaryStreamRight = (SyncRef <ValueStream <bool> >) typeof(StandardController).GetField("_primaryStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerRight); SyncRef <ValueStream <bool> > _secondaryStreamRight = (SyncRef <ValueStream <bool> >) typeof(StandardController).GetField("_secondaryStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerRight); SyncRef <ValueStream <bool> > _grabStreamRight = (SyncRef <ValueStream <bool> >) typeof(StandardController).GetField("_grabStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerRight); SyncRef <ValueStream <bool> > _menuStreamRight = (SyncRef <ValueStream <bool> >) typeof(StandardController).GetField("_menuStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerRight); SyncRef <ValueStream <float> > _strengthStreamRight = (SyncRef <ValueStream <float> >) typeof(StandardController).GetField("_strengthStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerRight); SyncRef <ValueStream <float2> > _axisStreamRight = (SyncRef <ValueStream <float2> >) typeof(StandardController).GetField("_axisStream", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(standardControllerRight); primaryStreamsRefs[user_id] = new Tuple <SyncRef <ValueStream <bool> >, SyncRef <ValueStream <bool> > >(_primaryStreamLeft, _primaryStreamRight); secondaryStreamsRefs[user_id] = new Tuple <SyncRef <ValueStream <bool> >, SyncRef <ValueStream <bool> > >(_secondaryStreamLeft, _secondaryStreamRight); grabStreamsRefs[user_id] = new Tuple <SyncRef <ValueStream <bool> >, SyncRef <ValueStream <bool> > >(_grabStreamLeft, _grabStreamRight); menuStreamsRefs[user_id] = new Tuple <SyncRef <ValueStream <bool> >, SyncRef <ValueStream <bool> > >(_menuStreamLeft, _menuStreamRight); strengthStreamsRefs[user_id] = new Tuple <SyncRef <ValueStream <float> >, SyncRef <ValueStream <float> > >(_strengthStreamLeft, _strengthStreamRight); axisStreamsRefs[user_id] = new Tuple <SyncRef <ValueStream <float2> >, SyncRef <ValueStream <float2> > >(_axisStreamLeft, _axisStreamRight); } added_logix = true; UniLog.Log("Added logix"); }); metagen_comp.StartTask(async() => { Task task = Task.Run(() => { bool all_streams_not_null = false; List <RefID> good_tracking_users = new List <RefID>(); //UniLog.Log("HO"); while (!all_streams_not_null & currentWorld.TotalUpdates <= currentTotalUpdates + 60) { if (!added_logix) { continue; } //UniLog.Log("HI"); bool all_user_streams_not_null = true; all_streams_not_null = true; foreach (RefID user_id in current_tracked_users) { //HMM: why does using .Target here rather than .RawTarget give a NullReferenceException?? bool primary_streams_not_null = (primaryStreamsRefs[user_id].Item1.RawTarget != null) & (primaryStreamsRefs[user_id].Item2.RawTarget != null); bool secondary_streams_not_null = (secondaryStreamsRefs[user_id].Item1.RawTarget != null) & (secondaryStreamsRefs[user_id].Item2.RawTarget != null); bool grab_streams_not_null = (grabStreamsRefs[user_id].Item1.RawTarget != null) & (grabStreamsRefs[user_id].Item2.RawTarget != null); bool menu_streams_not_null = (menuStreamsRefs[user_id].Item1.RawTarget != null) & (menuStreamsRefs[user_id].Item2.RawTarget != null); bool strength_streams_not_null = (strengthStreamsRefs[user_id].Item1.RawTarget != null) & (strengthStreamsRefs[user_id].Item2.RawTarget != null); bool axis_streams_not_null = (axisStreamsRefs[user_id].Item1.RawTarget != null) & (axisStreamsRefs[user_id].Item2.RawTarget != null); all_user_streams_not_null = primary_streams_not_null & secondary_streams_not_null & grab_streams_not_null & menu_streams_not_null & strength_streams_not_null & axis_streams_not_null; if (all_user_streams_not_null) { if (!good_tracking_users.Contains(user_id)) { good_tracking_users.Add(user_id); UniLog.Log("Added user " + user_id.ToString()); } } all_streams_not_null &= all_user_streams_not_null; } } current_tracked_users = good_tracking_users; //Get CommonToolStreamDriver List <RefID> good_tracking_users2 = new List <RefID>(); foreach (RefID user_id in current_tracked_users) { User user = currentWorld.GetUser(user_id); List <CommonToolStreamDriver> commonToolStreamDrivers = user.Root.Slot.GetComponents <CommonToolStreamDriver>(); ValueStream <bool> primaryBlockedStreamLeft = null; ValueStream <bool> secondaryBlockedStreamLeft = null; ValueStream <bool> laserActiveStreamLeft = null; ValueStream <bool> showLaserToOthersStreamLeft = null; ValueStream <float3> laserTargetStreamLeft = null; ValueStream <float> grabDistanceStreamLeft = null; ValueStream <bool> primaryBlockedStreamRight = null; ValueStream <bool> secondaryBlockedStreamRight = null; ValueStream <bool> laserActiveStreamRight = null; ValueStream <bool> showLaserToOthersStreamRight = null; ValueStream <float3> laserTargetStreamRight = null; ValueStream <float> grabDistanceStreamRight = null; foreach (CommonToolStreamDriver driver in commonToolStreamDrivers) { if (driver.Side.Value == Chirality.Left) { primaryBlockedStreamLeft = driver.PrimaryBlockedStream.Target; secondaryBlockedStreamLeft = driver.SecondaryBlockedStream.Target; laserActiveStreamLeft = driver.LaserActiveStream.Target; showLaserToOthersStreamLeft = driver.ShowLaserToOthersStream.Target; laserTargetStreamLeft = driver.LaserTargetStream.Target; grabDistanceStreamLeft = driver.GrabDistanceStream.Target; } else if (driver.Side.Value == Chirality.Right) { primaryBlockedStreamRight = driver.PrimaryBlockedStream.Target; secondaryBlockedStreamRight = driver.SecondaryBlockedStream.Target; laserActiveStreamRight = driver.LaserActiveStream.Target; showLaserToOthersStreamRight = driver.ShowLaserToOthersStream.Target; laserTargetStreamRight = driver.LaserTargetStream.Target; grabDistanceStreamRight = driver.GrabDistanceStream.Target; } } bool all_common_tool_streams_not_null = primaryBlockedStreamLeft != null & primaryBlockedStreamRight != null & secondaryBlockedStreamLeft != null & secondaryBlockedStreamRight != null & laserActiveStreamLeft != null & laserActiveStreamRight != null & showLaserToOthersStreamLeft != null & showLaserToOthersStreamRight != null & laserTargetStreamLeft != null & laserActiveStreamRight != null & grabDistanceStreamLeft != null & grabDistanceStreamRight != null; if (all_common_tool_streams_not_null) { good_tracking_users2.Add(user_id); primaryBlockedStreams[user_id] = new Tuple <ValueStream <bool>, ValueStream <bool> >(primaryBlockedStreamLeft, primaryBlockedStreamRight); secondaryBlockedStreams[user_id] = new Tuple <ValueStream <bool>, ValueStream <bool> >(secondaryBlockedStreamLeft, secondaryBlockedStreamRight); laserActiveStreams[user_id] = new Tuple <ValueStream <bool>, ValueStream <bool> >(laserActiveStreamLeft, laserActiveStreamRight); showLaserToOthersStreams[user_id] = new Tuple <ValueStream <bool>, ValueStream <bool> >(showLaserToOthersStreamLeft, showLaserToOthersStreamRight); laserTargetStreams[user_id] = new Tuple <ValueStream <float3>, ValueStream <float3> >(laserTargetStreamLeft, laserTargetStreamRight); grabDistanceStreams[user_id] = new Tuple <ValueStream <float>, ValueStream <float> >(grabDistanceStreamLeft, grabDistanceStreamRight); } } current_tracked_users = good_tracking_users2; foreach (RefID user_id in current_tracked_users) { primaryStreams[user_id] = new Tuple <ValueStream <bool>, ValueStream <bool> >(primaryStreamsRefs[user_id].Item1.RawTarget, primaryStreamsRefs[user_id].Item2.RawTarget); secondaryStreams[user_id] = new Tuple <ValueStream <bool>, ValueStream <bool> >(secondaryStreamsRefs[user_id].Item1.RawTarget, secondaryStreamsRefs[user_id].Item2.RawTarget); grabStreams[user_id] = new Tuple <ValueStream <bool>, ValueStream <bool> >(grabStreamsRefs[user_id].Item1.RawTarget, grabStreamsRefs[user_id].Item2.RawTarget); menuStreams[user_id] = new Tuple <ValueStream <bool>, ValueStream <bool> >(menuStreamsRefs[user_id].Item1.RawTarget, menuStreamsRefs[user_id].Item2.RawTarget); strengthStreams[user_id] = new Tuple <ValueStream <float>, ValueStream <float> >(strengthStreamsRefs[user_id].Item1.RawTarget, strengthStreamsRefs[user_id].Item2.RawTarget); axisStreams[user_id] = new Tuple <ValueStream <float2>, ValueStream <float2> >(axisStreamsRefs[user_id].Item1.RawTarget, axisStreamsRefs[user_id].Item2.RawTarget); RegisterUserStream(user_id, "controller_streams"); } //Destroy LogiX nodes currentWorld.RunSynchronously(() => { logix_slot.Destroy(); }); isRecording = true; }); //await CancelAfterAsync(ct=>task, TimeSpan.FromSeconds(30), CancellationToken.None); await task; }); }
public void PushToPool() { UniLog.CCAssert(Pool != null, "Pool is not signed"); Pool.AddToPool(this); }
//Record one chunk from the voice audio of each user public void InteractAudio() { //Debug.Log("Recording audio"); foreach (var item in audio_outputs) { AudioOutput audio_output = item.Value; RefID user_id = item.Key; if (audio_output != null) { buffer.EnsureSize <float>(metagen_comp.Engine.AudioSystem.BufferSize, false); if (audio_output.Source.Target != null) { //AudioSystemConnector.InformOfDSPTime(AudioSettings.dspTime); FrooxEngine.Engine.Current.AudioRead(); audio_sources_ready = true; AudioStream <MonoSample> stream = (AudioStream <MonoSample>)audio_output.Source.Target; stream.Read <MonoSample>(buffer.AsMonoBuffer()); for (int i = 0; i < buffer.Length; i++) { buffer[i] = MathX.Clamp(buffer[i], -1, 1); } float max_val = 0; for (int i = 0; i < buffer.Length; i++) { float val_squared = (float)Math.Pow((double)buffer[i], (double)2); //if (val_squared > max_val) max_val = val_squared; if (val_squared > max_val) { max_val = val_squared; break; } } if (isRecording[user_id]) { audio_recorders[user_id].ConvertAndWrite(buffer); //counting the number of consecutive all-zero buffers if (max_val == 0) { number_of_zero_buffers += 1; } else { number_of_zero_buffers = 0; } if (number_of_zero_buffers > zero_buffer_num_threshold) { StopWritingFile(user_id); } } else { //UniLog.Log(max_val); if (max_val > 0) { StartWritingFile(user_id); if (prev_buffer != null) { audio_recorders[user_id].ConvertAndWrite(prev_buffer); } audio_recorders[user_id].ConvertAndWrite(buffer); } } prev_buffer = buffer; //Task.Run(() => { audio_recorders[user_id].ConvertAndWrite(buffer); }); //metagen_comp.StartTask(async () => { audio_recorders[user_id].ConvertAndWrite(buffer); }); //} } else { UniLog.Log("Audio Output Source target was null! (hmm should we restart it?). Did it happen coz a user left (in which case we shouldn't restart it), or something else?"); //UniLog.Log("Restarting audio recording coz audio output source target was null!"); //StopRecording(); //StartRecording(); } } } }
public void PlayStreamsInternal() { if (!avatars_finished_loading) { return; } World currentWorld = metagen_comp.World; //currentWorld.RunSynchronously(() => //{ try { foreach (RefID user_id in user_ids) { //Decode the streams Task readTask = output_readers[user_id].MoveNext(); if (Task.WhenAny(readTask, Task.Delay(2000)).Result != readTask) { continue; } IEnumerator <float> reader = output_readers[user_id].Current.Transforms.GetEnumerator(); //UniLog.Log(output_readers[user_id].Current.Transforms); //await default(ToWorld); //READ deltaT //float deltaT = reader.ReadSingle(); int node_index = 0; //foreach (var item in fake_proxies[user_id]) foreach (var item in avatar_pose_nodes[user_id]) { BodyNode node = item.Item1; var available_streams = avatar_stream_channels[user_id][node]; //AvatarObjectSlot comp = item.Item2; AvatarObjectSlot avatarObject = fake_proxies[user_id][node_index].Item2; IAvatarObject comp = item.Item2; Slot slot = comp != null ? comp.Slot : null; if (node == BodyNode.Root) { slot = avatarObject.Slot; } //READ transform float x, y, z, w; //Scale stream if (available_streams.Item1) { reader.MoveNext(); x = reader.Current; reader.MoveNext(); y = reader.Current; reader.MoveNext(); z = reader.Current; reader.MoveNext(); float3 scale = new float3(x, y, z); if (slot != null) { //scale = avatarObject.Slot.Parent.LocalScaleToSpace(scale, slot.Parent); //slot.LocalScale = scale; //slot.GlobalScale = scale; } //UniLog.Log(slot.LocalScale.ToString()); } //Position stream if (available_streams.Item2) { x = reader.Current; reader.MoveNext(); y = reader.Current; reader.MoveNext(); z = reader.Current; reader.MoveNext(); float3 position = new float3(x, y, z); //UniLog.Log(position.x); //UniLog.Log(position.y); //UniLog.Log(position.z); if (slot != null) { //position = avatarObject.Slot.Parent.LocalPointToSpace(position, slot.Parent); //slot.LocalPosition = position; slot.GlobalPosition = position; } //UniLog.Log(slot.LocalPosition.ToString()); } //Rotation stream if (available_streams.Item3) { x = reader.Current; reader.MoveNext(); y = reader.Current; reader.MoveNext(); z = reader.Current; reader.MoveNext(); w = reader.Current; floatQ rotation = new floatQ(x, y, z, w); if (slot != null) { //rotation = avatarObject.Slot.Parent.LocalRotationToSpace(rotation, slot.Parent); //rotation = avatarObject.Slot.Parent.GlobalRotationToLocal(rotation); //slot.LocalRotation = rotation; slot.GlobalRotation = rotation; } //UniLog.Log(slot.LocalRotation.ToString()); } node_index++; } //READ finger pose var finger_slot = finger_slots[user_id]; if (hands_are_tracked[user_id]) { //UniLog.Log("UPDATING HANDS"); //FingerPlayerSource finger_source = finger_sources[user_id]; float x, y, z, w; //Left Hand HandPoser hand_poser = hand_posers[user_id][Chirality.Left]; floatQ lookRot = floatQ.LookRotation(hand_poser.HandForward, hand_poser.HandUp); for (int index = 0; index < FingerPoseStreamManager.FINGER_NODE_COUNT; ++index) { BodyNode node = (BodyNode)(18 + index); //READ whether finger data was obtained //bool was_succesful = reader.ReadBoolean(); x = reader.Current; reader.MoveNext(); y = reader.Current; reader.MoveNext(); z = reader.Current; reader.MoveNext(); w = reader.Current; reader.MoveNext(); if (finger_slot.ContainsKey(node)) { floatQ rot = new floatQ(x, y, z, w); rot = lookRot * rot; Slot root = hand_poser.HandRoot.Target ?? hand_poser.Slot; rot = finger_slot[node].Parent.SpaceRotationToLocal(rot, root); rot = rot * finger_compensations[user_id][node]; finger_slot[node].LocalRotation = rot; } } //Right Hand hand_poser = hand_posers[user_id][Chirality.Right]; lookRot = floatQ.LookRotation(hand_poser.HandForward, hand_poser.HandUp); for (int index = 0; index < FingerPoseStreamManager.FINGER_NODE_COUNT; ++index) { BodyNode node = (BodyNode)(47 + index); //READ whether finger data was obtained //bool was_succesful = reader.ReadBoolean(); x = reader.Current; reader.MoveNext(); y = reader.Current; reader.MoveNext(); z = reader.Current; reader.MoveNext(); w = reader.Current; reader.MoveNext(); //finger_source.UpdateFingerPose(node, new floatQ(x, y, z, w)); if (finger_slot.ContainsKey(node)) { floatQ rot = new floatQ(x, y, z, w); rot = lookRot * rot; Slot root = hand_poser.HandRoot.Target ?? hand_poser.Slot; rot = finger_slot[node].Parent.SpaceRotationToLocal(rot, root); rot = rot * finger_compensations[user_id][node]; finger_slot[node].LocalRotation = rot; } } } //await default(ToBackground); } if (generateAnimation) { animationRecorder.RecordFrame(); } if (generateBvh) { bvhRecorder.RecordFrame(); } } catch (Exception e) { UniLog.Log("OwO: " + e.Message); //this.StopPlaying(); metagen_comp.StopPlaying(); } //}); }
private void OnTextMessageReceived(WebsocketClient client, string msg) { //UniLog.Log("hi"); UniLog.Log(msg); // UniLog.Log(output_field.Value); string name = msg.Split('/')[0]; string value_str = msg.Substring(name.Length); metagen_comp.World.RunSynchronously(() => { if (output_fields.ContainsKey(name) && output_fields[name] != null) { IField field = output_fields[name]; Type type = field.ValueType; if (type == typeof(float)) { float result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <float>)field).Value = result; } } if (type == typeof(float2)) { float2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <float2>)field).Value = result; } } if (type == typeof(float2x2)) { float2x2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <float2x2>)field).Value = result; } } if (type == typeof(float3)) { float3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <float3>)field).Value = result; } } if (type == typeof(float3x3)) { float3x3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <float3x3>)field).Value = result; } } if (type == typeof(float4)) { float4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <float4>)field).Value = result; } } if (type == typeof(float4x4)) { float4x4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <float4x4>)field).Value = result; } } if (type == typeof(int)) { int result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <int>)field).Value = result; } } if (type == typeof(int2)) { int2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <int2>)field).Value = result; } } if (type == typeof(int3)) { int3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <int3>)field).Value = result; } } if (type == typeof(int4)) { int4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <int4>)field).Value = result; } } if (type == typeof(bool)) { bool result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <bool>)field).Value = result; } } if (type == typeof(bool2)) { bool2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <bool2>)field).Value = result; } } if (type == typeof(bool3)) { bool3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <bool3>)field).Value = result; } } if (type == typeof(bool4)) { bool4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <bool4>)field).Value = result; } } if (type == typeof(floatQ)) { floatQ result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <floatQ>)field).Value = result; } } if (type == typeof(ulong)) { ulong result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <ulong>)field).Value = result; } } if (type == typeof(ulong2)) { ulong2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <ulong2>)field).Value = result; } } if (type == typeof(ulong3)) { ulong3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <ulong3>)field).Value = result; } } if (type == typeof(ulong4)) { ulong4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <ulong4>)field).Value = result; } } if (type == typeof(long)) { long result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <long>)field).Value = result; } } if (type == typeof(long2)) { long2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <long2>)field).Value = result; } } if (type == typeof(long3)) { long3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <long3>)field).Value = result; } } if (type == typeof(long4)) { long4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <long4>)field).Value = result; } } if (type == typeof(double)) { double result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <double>)field).Value = result; } } if (type == typeof(double2)) { double2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <double2>)field).Value = result; } } if (type == typeof(double2x2)) { double2x2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <double2x2>)field).Value = result; } } if (type == typeof(double3)) { double3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <double3>)field).Value = result; } } if (type == typeof(double3x3)) { double3x3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <double3x3>)field).Value = result; } } if (type == typeof(double4)) { double4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <double4>)field).Value = result; } } if (type == typeof(double4x4)) { double4x4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <double4x4>)field).Value = result; } } if (type == typeof(doubleQ)) { doubleQ result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <doubleQ>)field).Value = result; } } if (type == typeof(uint)) { uint result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <uint>)field).Value = result; } } if (type == typeof(uint2)) { uint2 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <uint2>)field).Value = result; } } if (type == typeof(uint3)) { uint3 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <uint3>)field).Value = result; } } if (type == typeof(uint4)) { uint4 result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <uint4>)field).Value = result; } } if (type == typeof(string)) { string result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <string>)field).Value = result; } } if (type == typeof(color)) { color result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <color>)field).Value = result; } } if (type == typeof(short)) { short result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <short>)field).Value = result; } } if (type == typeof(ushort)) { ushort result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <ushort>)field).Value = result; } } if (type == typeof(byte)) { byte result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <byte>)field).Value = result; } } if (type == typeof(sbyte)) { sbyte result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <sbyte>)field).Value = result; } } if (type == typeof(char)) { char result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <char>)field).Value = result; } } if (type == typeof(colorX)) { colorX result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <colorX>)field).Value = result; } } if (type == typeof(TimeSpan)) { TimeSpan result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <TimeSpan>)field).Value = result; } } if (type == typeof(DateTime)) { DateTime result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <DateTime>)field).Value = result; } } if (type == typeof(Decimal)) { Decimal result; if (RobustParser.TryParse(value_str, out result)) { ((Sync <Decimal>)field).Value = result; } } } }); }
private void ProcessFriendRemoved(Friend friend) { UniLog.Log("removing friend " + friend.FriendUserId); dataBase.UpdateIsFriend(friend.FriendUserId, false); }
private async Task GenerateNew() { Processors.Clear(); ComponentTypeProcessor ComponentProcessor = new ComponentTypeProcessor(); LogixTypeProcessor LogixProcessor = new LogixTypeProcessor(); SyncMemberTypeProcessor SyncMemberProcessor = new SyncMemberTypeProcessor(); IEnumerable <Type> frooxEngineTypes = AppDomain.CurrentDomain.GetAssemblies().Where(T => T.GetName().Name == "FrooxEngine").SelectMany(T => T.GetTypes()); IEnumerable <Type> frooxEngineComponentTypes = frooxEngineTypes.Where(T => T.Namespace != null && T.Namespace.StartsWith("FrooxEngine")).Where(T => T.IsSubclassOf(typeof(Component)) || T.IsSubclassOf(typeof(LogixNode)) || T.IsSubclassOf(typeof(SyncObject))); Camera ComponentCamera = Slot.GetComponentOrAttach <Camera>(); ComponentCamera.Projection.Value = CameraProjection.Orthographic; ComponentCamera.Clear.Value = CameraClearMode.Color; ComponentCamera.ClearColor.Value = new color(new float4()); ComponentCamera.Postprocessing.Value = false; ComponentCamera.RenderShadows.Value = false; ComponentCamera.SelectiveRender.Clear(); ComponentCamera.SelectiveRender.Add(); NeosTypeProcessor.VisualCaptureCamera = ComponentCamera; //Ensure all necessary directories exist prior to starting Directory.CreateDirectory($"{BasePath}Config\\"); Directory.CreateDirectory($"{BasePath}Data\\"); Directory.CreateDirectory($"{BasePath}Logix\\"); Directory.CreateDirectory($"{BasePath}Components\\"); NeosTypeProcessor.TypeBlacklist = JsonConvert.DeserializeObject <List <string> >(File.ReadAllText($"{BasePath}Config\\TypeBlacklist.json")); Dictionary <string, Data.OverloadSetting> typeOverloads = JsonConvert.DeserializeObject <Dictionary <string, Data.OverloadSetting> >(File.ReadAllText($"{BasePath}Config\\TypeOverloads.json")); if (typeOverloads == null) { UniLog.Log("Could not load TypeOverloads"); ComponentProcessor.Overloads = new Dictionary <string, Data.OverloadSetting>(); LogixProcessor.Overloads = new Dictionary <string, Data.OverloadSetting>(); SyncMemberProcessor.Overloads = new Dictionary <string, Data.OverloadSetting>(); } else { ComponentProcessor.Overloads = typeOverloads; LogixProcessor.Overloads = typeOverloads; SyncMemberProcessor.Overloads = typeOverloads; } Processors.Add(LogixProcessor); Processors.Add(ComponentProcessor); Processors.Add(SyncMemberProcessor); List <string> typeErrors = new List <string>(); List <string> missingGenericTypeAttribute = new List <string>(); try { int totalComponents = frooxEngineComponentTypes.Count(); int completedComponents = 0; foreach (Type neosType in frooxEngineComponentTypes) { NeosTypeProcessor.VisualSlot = Slot.AddSlot("Visual", false);; NeosTypeProcessor.InstanceSlot = Slot.AddSlot("ComponentTarget", false); ComponentCamera.SelectiveRender[0] = NeosTypeProcessor.VisualSlot; NeosTypeProcessor.VisualSlot.LocalPosition = new float3(0, 0, 0.5f); foreach (NeosTypeProcessor currentProcessor in Processors) { try { if (currentProcessor.ValidateProcessor(neosType)) { object instance = currentProcessor.CreateInstance(neosType); if (instance != null) { await currentProcessor.GenerateVisual(instance, instance.GetType()); await currentProcessor.GenerateData(instance, instance.GetType()); currentProcessor.DestroyInstance(instance); } } } catch (Exception ex) { typeErrors.Add(neosType.FullName); UniLog.Log($"Component generation failed for {neosType.FullName}: {ex}"); } } NeosTypeProcessor.VisualSlot.Destroy(false); NeosTypeProcessor.InstanceSlot.Destroy(false); await new Updates(2); completedComponents++; componentProgress.Content.Value = $"{completedComponents} / {totalComponents} ({Math.Round(((float)completedComponents / (float)totalComponents) * 100.0f)}%)"; if (neosType.IsSubclassOf(typeof(Component)) && !neosType.IsSubclassOf(typeof(LogixNode)) && (neosType.IsGenericType || neosType.IsGenericTypeDefinition)) { if (neosType.GetCustomAttribute <GenericTypes>() is null) { missingGenericTypeAttribute.Add(neosType.FullName); } } } File.WriteAllText($"{BasePath}Data\\MissingGenericTypeAttribute.txt", String.Join("\r\n", missingGenericTypeAttribute)); } catch (Exception ex) { UniLog.Log("Processor Failed: " + ex); } File.WriteAllText($"{BasePath}Data\\TypeErrors.json", JsonConvert.SerializeObject(typeErrors, Formatting.Indented)); List <string> assemblyNames = new List <string> { "FrooxEngine", "CodeX", "BaseX", "CloudX.Shared", "PostX", "QuantityX", "CommandX", "ArchiteX" }; frooxEngineTypes = AppDomain.CurrentDomain.GetAssemblies().Where(T => assemblyNames.Contains(T.GetName().Name)).SelectMany(T => T.GetTypes()); List <EnumData> neosEnumTypes = new List <EnumData>(); foreach (Type neosType in frooxEngineTypes) { if (neosType.IsEnum) { EnumData enumData = new EnumData { Name = neosType.FullName, Values = System.Enum.GetNames(neosType).ToList() }; neosEnumTypes.Add(enumData); } } File.WriteAllText($"{BasePath}Data\\EnumTypes.json", JsonConvert.SerializeObject(neosEnumTypes, Formatting.Indented)); }
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); } }