public static void DrawHandPreview(IMixedRealityHandJointService handJointService, Handedness handedness) { if (!handJointService.IsHandTracked(handedness)) { return; } GenerateHandJointLookup(); Handles.color = previewJointColor; foreach (KeyValuePair <TrackedHandJoint, bool> setting in showHandJointSettings) { if (!setting.Value) { continue; } Transform jointTransform = handJointService.RequestJointTransform(setting.Key, handedness); if (jointTransform == null) { continue; } Handles.SphereHandleCap(0, jointTransform.position, jointTransform.rotation, previewJointSize, EventType.Repaint); } }
protected override void LateUpdate() { base.LateUpdate(); if (!MixedRealityToolkit.IsInitialized) { return; } if (!Initialized) { return; } #region hand tracking IMixedRealityInputSystem inputSystem = MixedRealityToolkit.Instance.GetService <IMixedRealityInputSystem>(); IMixedRealityHandJointService handJointService = (inputSystem as MixedRealityInputSystem).GetDataProvider <IMixedRealityHandJointService>(); int jointIndex = 0; // Right hand foreach (TrackedHandJoint joint in handJointTypes) { if (handJointService.IsHandTracked(Handedness.Right)) { Transform jointTransform = handJointService.RequestJointTransform(joint, Handedness.Right); handJoints[jointIndex].position = jointTransform.position; handJoints[jointIndex].rotation = jointTransform.rotation; handJoints[jointIndex].gameObject.SetActive(true); } else if (!Application.isEditor || disableInactiveFingersInEditor) { handJoints[jointIndex].gameObject.SetActive(false); } jointIndex++; } // Left hand foreach (TrackedHandJoint joint in handJointTypes) { if (handJointService.IsHandTracked(Handedness.Left)) { Transform jointTransform = handJointService.RequestJointTransform(joint, Handedness.Left); handJoints[jointIndex].position = jointTransform.position; handJoints[jointIndex].rotation = jointTransform.rotation; handJoints[jointIndex].gameObject.SetActive(true); } else if (!Application.isEditor || disableInactiveFingersInEditor) { handJoints[jointIndex].gameObject.SetActive(false); } jointIndex++; } #endregion }
public override void DrawSceneGUI(object target, SceneView sceneView) { if (!Application.isPlaying || !ShowHandPreviewInSceneView) { return; } IMixedRealityHandJointService handJointService = (IMixedRealityHandJointService)target; DrawHandPreview(handJointService, Handedness.Left); DrawHandPreview(handJointService, Handedness.Right); }
void Start() { handJointService = CoreServices.GetInputSystemDataProvider <IMixedRealityHandJointService>(); if (handJointService == null) { Debug.LogError("Can't get IMixedRealityHandJointService."); return; } dataProviderAccess = CoreServices.InputSystem as IMixedRealityDataProviderAccess; if (dataProviderAccess == null) { Debug.LogError("Can't get IMixedRealityDataProviderAccess."); return; } // ハンドレイを非表示にする //PointerUtils.SetHandRayPointerBehavior(PointerBehavior.AlwaysOff); Initialize(); }
void Update() { IMixedRealityHandJointService handJointService = null; if (CoreServices.InputSystem != null) { var dataProviderAccess = CoreServices.InputSystem as IMixedRealityDataProviderAccess; if (dataProviderAccess != null) { handJointService = dataProviderAccess.GetDataProvider <IMixedRealityHandJointService>(); } } if (handJointService != null) { Transform jointTransform = handJointService.RequestJointTransform(TrackedHandJoint.Palm, Handedness.Right); var p = jointTransform.position; posText.text = "(" + p.x.ToString("F3") + ", " + p.y.ToString("F3") + ", " + p.z.ToString("F3") + ")"; var r = jointTransform.rotation.eulerAngles; rotText.text = "(" + r.x.ToString("000") + ", " + r.y.ToString("000") + ", " + r.z.ToString("000") + ")"; } }
public override void DrawInspectorGUI(object target) { IMixedRealityHandJointService handJointService = (IMixedRealityHandJointService)target; EditorGUILayout.LabelField("Tracking State", EditorStyles.boldLabel); if (!Application.isPlaying) { GUI.color = disabledColor; EditorGUILayout.Toggle("Left Hand Tracked", false); EditorGUILayout.Toggle("Right Hand Tracked", false); } else { GUI.color = enabledColor; EditorGUILayout.Toggle("Left Hand Tracked", handJointService.IsHandTracked(Handedness.Left)); EditorGUILayout.Toggle("Right Hand Tracked", handJointService.IsHandTracked(Handedness.Right)); } GenerateHandJointLookup(); GUI.color = enabledColor; EditorGUILayout.Space(); EditorGUILayout.LabelField("Editor Settings", EditorStyles.boldLabel); ShowHandPreviewInSceneView = SessionState.GetBool(ShowHandPreviewInSceneViewKey, false); bool showHandPreviewInSceneView = EditorGUILayout.Toggle("Show Preview in Scene View", ShowHandPreviewInSceneView); if (ShowHandPreviewInSceneView != showHandPreviewInSceneView) { SessionState.SetBool(ShowHandPreviewInSceneViewKey, showHandPreviewInSceneView); } ShowHandJointFoldout = SessionState.GetBool(ShowHandJointFoldoutKey, false); ShowHandJointFoldout = EditorGUILayout.Foldout(ShowHandJointFoldout, "Visible Hand Joints", true); SessionState.SetBool(ShowHandJointFoldoutKey, ShowHandJointFoldout); if (ShowHandJointFoldout) { #region setting buttons EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("All")) { foreach (TrackedHandJoint joint in Enum.GetValues(typeof(TrackedHandJoint))) { if (joint == TrackedHandJoint.None) { continue; } SessionState.SetBool(showHandJointSettingKeys[joint], true); showHandJointSettings[joint] = true; } } if (GUILayout.Button("Fingers")) { foreach (TrackedHandJoint joint in Enum.GetValues(typeof(TrackedHandJoint))) { bool setting = false; switch (joint) { case TrackedHandJoint.IndexTip: case TrackedHandJoint.IndexDistalJoint: case TrackedHandJoint.IndexKnuckle: case TrackedHandJoint.IndexMetacarpal: case TrackedHandJoint.IndexMiddleJoint: case TrackedHandJoint.MiddleTip: case TrackedHandJoint.MiddleDistalJoint: case TrackedHandJoint.MiddleKnuckle: case TrackedHandJoint.MiddleMetacarpal: case TrackedHandJoint.MiddleMiddleJoint: case TrackedHandJoint.PinkyTip: case TrackedHandJoint.PinkyDistalJoint: case TrackedHandJoint.PinkyKnuckle: case TrackedHandJoint.PinkyMetacarpal: case TrackedHandJoint.PinkyMiddleJoint: case TrackedHandJoint.RingTip: case TrackedHandJoint.RingDistalJoint: case TrackedHandJoint.RingKnuckle: case TrackedHandJoint.RingMetacarpal: case TrackedHandJoint.RingMiddleJoint: case TrackedHandJoint.ThumbTip: case TrackedHandJoint.ThumbDistalJoint: case TrackedHandJoint.ThumbMetacarpalJoint: case TrackedHandJoint.ThumbProximalJoint: setting = true; break; default: break; case TrackedHandJoint.None: continue; } SessionState.SetBool(showHandJointSettingKeys[joint], setting); showHandJointSettings[joint] = setting; } } if (GUILayout.Button("Fingertips")) { foreach (TrackedHandJoint joint in Enum.GetValues(typeof(TrackedHandJoint))) { bool setting = false; switch (joint) { case TrackedHandJoint.IndexTip: case TrackedHandJoint.MiddleTip: case TrackedHandJoint.PinkyTip: case TrackedHandJoint.RingTip: case TrackedHandJoint.ThumbTip: setting = true; break; default: break; case TrackedHandJoint.None: continue; } SessionState.SetBool(showHandJointSettingKeys[joint], setting); showHandJointSettings[joint] = setting; } } if (GUILayout.Button("None")) { foreach (TrackedHandJoint joint in Enum.GetValues(typeof(TrackedHandJoint))) { if (joint == TrackedHandJoint.None) { continue; } SessionState.SetBool(showHandJointSettingKeys[joint], false); showHandJointSettings[joint] = false; } } EditorGUILayout.EndHorizontal(); #endregion EditorGUILayout.BeginVertical(EditorStyles.helpBox); foreach (TrackedHandJoint joint in Enum.GetValues(typeof(TrackedHandJoint))) { if (joint == TrackedHandJoint.None) { continue; } bool prevSetting = showHandJointSettings[joint]; bool newSetting = EditorGUILayout.Toggle(joint.ToString(), prevSetting); if (newSetting != prevSetting) { SessionState.SetBool(showHandJointSettingKeys[joint], newSetting); showHandJointSettings[joint] = newSetting; } } EditorGUILayout.EndVertical(); } }
protected virtual void LateUpdate() { if (!MixedRealityToolkit.IsInitialized) { return; } if (!Initialized) { return; } #region hand tracking IMixedRealityInputSystem inputSystem = MixedRealityToolkit.Instance.GetService <IMixedRealityInputSystem>(); IMixedRealityHandJointService handJointService = (inputSystem as MixedRealityInputSystem).GetDataProvider <IMixedRealityHandJointService>(); int fingerIndex = 0; // Right hand foreach (TrackedHandJoint joint in fingerJointTypes) { if (handJointService.IsHandTracked(Handedness.Right)) { Transform jointTransform = handJointService.RequestJointTransform(joint, Handedness.Right); fingers[fingerIndex].position = jointTransform.position; fingers[fingerIndex].rotation = jointTransform.rotation; fingers[fingerIndex].gameObject.SetActive(true); } else if (!Application.isEditor || disableInactiveFingersInEditor) { fingers[fingerIndex].gameObject.SetActive(false); } fingerIndex++; } // Left hand foreach (TrackedHandJoint joint in fingerJointTypes) { if (handJointService.IsHandTracked(Handedness.Left)) { Transform jointTransform = handJointService.RequestJointTransform(joint, Handedness.Left); fingers[fingerIndex].position = jointTransform.position; fingers[fingerIndex].rotation = jointTransform.rotation; fingers[fingerIndex].gameObject.SetActive(true); } else if (!Application.isEditor || disableInactiveFingersInEditor) { fingers[fingerIndex].gameObject.SetActive(false); } fingerIndex++; } if (palms.Length == 2) { if (handJointService.IsHandTracked(Handedness.Right)) { Transform palmTransform = handJointService.RequestJointTransform(TrackedHandJoint.Palm, Handedness.Right); palms[0].gameObject.SetActive(true); palms[0].position = palmTransform.position; palms[0].rotation = palmTransform.rotation; } else if (!Application.isEditor || disableInactiveFingersInEditor) { palms[0].gameObject.SetActive(false); } if (handJointService.IsHandTracked(Handedness.Left)) { Transform palmTransform = handJointService.RequestJointTransform(TrackedHandJoint.Palm, Handedness.Left); palms[1].gameObject.SetActive(true); palms[1].position = palmTransform.position; palms[1].rotation = palmTransform.rotation; } else if (!Application.isEditor || disableInactiveFingersInEditor) { palms[1].gameObject.SetActive(false); } } #endregion SurfacePosition = surfaceTransform.position; }
// Start is called before the first frame update void Start() { handJointService = CoreServices.GetInputSystemDataProvider <IMixedRealityHandJointService>(); if (handJointService == null) { Debug.LogError("Can't get IMixedRealityHandJointService."); return; } dataProviderAccess = CoreServices.InputSystem as IMixedRealityDataProviderAccess; if (dataProviderAccess == null) { Debug.LogError("Can't get IMixedRealityDataProviderAccess."); return; } // ハンドレイを非表示にする PointerUtils.SetHandRayPointerBehavior(PointerBehavior.AlwaysOff); /* * Mesh mesh = new Mesh(); * * // 頂点座標情報 * mesh.vertices = new Vector3[] { * new Vector3( 0f, 1f, 0f), * new Vector3( 0.5f, 0f, 0f), * new Vector3(-0.5f, 0f, 0f), * new Vector3( 1f, -1f, 0f), * new Vector3( 0f, -1f, 0f), * new Vector3( -1f, -1f, 0f) * }; * * //各頂点にUV座標を設定する * mesh.uv = new Vector2[] { * new Vector2 ( 0.5f, 1f), * new Vector2 (0.75f, 0.5f), * new Vector2 (0.25f, 0.5f), * new Vector2 ( 1f, 0f), * new Vector2 ( 0.5f, 0f), * new Vector2 ( 0f, 0f) * }; * * // 頂点を結ぶ順番情報 * mesh.triangles = new int[] { * 0, 1, 2, * 1, 3, 4, * 2, 4, 5 * }; * * // 三角形と頂点からメッシュの法線を再計算する * mesh.RecalculateNormals(); * * // バウンディングボリュームを再計算する * mesh.RecalculateBounds(); * * // MeshRendererにメッシュ情報を渡すために必要 * MeshFilter filter = GetComponent<MeshFilter>(); * filter.sharedMesh = mesh; * filter.sharedMesh.name = "SampleMesh"; * * // マテリアルを設定する * MeshRenderer renderer = GetComponent<MeshRenderer>(); * renderer.material = mat; */ }