public class SceneCamera : BaseTargetRect3DCamera
Thetype exposes the following members.
Checks if the scene size or position is changed(Overrides BaseTargetRect3DCameraCheckTargetRect3D.)
Forces a refresh of the camera.(Overrides BaseTargetRect3DCameraForceRefresh.)
Updates the PerspectiveCamera(Overrides BaseTargetRect3DCameraUpdateCamera(ProjectionCamera).)
SceneCamera is a camera that looks the whole 3D scene defined by the Viewport3D from the specified angle and distance. SceneCamera is the same as ThirdPersonCamera with its CenterObject set to the whole 3D scene.
If IsDistancePercent is false (by default) the Distance value is used as a distance from the center point of the scene to the camera.
If IsDistancePercent is true, than the Distance value is specified in percent. For example if Distance is 3.0, that means that the distance of the camera from the center of the CenterObject will be 3 times the size of the CenterObject's (diagonal length). This can be very useful when you just want to show the 3D object regardless in which size the object is defined.
Center point is calculated from the Bounds of the whole 3D scene.
When the position or the size of Bounds of the whole 3D scene is changed, the SceneCamera is not automatically updated to affect the changes. To manually update the camera, call the Refresh method. Another possibility is to enable automatic camera updating. This can be done with setting the IsDynamicTarget to true. This will subscribe the camera to CompositionTarget.Rendering event and will constantly monitor the position and size of the CenterObject and move the camera according to the change.
|If you know when the objects on the scene are changed (for example if they are changed manually from the code), it is recommended that the Refresh method is used instead of setting IsDynamicTarget to true. This way the check for the change will be done only after the change and not on every rendering pass (even if there is no change).|
SceneCamera also has some other properties that are common to all cameras that derive from SphericalCamera class.
The ShowCameraLight and the CameraLight properties can be used to add a lights to the Viewport3D that is positioned at the same position as the camera and is looking at the cameras direction.
In the real world this would be a light that is mounted to the camera.
This way the 3D objects that are viewed with the camera are always illuminated regardless of the cameras position.
The ShowCameraLight defines when the camera light is shown. The possible values are:
The CameraLight property is by default a DirectionalLight with White color. The value can be set to a new DirectionalLight with some other color. Other types of Lights are not supported - will not change according to the camera's changed.
Because SphericalCamera is derived from BaseCamera, the SceneCamera also contains properties that are defined in BaseCamera and therefore common to all the cameras:
If the Window, Page or UserControl has only one Viewport3D, there is no need to set and of the above properties on the camera. By default the IsAutoViewport3DFindingEnabled is set to true and that means, that the Viewport3D is automatically find from the current UserControl, Page or Window and it is set to a TargetViewport3D property.
But if there are more Viewport3D objects defined, than by default the first Viewport3D will be used by the camera. With setting the TargetViewport3D or TargetViewport3DName it is possible to specify which Viewport3D will be controlled by the camera.
The following xaml creates a Viewport3D with a few 3D objects and a SceneCamera that is looking at the scene from from left and from above. The Distance is defined as percent. Because there is no light defined in the Viewport3D and the default value of the camera's ShowCameraLight property is true, the cameras adds a light that is illuminating the scene.
<Page x:Class="PowerToysSamples" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys" xmlns:ab3dControls="clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys" xmlns:cameras="clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys"> <Grid> <Viewport3D> <visuals:BoxVisual3D x:Name="MyBoxModel" CenterPosition="30 10 30" Size="20 20 20" Material="Blue"/> <visuals:SphereVisual3D CenterPosition="-30 10 0" Radius="10" Material="Red"/> <visuals:PyramidVisual3D BottomCenterPosition="0 0 30" Size="20 20 20" Material="Green"/> </Viewport3D> <cameras:SceneCamera Heading="30" Attitude="-20" Distance="2" IsDistancePercent="True"/> <ab3dControls:MouseCameraController/> <ab3dControls:CameraControlPanel VerticalAlignment="Bottom" HorizontalAlignment="Left"/> </Grid> </Page>