AB4D Forum

Full Version: Translate, rotate and scale
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi i have just purchased DxEngine. i already had powertoys i have created a viewer with powertoys in VB.NET all was working fine, now i have created a dxviewport i can rotate and move the camera/viewport but when i select the modelmover or rotator the widgets appear but i cannot select them, any idea what i have not done?
Code:
Dim MystandardTransform3D = New StandardTransform3D()


       StandardTransform3D.SetStandardTransform3D(ContentVisual, MystandardTransform3D, updateTransform3D:=True)
       Dim MyvisualEventSource3D = New VisualEventSource3D(ContentVisual)
       AddHandler MyvisualEventSource3D.MouseEnter, AddressOf OnAMMouseEnter
       AddHandler MyvisualEventSource3D.MouseLeave, AddressOf OnAMMouseLeave
       AddHandler MyvisualEventSource3D.MouseDown, AddressOf OnAMMouseDown
       AddHandler MyvisualEventSource3D.MouseUp, AddressOf OnAMMouseUp

       _eventManager3D.RegisterEventSource3D(MyvisualEventSource3D)

       _selectedVisual3D = ContentVisual
       _standardTransform3D = StandardTransform3D.GetStandardTransform3D(ContentVisual)
       TXT_ModelInfo.Text = objectInfo

       AssetLoaded = True
ModelMoverVisual3D, ModelScalarVisual3D and ModelRotatorVisual3D internally use UIElement3D objects that can get mouse events. But this is not possible when those objects are rendered by DXEngine - in this case the Viewport3D is not actually visible from the WPF's perspective and therefore the UIElement3D objects do not receive any mouse events.

When you put ModelMoverVisual3D, ModelScalarVisual3D and ModelRotatorVisual3D into an overlay Viewport3D (Viewport3D objects that is rendered on top of DXViewportView - is defined after DXViewportView and take the same space in the window), then you do not need to change anything because the UIElement3D objects will get mouse events because they are rendered by WPF's Viewport3D.

But when ModelMoverVisual3D, ModelScalarVisual3D and ModelRotatorVisual3D are rendered in the same 3D scene as other objects and are therefore rendered by DXEngine, then they will not get any mouse events.

As described in the comments for "Other Ab3d.PowerToys samples / ModelMover inside object" and "Other Ab3d.PowerToys samples / ModelRotatorSample" sample in Ab3d.DXEngine samples project, you need to do the following to add support for those objects in DXEngine (coped text from the comments):

When ModelMoverVisual3D is used inside DXEngine, the mouse events on UIElement3D objects that are used inside ModelMoverVisual3D will not work. Therefore ModelMoverVisual3D also supports using Ab3d.Utilities.EventManager3D that can process mouse events when inside Ab3d.DXEngine.

To make ModelMoverVisual3D work inside DXEngine, the following code changes need to be done:
1) EventManager3D needs to be created and its CustomEventsSourceElement must be set the DXViewportView
   or a parent Border or some other parent element that has Background property set (see line 69)

2) When ModelMoverVisual3D is created, we need to call the SubscribeWithEventManager3D method 
   on the created ModelMoverVisual3D and pass the EventManager3D as a parameter (see line 84)

3) To allow the user to click on arrows that are inside the selected model, we need to exclude the selected
   model from being processed by EventManager3D. This can be done by calling RegisterExcludedVisual3D on EventManager3D (see line 226)

4) Because we called RegisterExcludedVisual3D, we need to call RemoveExcludedVisual3D after the mouse moving is completed (see line 207)


Another option is to create an overlay Viewport3D and move the ModelMoverVisual3D, ModelScalarVisual3D and ModelRotatorVisual3D to it.
Thank you for you quick response, i am an idiot i did not know there were DXEngine samples i was still using powertoy samples,  once i seen the sample i got it working :) going through all the samples now
(04-23-2021, 11:48 AM)GraPhiX Wrote: [ -> ]Thank you for you quick response, i am an idiot i did not know there were DXEngine samples i was still using powertoy samples,  once i seen the sample i got it working :) going through all the samples now

