private void SetSelectionFromCursor() { ClearSelection(); if (!Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out RaycastHit hitInfo)) { return; } _selectedRenderer = hitInfo.transform.GetComponent <MeshRenderer>(); _selectedOriginalMaterial = _selectedRenderer.sharedMaterial; _selectedRenderer.material = _selectionMaterial; var requestWrapper = new RequestWrapper { ElementTooltipRequest = new ElementTooltipRequest { ElementId = _selectedRenderer.name } }; _backend.SendRequest(requestWrapper, replyWrapper => { ElementTooltipReply tt = replyWrapper.ElementTooltipReply; _selectionText = $"Id: {tt.ElementId}\nClass: {tt.ClassLabel}\nCategory: {tt.CategoryLabel}\nModel: {tt.ModelLabel}"; }); }
public void OnUpdate() { if (_elementIdExportQueuePosition >= _elementIdExportQueueCount || _backend.HasPendingRequest) { return; } Profiler.BeginSample("Bentley.ExportMeshRequestManager.OnUpdate"); // This is all to work around RepeatedField generating garbage for each request: // * RepeatedField can't use an existing buffer // * RepeatedField.Clear releases the backing array, so we can't just Clear and then AddRange // * RepeatedField has no option to mark Length vs Capacity, so we can't just reuse a larger RepeatedField RequestWrapper requestWrapper; int count = Math.Min(_elementIdExportQueueCount - _elementIdExportQueuePosition, BatchSize); if (count == BatchSize) { RepeatedField <string> requestIds = _cachedRequestWrapper.ExportMeshesRequest.ElementIds; for (int i = 0; i < count; ++i) { requestIds[i] = _elementIdExportQueue[i + _elementIdExportQueuePosition]; } requestWrapper = _cachedRequestWrapper; } else { // Doesn't match size of cached MsgWrapper, so just allocate a one-off request object requestWrapper = new RequestWrapper() { ExportMeshesRequest = new ExportMeshesRequest { ChordTol = ChordTol } }; RepeatedField <string> requestIds = requestWrapper.ExportMeshesRequest.ElementIds; for (int i = 0; i < count; ++i) { requestIds.Add(_elementIdExportQueue[i + _elementIdExportQueuePosition]); } } _elementIdExportQueuePosition += count; _backend.SendRequest(requestWrapper, msgWrapper => { _meshReader.QueueForRead(msgWrapper.ExportMeshesReply); }); Profiler.EndSample(); }
public void CalculateOffsetFromProjectExtents() { _backend.SendRequest(new RequestWrapper { ProjectExtentsRequest = new ProjectExtentsRequest() }, replyWrapper => { ProjectExtentsReply msg = replyWrapper.ProjectExtentsReply; // Center the geometry in XY plane for better floating point behavior. _translationFromIModel = new Vector3d { X = -(msg.MinX + (msg.MaxX - msg.MinX) / 2), Y = -(msg.MinY + (msg.MaxY - msg.MinY) / 2), Z = -msg.MinZ }; }); }
public void OnUpdate() { if (_requestIsActive) { return; // Only one request in flight at a time } if (!_forceRequest && Time.time < _nextRequestTime) { return; // Time-based throttling } Vector3 cameraPos = _cameraTransform.position; Vector3 cameraFwd = _cameraTransform.forward; if (!_forceRequest && Vector3.Distance(cameraPos, _lastCameraPos) < MinPositionChange && 1.0f - Vector3.Dot(cameraFwd, _lastCameraFwd) < MinDirectionChange) { return; } Profiler.BeginSample("Bentley.GraphicsStreaming.OnUpdate"); _requestIsActive = true; _forceRequest = false; _lastCameraPos = cameraPos; _lastCameraFwd = cameraFwd; CalculateFrustumAABB(out Vector3 min, out Vector3 max); string selectFilter = CreateSelectFilter(min, max); _backend.SendRequest( new RequestWrapper { SelectElementIdsRequest = new SelectElementIdsRequest { SelectFilter = selectFilter } }, replyWrapper => { _meshRequestManager.AddElementIdsToQueue(replyWrapper.SelectElementIdsReply.ElementIds); _requestIsActive = false; _nextRequestTime = Time.time + MaxRequestFrequency; }); Profiler.EndSample(); }
public Texture2D GetById(string elementId) { Texture2D result; if (_cacheByElementId.TryGetValue(elementId, out result)) { return(result); } result = new Texture2D(1, 1); // stub in until real texture is received _cacheByElementId[elementId] = result; _backend.SendRequest(new RequestWrapper { TextureRequest = new TextureRequest { TextureId = elementId } }, replyWrapper => { result.LoadImage(replyWrapper.TextureReply.TextureData.ToByteArray()); }); return(result); }
public void RequestViewsFromBackend() { _backend.SendRequest(new RequestWrapper { CameraViewsRequest = new CameraViewsRequest() }, HandleCameraViewsReply); }