public void ApplyPose(bool leftHand, string poseName) { if (_vrIk == null) { _vrIk = GetComponent <VRIK>(); } if (_vrIk == null) { Debug.LogError("This script requires a VRIK component on the same object", gameObject); return; } Transform pose = GetPoseByName(poseName); Transform targetHand = leftHand ? _vrIk.references.leftHand : _vrIk.references.rightHand; HandPoser handPoser = targetHand.GetComponent <HandPoser>(); if (handPoser == null) { handPoser = targetHand.gameObject.AddComponent <HandPoser>(); } else { handPoser.weight = 1f; } handPoser.poseRoot = pose; }
public void ClearPose(bool leftHand) { if (_vrIk == null) { _vrIk = GetComponent <VRIK>(); } if (_vrIk == null) { Debug.LogError("This script requires a VRIK component on the same object", gameObject); return; } Transform targetHand = leftHand ? _vrIk.references.leftHand : _vrIk.references.rightHand; HandPoser handPoser = targetHand.GetComponent <HandPoser>(); if (handPoser != null) { handPoser.weight = 0f; } }
virtual public void OnSelected() // look at a particular instance object { myPoser = target as HandPoser; }
public override void OnInspectorGUI() { myPoser = target as HandPoser; DrawDefaultInspector(); if (GUILayout.Button ("Capture Open Pose")){ myPoser.SampleRotations(myPoser.morphs.poseOpen); } if (GUILayout.Button ("Capture Closed Pose")){ myPoser.SampleRotations(myPoser.morphs.poseFist); } if (GUILayout.Button ("Capture OneFingerPoint Pose")){ myPoser.SampleRotations(myPoser.morphs.poseOneFingerPoint); } if (GUILayout.Button ("Capture OneFingerGrasp Pose")){ myPoser.SampleRotations(myPoser.morphs.poseOneFingerGrasp); } if (GUILayout.Button ("Capture TwoFingerPoint Pose")){ myPoser.SampleRotations(myPoser.morphs.poseTwoFingerPoint); } if (GUILayout.Button ("Capture TwoFingerGrasp Pose")){ myPoser.SampleRotations(myPoser.morphs.poseTwoFingerGrasp); } if (GUILayout.Button ("Capture FourFingerPoint Pose")){ myPoser.SampleRotations(myPoser.morphs.poseFourFingerPoint); } if (GUILayout.Button ("Capture FourFingerGrasp Pose")){ myPoser.SampleRotations(myPoser.morphs.poseFourFingerGrasp); } GUI.backgroundColor = Color.red; if (GUILayout.Button ("Write Poses to XML")){ XmlSerializer serializer = new XmlSerializer(typeof(HandPoser.poseSet)); FileStream stream = new FileStream(myPoser.XMLDirectory+myPoser.pathname, FileMode.Create); serializer.Serialize(stream, myPoser.morphs); stream.Close(); } if (GUILayout.Button ("Read Poses from XML")){ myPoser.InitPoses(); } if (GUILayout.Button ("Call Start")){ myPoser.Start(); } if (GUILayout.Button ("FLIP Poses")){ myPoser.FlipPoses(); } GUI.backgroundColor = Color.green; if (GUILayout.Button ("SnapTo Open Pose")){ myPoser.SnapToPose(myPoser.morphs.poseOpen,myPoser.fingers); } if (GUILayout.Button ("SnapTo Closed Pose")){ myPoser.SnapToPose(myPoser.morphs.poseFist,myPoser.fingers); } if (GUILayout.Button ("SnapTo OneFingerPoint Pose")){ myPoser.SnapToPose(myPoser.morphs.poseOneFingerPoint,myPoser.fingers); } if (GUILayout.Button ("SnapTo OneFingerGrasp Pose")){ myPoser.SnapToPose(myPoser.morphs.poseOneFingerGrasp,myPoser.fingers); } if (GUILayout.Button ("SnapTo TwoFingerPoint Pose")){ myPoser.SnapToPose(myPoser.morphs.poseTwoFingerPoint,myPoser.fingers); } if (GUILayout.Button ("SnapTo TwoFingerGrasp Pose")){ myPoser.SnapToPose(myPoser.morphs.poseTwoFingerGrasp,myPoser.fingers); } if (GUILayout.Button ("SnapTo FourFingerPoint Pose")){ myPoser.SnapToPose(myPoser.morphs.poseFourFingerPoint,myPoser.fingers); } if (GUILayout.Button ("SnapTo FourFingerGrasp Pose")){ myPoser.SnapToPose(myPoser.morphs.poseFourFingerGrasp,myPoser.fingers); } }
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(); } //}); }