//protected override void OnChanges() //{ //} private void StartRPCServer() { channel = new Channel("127.0.0.1:50052", ChannelCredentials.Insecure); this.client = new DataComm.DataCommClient(channel); }
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); } }