private void MeshGeometryModel3D_Mouse3DDown(object sender, MouseDown3DEventArgs e) { var normal = e.HitTestResult.NormalAtHit; normal.Normalize(); var upDirection = Vector3.Zero; var lookDirection = -normal; if (Vector3.Cross(normal, view1.ModelUpDirection.ToVector3()).LengthSquared() < 1e-5) { var vecLeft = new Vector3(-normal.Y, -normal.Z, -normal.X); upDirection = vecLeft; } else { upDirection = view1.ModelUpDirection.ToVector3(); } var target = view1.Camera.Position + view1.Camera.LookDirection; var distance = view1.Camera.LookDirection.Length; lookDirection *= (float)distance; var newPosition = target.ToVector3() - lookDirection; view1.Camera.AnimateTo(newPosition.ToPoint3D(), lookDirection.ToVector3D(), upDirection.ToVector3D(), 500); }
private void Sandbox_OnMouseDown(object sender, MouseDown3DEventArgs e) { if (e.OriginalInputEventArgs.Pointer.PointerDeviceType != PointerDeviceType.Mouse) { return; } PointerPointProperties properties = e.OriginalInputEventArgs.GetCurrentPoint(this).Properties; if (properties.IsLeftButtonPressed) { // Left button pressed // Ignore } else if (properties.IsRightButtonPressed) { // Right button pressed if (e.HitTestResult is null) { return; } CallFlyout( targetElement: sender as UIElement, position: e.Position, position3D: e.HitTestResult.PointHit); } }
private void Manipulation_Mouse3DDown(object sender, MouseDown3DEventArgs e) { if (e.HitTestResult.ModelHit == negX) { manipulationType = ManipulationType.PosX; direction = Vector3.UnitX; } else if (e.HitTestResult.ModelHit == negY) { manipulationType = ManipulationType.PosY; direction = Vector3.UnitY; } else if (e.HitTestResult.ModelHit == negZ) { manipulationType = ManipulationType.PosZ; direction = Vector3.UnitZ; } else if (e.HitTestResult.ModelHit == posX) { manipulationType = ManipulationType.SizeX; direction = Vector3.UnitX; } else if (e.HitTestResult.ModelHit == posY) { manipulationType = ManipulationType.SizeY; direction = Vector3.UnitY; } else if (e.HitTestResult.ModelHit == posZ) { manipulationType = ManipulationType.SizeZ; direction = Vector3.UnitZ; } else { manipulationType = ManipulationType.None; isCaptured = false; return; } var material = ((e.HitTestResult.ModelHit as MeshGeometryModel3D).Material as DiffuseMaterial); material.DiffuseColor = Color.Yellow; currentViewport = e.Viewport; var cameraNormal = Vector3.Normalize(e.Viewport.Camera.CameraInternal.LookDirection); this.lastHitPosWS = e.HitTestResult.PointHit; var up = Vector3.Cross(cameraNormal, direction); normal = Vector3.Cross(up, direction); Vector3 hit; if (currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal, out hit)) { currentHit = hit; isCaptured = true; } }
public void OnMouseDown3DHandler(object sender, MouseDown3DEventArgs e) { if (e.HitTestResult != null && e.HitTestResult.ModelHit is MeshGeometryModel3D m && (m.Geometry == Model || m.Geometry == Model2)) { Target = null; Target = e.HitTestResult.ModelHit as Element3D; CenterOffset = m.Geometry.Bound.Center; } }
private void OnMouse3DDown(object sender, MouseDown3DEventArgs e) { if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) || e.HitTestResult.ModelHit is not CustomMeshGeometryModel3D m) { return; } _applicationView.ModelViewer.SelectedModel.SelectedGeometry = m; MaterialsListName.ScrollIntoView(m); }
private void Scaling_Mouse3DDown(object sender, MouseDown3DEventArgs e) { if (target == null || !CanBeginTransform(e)) { return; } if (e.HitTestResult.ModelHit == scaleX) { manipulationType = ManipulationType.ScaleX; direction = Vector3.UnitX; } else if (e.HitTestResult.ModelHit == scaleY) { manipulationType = ManipulationType.ScaleY; direction = Vector3.UnitY; } else if (e.HitTestResult.ModelHit == scaleZ) { manipulationType = ManipulationType.ScaleZ; direction = Vector3.UnitZ; } else { manipulationType = ManipulationType.None; isCaptured = false; return; } HideAllGeometry(); (e.HitTestResult.ModelHit as GeometryModel3D).IsRendering = true; var material = ((e.HitTestResult.ModelHit as MeshGeometryModel3D).Material as DiffuseMaterial); currentColor = material.DiffuseColor; material.DiffuseColor = Color.Yellow; currentViewport = e.Viewport; var cameraNormal = Vector3.Normalize(e.Viewport.Camera.CameraInternal.LookDirection); this.lastHitPosWS = e.HitTestResult.PointHit; var up = Vector3.Cross(cameraNormal, direction); normal = Vector3.Cross(up, direction); Vector3 hit; if (currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal, out hit)) { currentHit = hit; isCaptured = true; } }
/// <summary> /// Get element that is hit on mouse down in 3d viewport. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void onMouseDown3DHandler(object sender, MouseDown3DEventArgs e) { MouseEventArgs mouseArgs = e.OriginalInputEventArgs as MouseEventArgs; // check if the shift key is held down bool shiftDown = false; KeyStates state1 = Keyboard.GetKeyStates(Key.LeftShift); KeyStates state2 = Keyboard.GetKeyStates(Key.RightShift); if ((state1 & KeyStates.Down) > 0 || (state2 & KeyStates.Down) > 0) { shiftDown = true; } // only pay attention if its a LEFT click if (mouseArgs.LeftButton == MouseButtonState.Pressed) { if (e.HitTestResult != null && e.HitTestResult.ModelHit is GeometryModel3D geo) { // if shift is held, add to the selection if (shiftDown) { //selectionCenterOffset = geo.Geometry.Bound.Center; // must update before updating selection selection.Add(geo); updateSelectionProperties(); previewSelectionMaterial(); highlightSelection(); } // else change selection to only what was clicked else { clearSelection(); //selectionCenterOffset = geo.Geometry.Bound.Center; // must update before updating selection selection.Add(geo); updateSelectionProperties(); previewSelectionMaterial(); highlightSelection(); } } // if they clicked nothing else { if (!shiftDown) { clearSelection(); updateSelectionProperties(); } } } }
private void Rotation_Mouse3DDown(object sender, MouseDown3DEventArgs e) { if (target == null || !CanBeginTransform(e)) { return; } if (!(e.HitTestResult.ModelHit is Element3D elem)) { manipulationType = ManipulationType.None; isCaptured = false; return; } if (elem == rotationX) { manipulationType = ManipulationType.RotationX; direction = new Vector3(1, 0, 0); } else if (elem == rotationY) { manipulationType = ManipulationType.RotationY; direction = new Vector3(0, 1, 0); } else if (elem == rotationZ) { manipulationType = ManipulationType.RotationZ; direction = new Vector3(0, 0, 1); } else { manipulationType = ManipulationType.None; isCaptured = false; return; } var material = ((e.HitTestResult.ModelHit as MeshGeometryModel3D).Material as DiffuseMaterial); currentColor = material.DiffuseColor; material.DiffuseColor = Color.Yellow; currentViewport = e.Viewport; normal = Vector3.Normalize(e.Viewport.Camera.CameraInternal.LookDirection); this.lastHitPosWS = e.HitTestResult.PointHit; //var up = Vector3.Cross(cameraNormal, direction); //normal = Vector3.Cross(up, direction); if (currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal, out var hit)) { currentHit = hit; isCaptured = true; } }
private void LineGeometryModel3D_Mouse3DDown(object sender, MouseDown3DEventArgs e) { Debug.WriteLine("Line hitted."); }
protected virtual bool CanBeginTransform(MouseDown3DEventArgs e) { return(true); }
private void Viewport3DX_OnMouse3DDown(object sender, MouseDown3DEventArgs e) { throw new NotImplementedException(); }
private void Element3DPresenter_Mouse3DDown(object sender, MouseDown3DEventArgs e) { SelectedGeometry = e.HitTestResult.Geometry; }
private void Translation_Mouse3DDown(object sender, MouseDown3DEventArgs e) { if (target == null || !CanBeginTransform(e)) { return; } var overrideNormal = false; if (e.HitTestResult.ModelHit == translationX) { manipulationType = ManipulationType.TranslationX; direction = Vector3.UnitX; } else if (e.HitTestResult.ModelHit == translationY) { manipulationType = ManipulationType.TranslationY; direction = Vector3.UnitY; } else if (e.HitTestResult.ModelHit == translationZ) { manipulationType = ManipulationType.TranslationZ; direction = Vector3.UnitZ; } else if (e.HitTestResult.ModelHit == translationXY) { manipulationType = ManipulationType.TranslationXY; direction = Vector3.UnitZ; overrideNormal = true; } else if (e.HitTestResult.ModelHit == translationYZ) { manipulationType = ManipulationType.TranslationYZ; direction = -Vector3.UnitX; overrideNormal = true; } else if (e.HitTestResult.ModelHit == translationXZ) { manipulationType = ManipulationType.TranslationXZ; direction = -Vector3.UnitY; overrideNormal = true; } else { manipulationType = ManipulationType.None; isCaptured = false; return; } if (LocalAxes) { direction = Vector3.TransformNormal(direction, rotationMatrix); } HideAllGeometry(); (e.HitTestResult.ModelHit as GeometryModel3D).IsRendering = true; var material = ((e.HitTestResult.ModelHit as MeshGeometryModel3D).Material as DiffuseMaterial); currentColor = material.DiffuseColor; material.DiffuseColor = Color.Yellow; currentViewport = e.Viewport; if (overrideNormal) { normal = direction; } else { var cameraNormal = Vector3.Normalize(e.Viewport.Camera.CameraInternal.LookDirection); lastHitPosWS = e.HitTestResult.PointHit; var up = Vector3.Cross(cameraNormal, direction); normal = Vector3.Cross(up, direction); } Vector3 hit; if (currentViewport.UnProjectOnPlane(e.Position.ToVector2(), lastHitPosWS, normal, out hit)) { currentHit = hit; isCaptured = true; } }