Transparency |
public class TransparencySorter
The TransparencySorter type exposes the following members.
Name | Description | |
---|---|---|
TransparencySorter(ContainerUIElement3D) | Constructor with rootVisual3DCollection. Sorting mode is set to Simple. | |
TransparencySorter(Model3DGroup) | Constructor with rootModelGroup. Sorting mode is set to Simple. | |
TransparencySorter(ModelVisual3D) | Constructor with rootModelVisual3D. Sorting mode is set to Simple. | |
TransparencySorter(Viewport3D) | Constructor with rootViewport3D. Sorting mode is set to Simple. | |
TransparencySorter(Visual3DCollection) | Constructor with rootVisual3DCollection. Sorting mode is set to Simple. | |
TransparencySorter(Model3DGroup, BaseCamera) | Constructor with rootModelGroup and usedCamera. Sorting mode is set to ByCameraDistance. | |
TransparencySorter(Viewport3D, BaseCamera) | Constructor with rootViewport3D and usedCamera. Sorting mode is set to ByCameraDistance. | |
TransparencySorter(Model3DGroup, BaseCamera, Double) | Constructor with rootModelGroup, usedCamera and cameraAngleChange. Sorting mode is set to ByCameraDistance. | |
TransparencySorter(Viewport3D, BaseCamera, Double) | Constructor with rootViewport3D, usedCamera and cameraAngleChange. Sorting mode is set to ByCameraDistance. |
Name | Description | |
---|---|---|
CacheBounds | Gets or sets a Boolean that specify if the objects bounds can be cached. | |
CameraAngleChange | Gets or sets an angle in degrees that specify for how many degrees the camera can change before next automatic sorting is performed. | |
SortingMode | Gets or sets type of the transparency sorting. | |
TransparentModels | Gets root group of transparent models. | |
UsedCamera | Gets or sets a Camera that is used to make the sorting by camera distance. |
Name | Description | |
---|---|---|
AddTransparentModels(Model3D) | AddTransparentModels specifies that the models in the parameters should be treated as transparent models. This method must be called before the Sort method is called. If this method is called after Sort method, then a RecollectTransparentModels must be called for the models to be considered transparent. | |
AddTransparentModels(Visual3D) | AddTransparentModels specifies that the Visual3D objects in the parameters should be treated as transparent models. This method must be called before the Sort method is called. If this method is called after Sort method, then a RecollectTransparentModels must be called for the Visual3D objects to be considered transparent. | |
CalculateSortedValue | CalculateSortedValue returns the sorted value for transparentModel3D and sortingType that will be used to set the model's order. The method can be overridden to provide custom objects ordering. | |
ClearTransparentModels | Clears the Model3D or Visual3D objects that were added with AddTransparentModels method. | |
IsRearangeNeeded(FreeCamera) | Returns true is the camera has changed enough to perform automatic sorting. | |
IsRearangeNeeded(SphericalCamera) | Returns true is the camera has changed enough to perform automatic sorting. | |
RecollectTransparentModels | Refreshes the list of current transparent models (used in case when the opacity of some already collected models is changed). | |
RecollectTransparentModels(Model3DGroup) | Refreshes the collection of transparent objects. | |
RecollectTransparentModels(ModelVisual3D) | Refreshes the collection of transparent objects. | |
RecollectTransparentModels(Viewport3D) | Refreshes the collection of transparent objects. | |
RecollectTransparentModels(Visual3DCollection) | Refreshes the collection of transparent objects. | |
SimpleSort(ContainerUIElement3D) | Sorts objects in containerUIElement3D with moving transparent objects to the back of the objects collection. | |
SimpleSort(Model3DGroup) | Sorts objects in Model3DGroup with moving transparent objects to the back of the objects collection. | |
SimpleSort(ModelVisual3D) | Sorts objects in ModelVisual3D with moving transparent objects to the back of the objects collection. | |
SimpleSort(Viewport3D) | Sorts objects in Viewport3D with moving transparent objects to the back of the objects collection. | |
SimpleSort(Visual3DCollection) | Sorts objects in Visual3DCollection with moving transparent objects to the back of the objects collection. | |
Sort | Sort the objects. | |
Sort(TransparencySorterSortingModeTypes) | Sort the objects with the sortingType. | |
SortByCameraDistance(ContainerUIElement3D, Point3D) | Sorts objects in Visual3DCollection with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
SortByCameraDistance(Model3DGroup, BaseCamera) | Sorts objects in Model3DGroup with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
SortByCameraDistance(Model3DGroup, Point3D) | Sorts objects in Model3DGroup with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
SortByCameraDistance(ModelVisual3D, BaseCamera) | Sorts objects in ModelVisual3D with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
SortByCameraDistance(ModelVisual3D, Point3D) | Sorts objects in ModelVisual3D with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
SortByCameraDistance(Viewport3D, BaseCamera) | Sorts objects in Viewport3D with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
SortByCameraDistance(Viewport3D, Point3D) | Sorts objects in Viewport3D with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
SortByCameraDistance(Visual3DCollection, BaseCamera) | Sorts objects in Visual3DCollection with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
SortByCameraDistance(Visual3DCollection, Point3D) | Sorts objects in Visual3DCollection with moving transparent objects to the back of the objects collection. The transparent objects are arranged in that way that the objects that are farther away from the camera are rendered before objects that are closer to the camera. | |
StartSortingOnCameraChanged | StartSortingOnCameraChanged method starts checking the camera changed events and performs automatic sorting when the camera is changed for more than CameraAngleChange. | |
StopSortingOnCameraChanged | Stops automatic sorting on camera changed event. |
Name | Description | |
---|---|---|
SortingCompleted | Notify that the sorting is completed. | |
TransparentModelIndexChanged | Notify that the specific Transparent model has been repositioned. |
Name | Description | |
---|---|---|
ConsiderNonSolidColoredBrushesAsTransparent | When true (by default), then objects with materials that use ImageBrush or VisualBrush are re-arranged so they are rendered before objects with non-transparent SolidColorObject materials. |
WPF 3D can show transparent 3D objects. But to show them correctly, the transparent objects need to be defined after all the objects that are visible through them. This does not mean their position in 3D space but their index in the object's hierarchy (index in the parent's Children collection). The objects that are defined after the transparent objects cannot be seen through the transparent objects.
The following image shows the transparency problem in a simple 3D scene (because the red boxes are defined after the semi-transparent GlassPlane they are not visible throug the GlassPlane. The order of objects is visible in the right):
To solve the problem, the GlassPlane needs to be moved after the non-transparent objects. The following image is showing the correctly rendered scene.
For cases when the number of transparent objects is not big and if the transparent objects are not positioned in 3D space one after another, the simple transparency sorting is usually enough to produce correct rendering in WPF 3D.
But simply moving transparent objects after non-transparent objects is not always enough. For example if transparent object A is visible through transparent object B, than B must be defined after A. The problem in this case occurs when the camera is rotated so that B is visible through A. Now B must be defined before A. To solve this problem correctly, firstly the transparent objects must be moved after non-transparent objects and than transparent objects must be sorted by their distance to the camera. The sorting must be done after the camera is changed.
TransparencySorter class can be used to perform a simple transparency sorting with just moving all transparent objects after non-transparent objects, or to perform a ByCameraDistance transparency sorting where the transparent objects are sorted by their distance to the camera.
The sorting by camera distance can be also automated so the sorting is automatically done when the camera is changed. To improve performance sorting is not done on each camera change, but is done only if the angle of the camera is changed for more than CameraAngleChange. By default the CameraAngleChange is 5. This means that the transparent object will be resorted after the camera has changed for more than 5 degrees.
If it is not known if the scene contains any transparent objects (for example if it created from a external file), it is possible to check for transparent objects with the GetTransparentObjectsCount(Model3DGroup) method. If the objects are read with Ab3d.Reader3ds, it is possible to get the number of transparent objects with TransparentObjectsCount property.
The following line of code is enough to perform a simple transparency sorting:
Ab3d.Utilities.TransparencySorter.SimpleSort(myRootObjectsGroup);
The following line of code is enough to perform a transparency sorting by camera distance (sorting is performed only once):
Ab3d.Utilities.TransparencySorter.SortByCameraDistance(myRootObjectsGroup, myCamera);
Instead of using Ab3d.Camera (for example TargetPositionCamera), it is also possible to use camera's position (Point3D):
Ab3d.Utilities.TransparencySorter.SortByCameraDistance(myRootObjectsGroup, cameraPosition);
To automatically sort the objects when the camera is changed the following code can be used:
TransparencySorter transparencySorter; transparencySorter = new TransparencySorter(myRootObjectsGroup, myCamera); transparencySorter.StartSortingOnCameraChanged(); // transparencySorter.StopSortingOnCameraChanged(); // Stops the sorting on camera changed
When creating an instance of TransparencySorter class, it is possible to monitor the sorting with subscribing to TransparentModelIndexChanged and SortingCompleted events. To implement custom sorting or use custom values to sort the objects, it is possible to derive a custom class from TransparencySorter and override some of the metods that are used to perform the sorting.