[ad_1]
i try to move multiple object open on Helix viewport 3D. so curtly mutiple object are open succesfuly. but problem in when i try to move any specific model at that time object move mouse opposit position like when i move on Right side at time object is goes to left side same as all axis. so i past here mouse move click event hrer, please provide a solution. Number of query - multiple object open at time i need to select particular object and move it. curntly all model are move in oposite axix. Mouse move time object move opposite direction.
私が試したこと:
Object load Event :
C#
private void loadbtn_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".stl"; dlg.Filter = "STL Files|*.stl;"; Nullable<bool> result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; openfile = filename; // txt1.Text = dlg.FileName; } ModelVisual3D device3D = new ModelVisual3D(); device3D.Content = Display3d(openfile); // viewPort3d.Children.Add(device3D); var reader = new StLReader(); _modelGroup = reader.Read(openfile); var modelVisual = new ModelVisual3D(); modelVisual.Content = _modelGroup; // Apply the TranslateTransform3D to your STL object _modelGroup.Transform = _translate; // Add the ModelVisual3D to the Children property of the HelixViewport3D viewPort3d.Children.Add(modelVisual); }
Mouse Down event is as per below.
C#
private void viewPort3d_MouseDown(object sender, MouseButtonEventArgs e) { //*** MOVE *** var position = e.GetPosition(viewPort3d); var origin = new Point3D(position.X, position.Y, 0); Point originPoint = new Point(origin.X, origin.Y); var transformedOrigin = Viewport3DHelper.UnProject(ConvertToViewport3D(viewPort3d), originPoint); _lastPosition = position; viewPort3d.MouseMove += viewPort3d_MouseMove; viewPort3d.MouseUp += viewPort3d_MouseUp; }
C#
private Viewport3D ConvertToViewport3D(HelixViewport3D helixViewport) { Viewport3D viewport = new Viewport3D(); viewport.Camera = helixViewport.Camera; foreach (var child in helixViewport.Children) { if (child is ModelVisual3D modelVisual) { if (modelVisual.Content is Model3D model) { ModelVisual3D newChild = new ModelVisual3D(); newChild.Content = model; viewport.Children.Add(newChild); } else { // handle other types of modelVisual.Content if necessary } } else { // handle other types of Visual3D objects if necessary } } return viewport; }
Mouse Move event is as per below.
C#
private void viewPort3d_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { System.Windows.Point position = e.GetPosition(this); // this = viewPort3D double pX = position.X; double pY = position.Y; _translate.OffsetX -=pX; _translate.OffsetY += pY; _lastPosition = position; }
Mouse Up event is as per below.
C#
private void viewPort3d_MouseUp(object sender, MouseButtonEventArgs e) { //_isDragging = false; viewPort3d.MouseMove -= viewPort3d_MouseMove; viewPort3d.MouseUp -= viewPort3d_MouseUp; //ReleaseMouseCapture(); }
[ad_2]
コメント