public void RecordFrame(float deltaT) { bool streams_ok = (streamRecorder == null ? false : streamRecorder.isRecording) || !metagen_comp.recording_streams; bool eye_streams_ok = (eyeRecorder == null ? false : eyeRecorder.isRecording) || !metagen_comp.recording_faces; bool mouth_streams_ok = (mouthRecorder == null ? false : mouthRecorder.isRecording) || !metagen_comp.recording_faces; bool controller_streams_ok = (controllerRecorder == null ? false : controllerRecorder.isRecording) || !metagen_comp.recording_controllers; bool vision_ok = (visionRecorder == null ? false : visionRecorder.isRecording) || !metagen_comp.recording_vision; bool hearing_ok = (metagen_comp.hearingRecorder == null ? false : metagen_comp.hearingRecorder.isRecording) || !metagen_comp.recording_hearing; bool voice_ok = (voiceRecorder == null ? false : (voiceRecorder.isRecording && voiceRecorder.audio_sources_ready)) || !metagen_comp.recording_voice; bool all_ready = voice_ok && streams_ok && controller_streams_ok && eye_streams_ok && mouth_streams_ok && vision_ok && hearing_ok; //bool all_ready = hearing_ok; if (all_ready && streamRecorder == null? false : streamRecorder.isRecording) { UniLog.Log("recording pose streams"); streamRecorder.RecordStreams(deltaT); } if (all_ready && controllerRecorder == null? false : controllerRecorder.isRecording) { UniLog.Log("recording controller streams"); controllerRecorder.RecordStreams(deltaT); } if (all_ready && eyeRecorder == null? false : eyeRecorder.isRecording) { //UniLog.Log("recording streams"); eyeRecorder.RecordStreams(deltaT); } if (all_ready && mouthRecorder == null? false : mouthRecorder.isRecording) { //UniLog.Log("recording streams"); mouthRecorder.RecordStreams(deltaT); } if (all_ready && visionRecorder == null? false : visionRecorder.isRecording) { //UniLog.Log("recording vision"); //if (frame_index == 30) // hearingRecorder.videoStartedRecording = true; visionRecorder.RecordVision(); } if (all_ready && animationRecorder == null? false : animationRecorder.isRecording) { animationRecorder.RecordFrame(); } if (all_ready && bvhRecorder == null? false : bvhRecorder.isRecording) { bvhRecorder.RecordFrame(); } //if (recording && all_ready && recording_hearing_user != null && hearingRecorder==null? false : hearingRecorder.isRecording) //{ //} }
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(); } //}); }