Search code examples
c#uwp-xamlhelix-3d-toolkit

Helixtoolkit UWP TransformManipulator3D


I'm trying to move/rotate/scale a model using the TransformManipulator3D control in UWP.

I do get it to work but the camera does not stop moving when I'm manipulating the model. So when I try to move/rotate/scale the model the camera also moves and this behavior causes the actual move/scale/rotate to be very wonky and not at all smooth or what is expected.

What am I missing and how can I get this behavior to stop from happening?

Thank you.


Solution

  • I got it working without having to change mouse gestures for the camera.

    I did the following:

    private void viewer_OnMouse3DDown(object sender, MouseDown3DEventArgs e)
        {
            if(e.HitTestResult != null && e.HitTestResult.ModelHit is MeshGeometryModel3D model && GroupModel.Any(x => x == model))
            {
                if(ViewerContext.Selected == model)
                {
                    ViewerContext.Selected.PostEffects = null;
                    ViewerContext.Selected = null;
    
                    return;
                }
    
                if(ViewerContext.Selected != null)
                {
                    ViewerContext.Selected.PostEffects = null;
                }
    
                ViewerContext.Selected = model;
    
                ViewerContext.Selected.PostEffects = string.IsNullOrEmpty(ViewerContext.Selected.PostEffects) ? "border[color:#00FFDE]" : null;
    
                return;
            }
    
            if (e.HitTestResult != null && e.HitTestResult.ModelHit is MeshGeometryModel3D pointer && !GroupModel.Any(x => x == pointer))
            {
                ViewerContext.IsRotationEnabled = false;
                ViewerContext.IsMoveEnabled = false;
                ViewerContext.IsPanEnabled = false;
    
                return;
            }
        }
    

    and

    private void viewer_OnMouse3DUp(object sender, MouseUp3DEventArgs e)
        {
            ViewerContext.IsRotationEnabled = true;
            ViewerContext.IsMoveEnabled = true;
            ViewerContext.IsPanEnabled = true;
        }
    

    The pointer variable checks if the ModelHit is part of the TransformManipulator3D control.

    I followed the UWP sample for the PostEffects.

    The ViewerContext is the ViewModel holding the Viewport3DX properties to know when the camera can again rotate, move or pan.

    The GroupModel holds all the models as MeshGeometryModel3D objects.

    The TransformManipulator3D control binds to the Selected property on ViewerContext which is also of type MeshGeometryModel3D.