void OnSpeechToTextResult(LexiconSpeechResult speechResult) { foreach (GameObject markerObject in markers) { Destroy(markerObject); } markers.Clear(); foreach (LexiconSpeechResult.WordResult wordResult in speechResult.WordResults) { if (positionEntity.FindValueByName(wordResult.Word, true) != null) { FocusPosition focusPosition = focusManager.GetFocusData <FocusPosition>(wordResult.RealtimeStart); if (focusPosition != null) { GameObject markerObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); markerObject.transform.position = focusPosition.Position; markerObject.transform.localScale = new Vector3(markerScale, markerScale, markerScale); markerObject.transform.parent = this.transform; markerObject.GetComponent <Renderer>().material = markerMaterial; markerObject.GetComponent <SphereCollider>().enabled = false; markers.Add(markerObject); } } } }
public override bool Process(LexiconRuntimeResult runtimeResult) { // There may be multiple selections, break the phrase up by selection entity. // E.g. "Move this one over here and this one over here." foreach (LexiconEntityMatch selectionMatch in runtimeResult.GetEntityMatches(Strings.Selection)) { // We expect the position entity to come after the selection entity. LexiconEntityMatch positionMatch = runtimeResult.GetEntityAfter(Strings.Position, selectionMatch); if (positionMatch != null) { FocusSelection focusSelection = selectionMatch.FocusSelection; FocusPosition focusPosition = positionMatch.FocusPosition; if (focusSelection != null && focusPosition != null) { float floorAngle = Vector3.Angle(Vector3.up, focusPosition.Normal); if (floorAngle < 45) { focusSelection.SelectedObject.transform.position = focusPosition.Position; } else { // Match the normal with vertical surfaces. focusSelection.SelectedObject.transform.position = focusPosition.Position; focusSelection.SelectedObject.transform.forward = -focusPosition.Normal; } } } } // We've consumed this intent, return true to prevent other handlers from firing. return(true); }
public void CaptureFocus() { // Get a focus position data entry from the pool. FocusPosition focusPosition = focusManager.GetPooledData <FocusPosition>(); Ray cameraRay = new Ray(mainCamera.transform.position, mainCamera.transform.forward); RaycastHit hit; if (Physics.Raycast(cameraRay, out hit)) { // This sample uses a LexiconSelectable component to determine object selectability. // You could just as easily use layers, tags, or your own scripts. LexiconSelectable selectable = hit.collider.gameObject.GetComponentInParent <LexiconSelectable>(); if (selectable != null) { FocusSelection focusSelection = focusManager.GetPooledData <FocusSelection>(); focusSelection.SelectedObject = selectable.gameObject; focusManager.AddFocusData(focusSelection); } // Set the focus position to the hit point if present. focusPosition.Position = hit.point; focusPosition.Normal = hit.normal; } else { // Set the focus position in front of the camera if no hit point. focusPosition.Position = mainCamera.transform.position + mainCamera.transform.forward * 2.0f; focusPosition.Normal = -mainCamera.transform.forward; } // Add our focus position data entry. focusManager.AddFocusData(focusPosition); // Update the pointer position. pointerSphere.transform.position = focusPosition.Position; float dist = Vector3.Distance(focusPosition.Position, mainCamera.transform.position); float scale = pointerSize * dist; pointerSphere.transform.localScale = new Vector3(scale, scale, scale); // Add a dwell position entry if the user's gaze is lingering on a spot. float speed = Vector3.Magnitude(lastPosition - focusPosition.Position) / Time.deltaTime; if (speed < dwellSpeed) { FocusDwellPosition dwellPosition = focusManager.GetPooledData <FocusDwellPosition>(); dwellPosition.Position = focusPosition.Position; dwellPosition.Normal = focusPosition.Normal; focusManager.AddFocusData(dwellPosition); } lastPosition = focusPosition.Position; }
public void CaptureFocus() { // Get a focus position data entry from the pool. FocusPosition focusPosition = focusManager.GetPooledData <FocusPosition>(); Ray pointerRay = mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(pointerRay, out hit)) { // This sample uses a LexiconSelectable component to determine object selectability. // You could just as easily use layers, tags, or your own scripts. LexiconSelectable selectable = hit.collider.gameObject.GetComponentInParent <LexiconSelectable>(); if (selectable != null) { FocusSelection focusSelection = focusManager.GetPooledData <FocusSelection>(); focusSelection.SelectedObject = selectable.gameObject; focusManager.AddFocusData(focusSelection); } // Set the focus position to the hit point if present. focusPosition.Position = hit.point; focusPosition.Normal = hit.normal; } else { // Set the focus position in front of the mouse if no hit point. focusPosition.Position = pointerRay.GetPoint(1.5f); focusPosition.Normal = -pointerRay.direction; } // Add our focus position data entry. focusManager.AddFocusData(focusPosition); // Add a dwell position entry if the mouse is lingering on a spot. float speed = Vector3.Magnitude(lastPosition - focusPosition.Position) / Time.deltaTime; if (speed < dwellSpeed) { FocusDwellPosition dwellPosition = focusManager.GetPooledData <FocusDwellPosition>(); dwellPosition.Position = focusPosition.Position; dwellPosition.Normal = focusPosition.Normal; focusManager.AddFocusData(dwellPosition); } lastPosition = focusPosition.Position; }
void OnSpeechToTextResult(LexiconSpeechResult speechResult) { foreach (GameObject labelObject in labels) { Destroy(labelObject); } labels.Clear(); foreach (GameObject markerObject in markers) { Destroy(markerObject); } markers.Clear(); foreach (LexiconSpeechResult.WordResult wordResult in speechResult.WordResults) { FocusPosition focusPosition = focusManager.GetFocusData <FocusPosition>(wordResult.RealtimeStart); //DwellPosition dwellPosition = focusManager.GetFocusData<DwellPosition>(wordResult.realtimeStart); if (focusPosition != null) { GameObject labelObject = new GameObject("WordAlignmentLabel"); labelObject.transform.position = focusPosition.Position; labelObject.transform.localScale = new Vector3(labelScale, labelScale, labelScale); labelObject.transform.parent = this.transform; TextMesh textMesh = labelObject.AddComponent <TextMesh>(); textMesh.text = wordResult.Word; textMesh.color = labelColor; textMesh.font = labelFont; textMesh.fontSize = labelFontSize; textMesh.GetComponent <Renderer>().sharedMaterial = labelFont.material; labels.Add(labelObject); GameObject markerObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); markerObject.transform.position = focusPosition.Position; markerObject.transform.localScale = new Vector3(markerScale, markerScale, markerScale); markerObject.transform.parent = this.transform; markerObject.GetComponent <Renderer>().material = markerMaterial; markerObject.GetComponent <Collider>().enabled = false; markers.Add(markerObject); } } }
public async Task ActTrackingFocusAsync(FocusPosition position) { await NoValue(RequestGenerator.Serialize("actTrackingFocus", ApiVersion.V1_0, position)).ConfigureAwait(false); }