public override void Read(SocketEndpoint sendingEndpoint, BinaryReader message) { LightBroadcaster.ChangeType changeType = (LightBroadcaster.ChangeType)message.ReadByte(); if (LightBroadcaster.HasFlag(changeType, LightBroadcaster.ChangeType.Properties)) { if (attachedComponent == null) { attachedComponent = gameObject.AddComponent <Light>(); } attachedComponent.enabled = message.ReadBoolean(); attachedComponent.type = (LightType)message.ReadByte(); attachedComponent.bounceIntensity = message.ReadSingle(); attachedComponent.color = message.ReadColor(); attachedComponent.colorTemperature = message.ReadSingle(); Texture cookieTexture; if (AssetService.Instance.TryDeserializeTexture(message, out cookieTexture)) { attachedComponent.cookie = cookieTexture; } attachedComponent.cookieSize = message.ReadSingle(); attachedComponent.cullingMask = message.ReadInt32(); attachedComponent.intensity = message.ReadSingle(); attachedComponent.range = message.ReadSingle(); attachedComponent.shadowBias = message.ReadSingle(); attachedComponent.shadowCustomResolution = message.ReadInt32(); attachedComponent.shadowNearPlane = message.ReadSingle(); attachedComponent.shadowNormalBias = message.ReadSingle(); attachedComponent.shadows = (LightShadows)message.ReadByte(); attachedComponent.spotAngle = message.ReadSingle(); } }
public Task <bool> RunRemoteLocalizationAsync(SocketEndpoint socketEndpoint, Guid spatialLocalizerID, ISpatialLocalizationSettings settings) { DebugLog($"Initiating remote localization: {socketEndpoint.Address}, {spatialLocalizerID.ToString()}"); if (remoteLocalizationSessions.TryGetValue(socketEndpoint, out var currentCompletionSource)) { DebugLog("Canceling existing remote localization session: {socketEndpoint.Address}"); currentCompletionSource.TrySetCanceled(); remoteLocalizationSessions.Remove(socketEndpoint); } TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>(); remoteLocalizationSessions.Add(socketEndpoint, taskCompletionSource); using (MemoryStream stream = new MemoryStream()) using (BinaryWriter message = new BinaryWriter(stream)) { message.Write(LocalizeCommand); message.Write(spatialLocalizerID); settings.Serialize(message); socketEndpoint.Send(stream.ToArray()); } return(taskCompletionSource.Task); }
protected override bool ShouldSendChanges(SocketEndpoint endpoint) { using (StateSynchronizationPerformanceMonitor.Instance.MeasureEventDuration(PerformanceComponentName, "ShouldSendChanges")) { return(base.ShouldSendChanges(endpoint)); } }
protected override void Read(SocketEndpoint sendingEndpoint, BinaryReader message, byte changeType) { base.Read(sendingEndpoint, message, changeType); if (LineRendererBroadcaster.HasFlag(changeType, LineRendererBroadcaster.LineRendererChangeType.StaticProperties)) { Renderer.generateLightingData = message.ReadBoolean(); Renderer.loop = message.ReadBoolean(); Renderer.useWorldSpace = message.ReadBoolean(); Renderer.numCapVertices = message.ReadInt32(); Renderer.textureMode = (LineTextureMode)message.ReadByte(); Renderer.alignment = (LineAlignment)message.ReadByte(); Renderer.colorGradient = ReadColorGradient(message); Renderer.widthCurve = ReadAnimationCurve(message); } if (LineRendererBroadcaster.HasFlag(changeType, LineRendererBroadcaster.LineRendererChangeType.DynamicProperties)) { Vector3[] positions = message.ReadVector3Array(); Renderer.positionCount = positions?.Length ?? 0; Renderer.SetPositions(positions); Renderer.endColor = message.ReadColor(); Renderer.startColor = message.ReadColor(); Renderer.widthMultiplier = message.ReadSingle(); Renderer.endWidth = message.ReadSingle(); Renderer.startWidth = message.ReadSingle(); } }
private void OnDisconnected(SocketEndpoint endpoint) { if (connectedEndpoint == endpoint) { connectedEndpoint = null; } }
public override void Read(SocketEndpoint sendingEndpoint, BinaryReader message) { TextBroadcaster.ChangeType changeType = (TextBroadcaster.ChangeType)message.ReadByte(); if (TextBroadcaster.HasFlag(changeType, TextBroadcaster.ChangeType.Text)) { attachedComponent.text = message.ReadString(); } if (TextBroadcaster.HasFlag(changeType, TextBroadcaster.ChangeType.FontAndPlacement)) { attachedComponent.alignment = (TextAnchor)message.ReadByte(); attachedComponent.color = message.ReadColor(); attachedComponent.fontSize = message.ReadInt32(); attachedComponent.fontStyle = (FontStyle)message.ReadByte(); attachedComponent.lineSpacing = message.ReadSingle(); attachedComponent.horizontalOverflow = (HorizontalWrapMode)message.ReadByte(); attachedComponent.verticalOverflow = (VerticalWrapMode)message.ReadByte(); attachedComponent.font = TextService.Instance.GetFont(message.ReadGuid()); } if (TextBroadcaster.HasFlag(changeType, TextBroadcaster.ChangeType.Materials)) { var materials = MaterialPropertyAsset.ReadMaterials(message, null); if (materials != null && materials.Length > 0) { attachedComponent.material = materials[0]; } } if (TextBroadcaster.HasFlag(changeType, TextBroadcaster.ChangeType.MaterialProperty)) { int materialIndex = message.ReadInt32(); MaterialPropertyAsset.Read(message, new Material[] { attachedComponent.material }, materialIndex); } }
private void OnConnected(SocketEndpoint endpoint) { if (participants.TryGetValue(endpoint, out var existingParticipant)) { Debug.LogWarning("SpatialCoordinateSystemParticipant connected that already existed."); return; } DebugLog($"Creating new SpatialCoordinateSystemParticipant, IPAddress: {endpoint.Address}, DebugLogging: {debugLogging}"); SpatialCoordinateSystemParticipant participant = new SpatialCoordinateSystemParticipant(endpoint, debugVisual, debugVisualScale); participants[endpoint] = participant; participant.ShowDebugVisuals = showDebugVisuals; participant.SendSupportedLocalizersMessage(endpoint, localizers.Keys); if (ParticipantConnected == null) { DebugLog($"No ParticipantConnected event handlers exist"); } else { DebugLog($"Invoking ParticipantConnected event"); ParticipantConnected.Invoke(participant); } }
private void HandleCalibrationDataCommand(SocketEndpoint endpoint, string command, BinaryReader reader, int remainingDataSize) { int calibrationDataPayloadLength = reader.ReadInt32(); byte[] calibrationDataPayload = reader.ReadBytes(calibrationDataPayloadLength); CalculatedCameraCalibration calibration; if (CalculatedCameraCalibration.TryDeserialize(calibrationDataPayload, out calibration)) { if (sharedSpatialCoordinateProxy == null) { sharedSpatialCoordinateProxy = new GameObject("App HMD Shared Spatial Coordinate"); sharedSpatialCoordinateProxy.transform.SetParent(transform, worldPositionStays: true); if (appDeviceObserver != null && appDeviceObserver.ConnectedEndpoint != null && SpatialCoordinateSystemManager.IsInitialized && SpatialCoordinateSystemManager.Instance.TryGetSpatialCoordinateSystemParticipant(appDeviceObserver.ConnectedEndpoint, out SpatialCoordinateSystemParticipant participant)) { sharedSpatialCoordinateProxy.transform.position = participant.PeerSpatialCoordinateWorldPosition; sharedSpatialCoordinateProxy.transform.rotation = participant.PeerSpatialCoordinateWorldRotation; } } compositionManager.EnableHolographicCamera(sharedSpatialCoordinateProxy.transform, new CalibrationData(calibration.Intrinsics, calibration.Extrinsics)); } else { Debug.LogError("Received a CalibrationData packet from the HoloLens that could not be understood."); } }
public override void Read(SocketEndpoint sendingEndpoint, BinaryReader message) { ImageBroadcaster.ChangeType changeType = (ImageBroadcaster.ChangeType)message.ReadByte(); if (ImageBroadcaster.HasFlag(changeType, ImageBroadcaster.ChangeType.Data)) { attachedComponent.overrideSprite = ImageService.Instance.GetSprite(message.ReadGuid()); attachedComponent.sprite = ImageService.Instance.GetSprite(message.ReadGuid()); attachedComponent.fillAmount = message.ReadSingle(); attachedComponent.color = message.ReadColor(); attachedComponent.alphaHitTestMinimumThreshold = message.ReadSingle(); attachedComponent.fillOrigin = message.ReadInt32(); attachedComponent.fillClockwise = message.ReadBoolean(); attachedComponent.fillMethod = (Image.FillMethod)message.ReadByte(); attachedComponent.fillCenter = message.ReadBoolean(); attachedComponent.preserveAspect = message.ReadBoolean(); attachedComponent.type = (Image.Type)message.ReadByte(); attachedComponent.enabled = message.ReadBoolean(); } if (ImageBroadcaster.HasFlag(changeType, ImageBroadcaster.ChangeType.Materials)) { var materials = MaterialPropertyAsset.ReadMaterials(message, null); if (materials != null && materials.Length > 0) { attachedComponent.material = materials[0]; } } if (ImageBroadcaster.HasFlag(changeType, ImageBroadcaster.ChangeType.MaterialProperty)) { int materialIndex = message.ReadInt32(); MaterialPropertyAsset.Read(message, new Material[] { attachedComponent.material }, materialIndex); } }
protected override void Read(SocketEndpoint sendingEndpoint, BinaryReader message, byte changeType) { if (TextMeshBroadcaster.HasFlag(changeType, TextMeshBroadcaster.TextMeshChangeType.Text)) { textMesh.text = message.ReadString(); } if (TextMeshBroadcaster.HasFlag(changeType, TextMeshBroadcaster.TextMeshChangeType.FontAndPlacement)) { textMesh.alignment = (TextAlignment)message.ReadByte(); textMesh.anchor = (TextAnchor)message.ReadByte(); textMesh.characterSize = message.ReadSingle(); textMesh.color = message.ReadColor(); textMesh.fontSize = message.ReadInt32(); textMesh.fontStyle = (FontStyle)message.ReadByte(); textMesh.lineSpacing = message.ReadSingle(); textMesh.offsetZ = message.ReadSingle(); textMesh.richText = message.ReadBoolean(); textMesh.tabSize = message.ReadSingle(); textMesh.font = TextMeshService.Instance.GetFont(message.ReadGuid()); if (textMesh.font != null) { Renderer.material = textMesh.font.material; } } base.Read(sendingEndpoint, message, changeType); }
private void OnConnected(SocketEndpoint endpoint) { if (participants.ContainsKey(endpoint)) { Debug.LogWarning("SpatialCoordinateSystemParticipant connected that already existed"); return; } DebugLog($"Creating new SpatialCoordinateSystemParticipant, IPAddress: {endpoint.Address}, DebugLogging: {debugLogging}"); SpatialCoordinateSystemParticipant participant = new SpatialCoordinateSystemParticipant(endpoint, debugVisual, debugVisualScale); participants[endpoint] = participant; participant.ShowDebugVisuals = showDebugVisuals; if (ParticipantConnected == null) { Debug.LogWarning("Participant created, but no connection listeners were found"); return; } participant.SendSupportedLocalizersMessage(endpoint, localizers.Keys); DebugLog($"Invoking ParticipantConnected event"); ParticipantConnected.Invoke(participant); }
private void OnDisconnect(SocketEndpoint endpoint) { if (endpoint.Address == editorAddress) { DisableChildren(); } }
private async void UploadCalibrationDataAsync(SocketEndpoint endpoint, string command, BinaryReader reader, int remainingDataSize) { bool succeeded = true; string uploadMessage = "Successfully uploaded calibration data."; Debug.Log("Received a calibration data payload"); var size = reader.ReadInt32(); var data = reader.ReadBytes(size); if (CalculatedCameraCalibration.TryDeserialize(data, out var calibrationData)) { var fileName = "CalibrationData.json"; Windows.Storage.StorageFile file = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting); await Windows.Storage.FileIO.WriteBytesAsync(file, data); } else { succeeded = false; uploadMessage = "Uploading calibration data failed - failed to deserialize calibration data."; Debug.LogError(uploadMessage); } SendUploadResult(succeeded, uploadMessage); }
protected virtual void Read(SocketEndpoint sendingEndpoint, BinaryReader message, byte changeType) { switch (changeType) { case ChangeType.ObserverObjectCreated: { PerConnectionInstantiationState state; if (perConnectionInstantiationState.TryGetValue(sendingEndpoint, out state)) { state.observerObjectCreated = true; if (DynamicObject != null) { state.sendTransformHierarchyBinding = true; } } } break; case ChangeType.ObserverHierarchyBound: if (DynamicObject != null) { DynamicObject.GetComponent <TransformBroadcaster>().BlockedConnections.Remove(sendingEndpoint); } break; } }
/// <summary> /// Returns true if the provided endpoint should receive a transform update, otherwise false /// </summary> /// <param name="endpoint">network connection to potentially send transform update</param> /// <returns>True if the provided endpoint should receive a transform update, otherwise false</returns> public bool ShouldSendTransformInHierarchy(SocketEndpoint endpoint) { if (isParentTransformReportingFlagValid) { StateSynchronizationPerformanceMonitor.Instance.IncrementEventCount(PerformanceComponentName, "ShouldSendTransformInHierarchy.UsedCache"); return(cachedParentTransformReportingFlag); } if (BlockedConnections.Contains(endpoint)) { StateSynchronizationPerformanceMonitor.Instance.IncrementEventCount(PerformanceComponentName, "BlockedConnection"); return(false); } if (IsHidden) { return(false); } if (CachedParentTransform != null) { cachedParentTransformReportingFlag = CachedParentTransform.ShouldSendTransformInHierarchy(endpoint); isParentTransformReportingFlagValid = true; StateSynchronizationPerformanceMonitor.Instance.IncrementEventCount(PerformanceComponentName, "ShouldSendTransformInHierarchy.LookupParent"); return(cachedParentTransformReportingFlag); } else { return(true); } }
public Task <bool> LocalizeAsync(SocketEndpoint socketEndpoint, Guid spatialLocalizerID, ISpatialLocalizationSettings settings) { DebugLog("LocalizeAsync"); if (!participants.TryGetValue(socketEndpoint, out SpatialCoordinateSystemParticipant participant)) { Debug.LogError($"Could not find a SpatialCoordinateSystemParticipant for SocketEndpoint {socketEndpoint.Address}"); return(Task.FromResult(false)); } if (currentLocalizationSession != null) { if (participant == currentLocalizationSession.Peer && remoteLocalizationSessions.TryGetValue(socketEndpoint, out var taskCompletionSource) && taskCompletionSource.TrySetCanceled()) { DebugLog($"Current localization session for {socketEndpoint.Address} was canceled based on a new localization request."); remoteLocalizationSessions.Remove(socketEndpoint); } else { Debug.LogError($"Failed to start localization session because an existing localization session is in progress"); return(Task.FromResult(false)); } } if (!localizers.TryGetValue(spatialLocalizerID, out ISpatialLocalizer localizer)) { Debug.LogError($"Could not find a ISpatialLocalizer for spatialLocalizerID {spatialLocalizerID}"); return(Task.FromResult(false)); } DebugLog("Returning a localization session."); return(RunLocalizationSessionAsync(localizer, settings, participant)); }
private void TcpConnectionManager_OnConnected(SocketEndpoint endpoint) { // Restart the timeline at 0 each time we reconnect to the HoloLens timestampStopwatch = Stopwatch.StartNew(); sharedCoordinateParticipant = null; currentConnection = endpoint; }
private async void OnLocalizeMessageReceived(SocketEndpoint socketEndpoint, string command, BinaryReader reader, int remainingDataSize) { DebugLog("LocalizeMessageReceived"); if (!participants.TryGetValue(socketEndpoint, out SpatialCoordinateSystemParticipant participant)) { Debug.LogError($"Could not find a SpatialCoordinateSystemParticipant for SocketEndpoint {socketEndpoint.Address}"); SendLocalizationCompleteCommand(socketEndpoint, localizationSuccessful: false); return; } Guid spatialLocalizerID = reader.ReadGuid(); if (!localizers.TryGetValue(spatialLocalizerID, out ISpatialLocalizer localizer)) { Debug.LogError($"Request to begin localization with localizer {spatialLocalizerID} but no localizer with that ID was registered"); SendLocalizationCompleteCommand(socketEndpoint, localizationSuccessful: false); return; } if (!localizer.TryDeserializeSettings(reader, out ISpatialLocalizationSettings settings)) { Debug.LogError($"Failed to deserialize settings for localizer {spatialLocalizerID}"); SendLocalizationCompleteCommand(socketEndpoint, localizationSuccessful: false); return; } bool localizationSuccessful = await RunLocalizationSessionAsync(localizer, settings, participant); // Ensure that the participant's fully-localized state is sent before sending the LocalizationComplete command (versus waiting // for the next Update). This way the remote peer receives the located state of the participant before they receive the notification // that this localization session completed. participant.EnsureStateChangesAreBroadcast(); SendLocalizationCompleteCommand(socketEndpoint, localizationSuccessful); }
public void HandleCameraCommand(SocketEndpoint endpoint, string command, BinaryReader reader, int remainingDataSize) { float timeStamp = reader.ReadSingle(); hologramSynchronizer.RegisterCameraUpdate(timeStamp); transform.position = reader.ReadVector3(); transform.rotation = reader.ReadQuaternion(); }
private void OnConnected(SocketEndpoint endpoint) { if (TransformBroadcaster != null) { Destroy(TransformBroadcaster); } TransformBroadcaster = this.gameObject.EnsureComponent <TransformBroadcaster>(); }
public override void Read(SocketEndpoint sendingEndpoint, BinaryReader message) { byte changeType = message.ReadByte(); EnsureRenderer(message, changeType); Read(sendingEndpoint, message, changeType); }
private void HandleCameraCommand(SocketEndpoint endpoint, string command, BinaryReader reader, int remainingDataSize) { float timestamp = reader.ReadSingle(); Vector3 cameraPosition = reader.ReadVector3(); Quaternion cameraRotation = reader.ReadQuaternion(); compositionManager.AddCameraPose(cameraPosition, cameraRotation, timestamp); }
private void OnServerConnected(SocketerClient client, int sourceId, string clientAddress) { Debug.Log("Server connected to " + clientAddress); SocketEndpoint socketEndpoint = new SocketEndpoint(client, timeoutInterval, clientAddress, sourceId); serverConnections[sourceId] = socketEndpoint; socketEndpoint.QueueIncomingMessages(inputMessageQueue); newConnections.Enqueue(socketEndpoint); }
private void OnClientConnected(SocketerClient client, MessageEvent e) { Debug.Log("Client connected to " + e.SourceHost); SocketEndpoint socketEndpoint = new SocketEndpoint(client, timeoutInterval, e.SourceHost, e.SourceId); clientConnection = socketEndpoint; socketEndpoint.QueueIncomingMessages(inputMessageQueue); newConnections.Enqueue(socketEndpoint); }
private void HandlePerfMonitoringModeEnableRequest(SocketEndpoint endpoint, string command, BinaryReader reader, int remainingDataSize) { bool enabled = reader.ReadBoolean(); if (StateSynchronizationPerformanceMonitor.Instance != null) { StateSynchronizationPerformanceMonitor.Instance.SetDiagnosticMode(enabled); } }
private void OnClientConnected(SocketerClient client, int sourceId, string hostAddress) { Debug.Log("Client connected to " + hostAddress); SocketEndpoint socketEndpoint = new SocketEndpoint(client, timeoutInterval, hostAddress, sourceId); clientConnection = socketEndpoint; socketEndpoint.QueueIncomingMessages(inputMessageQueue); newConnections.Enqueue(socketEndpoint); }
protected virtual void OnDisconnected(SocketEndpoint endpoint) { if (currentConnection == endpoint) { currentConnection = null; } NotifyDisconnected(endpoint); }
public override void Read(SocketEndpoint sendingEndpoint, BinaryReader message) { MaskBroadcaster.ChangeType changeType = (MaskBroadcaster.ChangeType)message.ReadByte(); if (MaskBroadcaster.HasFlag(changeType, MaskBroadcaster.ChangeType.Properties)) { attachedComponent.enabled = message.ReadBoolean(); } }
private void OnSupportedLocalizersMessageReceived(SocketEndpoint socketEndpoint, string command, BinaryReader reader, int remainingDataSize) { if (!participants.TryGetValue(socketEndpoint, out SpatialCoordinateSystemParticipant participant)) { Debug.LogError($"Failed to find a SpatialCoordinateSystemParticipant for an attached SocketEndpoint"); return; } participant.ReadSupportedLocalizersMessage(reader); }
public override void Read(SocketEndpoint sendingEndpoint, BinaryReader message) { CanvasRendererBroadcaster.ChangeType changeType = (CanvasRendererBroadcaster.ChangeType)message.ReadByte(); if (CanvasRendererBroadcaster.HasFlag(changeType, CanvasRendererBroadcaster.ChangeType.Properties)) { attachedComponent.SetAlpha(message.ReadSingle()); attachedComponent.SetColor(message.ReadColor()); } }