03-08-2021, 11:48 PM
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:
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.
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