I spoke too soon :(
_modelMover works
_modelRotator works
_modelScaler not working :(

Code:
Public Sub ShowModelMover()

       If MoveAsset = True Then
           HideModelRotator()
           HideModelScalar()
       End If


       If _selectedVisual3D Is Nothing OrElse _standardTransform3D Is Nothing Then Return

       EnsureModelMover()
       '_modelMover.ShowMovablePlanes = False
       _modelMover.Position = _standardTransform3D.GetTranslateVector3D().ToPoint3D
       Dim length As Double = (_modelMover.Position - Camera1.GetCameraPosition).Length
       Dim worldSize As Size = CameraUtils.GetPerspectiveWorldSize(New Size(100, 100), length, Camera1.FieldOfView, New Size(_viewport3D.ActualWidth, _viewport3D.ActualHeight))

       _modelMover.AxisLength = (worldSize.Width + worldSize.Height) '/ 2
       _modelMover.AxisRadius = (_modelMover.AxisLength * 0.02)
       _modelMover.AxisArrowRadius = (_modelMover.AxisRadius * 2)


       If Not _viewport3D.Children.Contains(_modelMover) Then
           _viewport3D.Children.Add(_modelMover)
           _modelMover.SubscribeWithEventManager3D(_eventManager3D)
       End If


   End Sub
Code:
Public Sub ShowModelRotator(sender As Object, e As ModelRotatedEventArgs)
       If RotateAsset = True Then
           HideModelMover()
           HideModelScalar()
       End If


       If _selectedVisual3D Is Nothing OrElse _standardTransform3D Is Nothing Then Return

       EnsureModelRotator(sender, e)
       _modelRotator.Position = _standardTransform3D.GetTranslateVector3D().ToPoint3D
       Dim lookDirectionDistance As Double = (_modelRotator.Position - Camera1.GetCameraPosition()).Length
       Dim worldSize = Ab3d.Utilities.CameraUtils.GetPerspectiveWorldSize(New Size(100, 100), lookDirectionDistance, Camera1.FieldOfView, New Size(_viewport3D.ActualWidth, _viewport3D.ActualHeight))
       _modelRotator.InnerRadius = (worldSize.Width + worldSize.Height) / 2 '* 0.8
       _modelRotator.OuterRadius = _modelRotator.InnerRadius * 1.1
       If Not _viewport3D.Children.Contains(_modelRotator) Then
           _viewport3D.Children.Add(_modelRotator)
           _modelRotator.SubscribeWithEventManager3D(_eventManager3D)
       End If
   End Sub
Code:
Public Sub ShowModelScalar(sender As Object, ARGSS As ModelScaledEventArgs)
       If ScaleAsset = True Then
           HideModelMover()
           HideModelRotator()
       End If

       If _selectedVisual3D Is Nothing OrElse _standardTransform3D Is Nothing Then Return

       EnsureModelScalar(sender, ARGSS)
       _modelScalar.Position = _standardTransform3D.GetTranslateVector3D().ToPoint3D
       Dim length As Double = (_modelScalar.Position - Camera1.GetCameraPosition).Length
       Dim worldsize As Size = CameraUtils.GetPerspectiveWorldSize(New Size(100, 100), length, Camera1.FieldOfView, New Size(_viewport3D.ActualWidth, _viewport3D.ActualHeight))

       _modelScalar.AxisLength = (worldsize.Width + worldsize.Height) '/ 2
       _modelScalar.InnerBoxWidth = _modelScalar.AxisLength * 0.03
       _modelScalar.OuterBoxWidth = _modelScalar.InnerBoxWidth * 3
       _modelScalar.CenterBoxWidth = _modelScalar.InnerBoxWidth * 5

       If Not _viewport3D.Children.Contains(_modelScalar) Then
           _viewport3D.Children.Add(_modelScalar)
           _modelScalar.SubscribeWithEventManager3D(_eventManager3D) 'error on this line
       End If

   End Sub

the error is BC30456 'SubscribeWithEventManager3D' is not a member of 'ModelScalarVisual3D'
looking at Ab3d.Visuals 
Public Class ModelScalarVisual3D

this line is missing 

Public Sub SubscribeWithEventManager3D(eventManager3D As EventManager3D)

is this a bug or am i wrong 
SubscribeWithEventManager3D is missing from the ModelScalarVisual3D. I will update the code and send you a pre-release version with that method.
(04-26-2021, 11:44 AM)abenedik Wrote: [ -> ]SubscribeWithEventManager3D is missing from the ModelScalarVisual3D. I will update the code and send you a pre-release version with that method.

Thank you very much :) installed update and it works perfectly