Overlay Viewport Black
#1
i have my main viewport setup for displaying models, I am trying to add an Overlay viewport for widgets and the move rotate and scale widgets, i have added the overlay viewport but it displays in black !

What have i missed, i have added a screen shot of what i see, this is VB.NET winforms with Elementhost, just a thought but can the elementhost have 2 viewports ?

Would it be better to have just one viewport and add to that?


Attached Files Thumbnail(s)
   
Kevan Hampson
#2
I have removed the overlay and stuck with a single one, this now leads to another issue, i can attach and see my model mover widget, i can select it but cannot move it.

Is this because of the eventhandler ? is just having one viewport screwing up the mouse ?
Kevan Hampson
#3
ElementHost supports multiple Viewport3D objects. 
To test that you can add the following code to the Form1.cs file that is part of the Ab3d.DXEngine.WinForms.Sample:

Code:
       private Viewport3D _overlayViewport3D;
       private ModelMoverVisual3D _modelMover;
       private Point3D _startMovePosition;
       private DirectionalLight _overlayViewportLight;

       private void AddModelMover3D()
       {
           _targetPositionCamera.StopRotation();


           var boxVisual3D = new Ab3d.Visuals.BoxVisual3D()
           {
               CenterPosition = new Point3D(0, 0, 0),
               Size = new Size3D(80, 80, 80),
               Material = new DiffuseMaterial(System.Windows.Media.Brushes.Yellow)
           };

           _viewport3D.Children.Add(boxVisual3D);

           
           _overlayViewport3D = new Viewport3D();

           var rootOverlayModelVisual3D = new ModelVisual3D();
           _overlayViewport3D.Children.Add(rootOverlayModelVisual3D);

           _modelMover = new ModelMoverVisual3D()
           {
               AxisLength = 100,
               AxisRadius = 10,
               AxisArrowRadius = 3,
               Position = new Point3D(0, 0, 0)
           };

           // Setup event handlers on ModelMoverVisual3D
           _modelMover.ModelMoveStarted += delegate (object o, EventArgs eventArgs)
           {
               _startMovePosition = boxVisual3D.CenterPosition;
               boxVisual3D.Material = new DiffuseMaterial(System.Windows.Media.Brushes.Red);
           };

           _modelMover.ModelMoved += delegate (object o, Ab3d.Common.ModelMovedEventArgs e)
           {
               var newCenterPosition = _startMovePosition + e.MoveVector3D;
               boxVisual3D.CenterPosition = newCenterPosition;

               _modelMover.Position = newCenterPosition;
           };

           _modelMover.ModelMoveEnded += delegate (object sender, EventArgs args)
           {
               boxVisual3D.Material = new DiffuseMaterial(System.Windows.Media.Brushes.Yellow);
           };


           rootOverlayModelVisual3D.Children.Add(_modelMover);


           _overlayViewportLight = new DirectionalLight();
           rootOverlayModelVisual3D.Content = _overlayViewportLight;

           _rootGrid.Children.Add(_overlayViewport3D);


           _targetPositionCamera.CameraChanged += delegate (object s, CameraChangedRoutedEventArgs args)
           {
               _overlayViewport3D.Camera = _viewport3D.Camera;
               _overlayViewportLight.Direction = ((DirectionalLight)_targetPositionCamera.CameraLight).Direction;
           };
       }

The comment the call to the Setup3DObjects method in constructor and call the AddModelMover3D method to the constructor.

I am sorry because this is not in VB.Net, but I hope that you will be able to understand it.

Under the hood both C# and VB.Net are converted into the same IL code so VB.Net is not a problem.
Andrej Benedik
#4
(03-08-2021, 11:48 PM)abenedik Wrote: ElementHost supports multiple Viewport3D objects. 
To test that you can add the following code to the Form1.cs file that is part of the Ab3d.DXEngine.WinForms.Sample:

Code:
       private Viewport3D _overlayViewport3D;
       private ModelMoverVisual3D _modelMover;
       private Point3D _startMovePosition;
       private DirectionalLight _overlayViewportLight;

       private void AddModelMover3D()
       {
           _targetPositionCamera.StopRotation();


           var boxVisual3D = new Ab3d.Visuals.BoxVisual3D()
           {
               CenterPosition = new Point3D(0, 0, 0),
               Size = new Size3D(80, 80, 80),
               Material = new DiffuseMaterial(System.Windows.Media.Brushes.Yellow)
           };

           _viewport3D.Children.Add(boxVisual3D);

           
           _overlayViewport3D = new Viewport3D();

           var rootOverlayModelVisual3D = new ModelVisual3D();
           _overlayViewport3D.Children.Add(rootOverlayModelVisual3D);

           _modelMover = new ModelMoverVisual3D()
           {
               AxisLength = 100,
               AxisRadius = 10,
               AxisArrowRadius = 3,
               Position = new Point3D(0, 0, 0)
           };

           // Setup event handlers on ModelMoverVisual3D
           _modelMover.ModelMoveStarted += delegate (object o, EventArgs eventArgs)
           {
               _startMovePosition = boxVisual3D.CenterPosition;
               boxVisual3D.Material = new DiffuseMaterial(System.Windows.Media.Brushes.Red);
           };

           _modelMover.ModelMoved += delegate (object o, Ab3d.Common.ModelMovedEventArgs e)
           {
               var newCenterPosition = _startMovePosition + e.MoveVector3D;
               boxVisual3D.CenterPosition = newCenterPosition;

               _modelMover.Position = newCenterPosition;
           };

           _modelMover.ModelMoveEnded += delegate (object sender, EventArgs args)
           {
               boxVisual3D.Material = new DiffuseMaterial(System.Windows.Media.Brushes.Yellow);
           };


           rootOverlayModelVisual3D.Children.Add(_modelMover);


           _overlayViewportLight = new DirectionalLight();
           rootOverlayModelVisual3D.Content = _overlayViewportLight;

           _rootGrid.Children.Add(_overlayViewport3D);


           _targetPositionCamera.CameraChanged += delegate (object s, CameraChangedRoutedEventArgs args)
           {
               _overlayViewport3D.Camera = _viewport3D.Camera;
               _overlayViewportLight.Direction = ((DirectionalLight)_targetPositionCamera.CameraLight).Direction;
           };
       }

The comment the call to the Setup3DObjects method in constructor and call the AddModelMover3D method to the constructor.

I am sorry because this is not in VB.Net, but I hope that you will be able to understand it.

Under the hood both C# and VB.Net are converted into the same IL code so VB.Net is not a problem.

thank you for this, for the time being i am just using 1 viewport makes things easier at the moment.
i did try to also add a skyboxviewport too but that also failed, i will continue setting up my app and see how far i get
Kevan Hampson
  


Forum Jump:


Users browsing this thread:
1 Guest(s)