Page 1 of 1

Sync camera view between two 3d charts

Posted: Fri Oct 13, 2023 10:09 am
by cchrc
Hi there,
I have two 3D charts, and I would like to synchronize their camera views. This means that when I zoom, rotate, or pan in one of them, I want the other chart to update its camera settings accordingly.

To accomplish this, I am utilizing the CameraViewChanged event as follows:

Code: Select all

            chartA.View3D.CameraViewChanged += View3D_CameraViewChanged;
            chartB.View3D.CameraViewChanged += View3D_CameraViewChanged;w

        private void View3D_CameraViewChanged(Camera3D newCameraViewPoint, View3D view, LightningChart chart)
        {
            var otherChart = chart == chartA ? chartB : chartA;
            
             // update only the not focused chart
            if(! otherChart.IsFocused)
            {
                otherChart.View3D.Camera.RotationX = newCameraViewPoint.RotationX;
                otherChart.View3D.Camera.RotationY = newCameraViewPoint.RotationY;
                otherChart.View3D.Camera.RotationZ = newCameraViewPoint.RotationZ;
                otherChart.View3D.Camera.Target = newCameraViewPoint.Target;
                otherChart.View3D.Camera.ViewDistance = newCameraViewPoint.ViewDistance;
            }
        }
It works for rotation and zoom, but not for panning. To update the pan as well, I need to zoom or rotate the chart. Only at that point, the pan information is updated.
Can you please assist me with this issue?
Thank you.

Re: Sync camera view between two 3d charts

Posted: Fri Oct 13, 2023 11:07 am
by ArctionKestutis
About which panning you are asking?
If it is about panning whole 3D-model (by default with right-mouse-button dragging), then such event should raise View3D.CameraViewChanged event. Such panning updates Target property of Camera. That works in latest 10.5.1 version and I am not aware it was ever broken.

If it is not working for you, then let us know the version you are using and whatever you did changes for properties on View3D.ZoomPanOptions tree.

If you talk about Axis panning (like changing Minimum and Maximum by same amount), then you need Axis.RangeChanged event handler.

Hope this helps.

Re: Sync camera view between two 3d charts

Posted: Fri Oct 13, 2023 11:19 am
by cchrc
Hi Kestutis,

Yes, I'm talking about panning the entire 3D model by holding and dragging the right mouse button. You're correct that this action triggers the CameraViewChanged event. However, the position of the 3D chart isn't updated unless I zoom or rotate the chart further.

I'm using LightingChart 10.5.1, which was released on 15/06/23.
Here's how the ZoomAndPanOptions is configured:

ZoomPanOptions = new ZoomPanOptions3D()
{
AxisWheelAction = AxisWheelAction.None,
DeviceTertiaryButtonButtonAction = UserInteractiveDeviceButtonAction3D.None,
AllowWheelZoom = true,
WheelZoomFactor = 1.06
}

Re: Sync camera view between two 3d charts

Posted: Mon Oct 16, 2023 10:45 am
by ArctionKestutis
Overall nothing is wrong with View3D.CameraViewChanged event, as it is raised and report newCameraViewPoint.Target change correctly. Problem that Target property is not set for another Chart.

Solution is to replace line

Code: Select all

                otherChart.View3D.Camera.Target = newCameraViewPoint.Target;
with

Code: Select all

                otherChart.View3D.Camera.Target.SetValues(newCameraViewPoint.Target.X, newCameraViewPoint.Target.Y, newCameraViewPoint.Target.Z);
Most likely reason - a violation of requirement for non-sharing objects.
It is important to remember that LightningChart has requirement of non-sharing object (see User Manual chapter 29.1 Sharing objects between other objects).
That is, Sharing objects between other objects in the same chart, or other chart instances, is not allowed.
Summary: Only copy properties if they are of ValueType (e.g. Integer, Double, Color) not objects (e.g. Fill, Style, Font).
In most cases _chart.ChartMessage event reports errors of invalid object sharing cases and details should tell which object in particular.

In many cases ParentSharingError does not produce noticeable problem. That is the reason, severity for it marked as 'warning'. However, sometimes it could lead to unexpected results (like here) or even crashes. Therefore, those should be always fixed.

Re: Sync camera view between two 3d charts

Posted: Mon Oct 16, 2023 2:51 pm
by cchrc
Thank you Kestutis, your feedback has been very helpful!