Click or drag to resize
AB4D logo

PixelsVisual3D Class

PixelsVisual3D is a Visual3D that can show many pixels with specified color and size and at the specified 3D positions. The size is specified in screen coordinates.
Inheritance Hierarchy
SystemObject
  System.Windows.ThreadingDispatcherObject
    System.WindowsDependencyObject
      System.Windows.Media.Media3DVisual3D
        System.Windows.Media.Media3DModelVisual3D
          Ab3d.VisualsBaseDXVisual3D
            Ab3d.VisualsSceneNodeVisual3D
              Ab3d.VisualsPixelsVisual3D

Namespace: Ab3d.Visuals
Assembly: Ab3d.DXEngine.Wpf (in Ab3d.DXEngine.Wpf.dll) Version: 7.1.9105.2048
Syntax
C#
public class PixelsVisual3D : SceneNodeVisual3D, 
	IDynamicVertexBufferCreator

The PixelsVisual3D type exposes the following members.

Constructors
 NameDescription
Public methodPixelsVisual3D PixelsVisual3D constructor with no positions and default pixel color (White) and pixel size (1.0f)
Public methodPixelsVisual3D(Vector3) PixelsVisual3D constructor with specified positions and default pixel color (White) and pixel size (1.0f)
Public methodPixelsVisual3D(Vector3, Color, Double) Constructor
Top
Properties
 NameDescription
Public propertyCreateDynamicVertexBuffer Gets or sets a Boolean that specifies if the vertex buffer that is used to sent pixels data to graphics card is created as a dynamic buffer. This can provide slightly better performance for cases when pixels data is updated very often. Default value is false. Setting this value will change the same properties in the used SimpleMesh and PixelMaterial.
Public propertyHasTransparentPixelColors Gets a Boolean that specifies if the PixelColors array contains any transparent color (alpha < 1). This property is used only when PixelColors array is defined. Default value is false.
Public propertyIsCircularPixel When true then each pixel is rendered as circle instead of square. Default value is false.
Public propertyIsWorldSize When true then the PixelSize is specified in 3D world coordinates (when using perspective camera, the size of the pixel is smaller when it is farther away from the camera). When false (by default), then the size is defined in screen coordinates (the size of the pixel is always the same regardless of the distance from the camera).
Public propertyPixelColor Gets or sets the Color4 of pixels. Default value is White. When PixelColors array is set, the value of this property is used as a mask that is multiplied with each color defined in the array.
Public propertyPixelColors Gets or sets the Color4 array that specifies the colors for each pixel. When color's alpha is 0, the pixel is not rendered. When null, the color of all the pixels is set by the color defined by the PixelColor property. When PixelColors array is set, the PixelColor is used as a mask that is multiplied with each color specified in this array. To hide an individual pixel from rendering, set its color in PixelColors to a color with alpha value if zero (you can also set its size in the PixelSizes to 0).
Public propertyPixelSize Gets or sets the width and height of the pixel in screen space units.
Public propertyPixelSizes Gets or sets a float array that specifies the sizes for each pixel. When size is less of equal to 0, the pixel is not rendered. When PixelSizes array is set, the PixelSize value is multiplied with each size defined in the array (set PixelSize to 1 to use the values specified in this array). When null, the size of all the pixels is set by the value defined by the PixelSize property. When individual values of PixelSizes are changed, you need to call UpdatePixelSizes method for the changes to take effect. To hide an individual pixel from rendering, set its size in the PixelSizes to 0 (you can also set its color in PixelColors to a color with alpha value if zero).
Public propertyPositions Gets or sets an array of Vector3 that represents the 3D positions of pixels.
Public propertyPositionsBounds Gets or sets Bounds of the positions. This value can be set before setting the Positions to manually set the Bounds. This prevents automatic bounds calculations with checking all positions.
Top
Methods
 NameDescription
Public methodChangePositionArrays ChangePositionArrays method can be used to change Positions, PixelColors and PixelSizes with one method. This is needed when the number of positions is changed compared to the previous count in the Positions array.
Public methodRemoveTexture Removes the texture that was set by calling SetTexture method.
Public methodResetFixedUpVector Resets the fixed up vector that was set by SetFixedUpVector(Vector3) to default behaviour (pixels always face the camera so that their up vector is perpendicular to the look direction).
Public methodSetFixedUpVector SetFixedUpVector sets a fixed up Vector3 to be always used for up vector when orienting pixel towards the camera. By default, pixels always face the camera so that their up vector is perpendicular to the look direction. But for some cases (for example for rendering trees that always grow upwards), you can fix the up vector. To reset that up vector to default behaviour, call ResetFixedUpVector. Fixed up vector can be used only when IsWorldSize is set to true.
Public methodSetTexture(ShaderResourceView, Size2, SamplerState, BlendState) SetTexture method sets the specified texture to be rendered for each pixel. This value is used when the object does not provide a PixelMaterial. When rendering texture, AlphaClipThreshold is set to 0.5 (pixel with alpha color values below this value will be clipped). To remove the texture, set the pixelTexture to null or call RemoveTexture.
Public methodSetTexture(ShaderResourceView, Size2, Color, SamplerState, BlendState) SetTexture method sets the specified texture to be rendered for each pixel. This value is used when the object does not provide a PixelMaterial. When rendering texture, AlphaClipThreshold is set to 0.5 (pixel with alpha color values below this value will be clipped). To remove the texture, set the pixelTexture to null or call RemoveTexture.
Public methodUpdatePixelColors UpdatePixelColors method updates the DirectX vertex buffer from the current values of PixelColors.
Public methodUpdatePixelSizes UpdatePixelSizes method updates the DirectX vertex buffer from the current values of PixelSize.
Public methodUpdatePositions UpdatePositions updates the DirectX vertex buffer from the existing Positions array. This method must be called when the values defined in the Positions array are changed.
Top
Fields
 NameDescription
Public fieldStatic memberIsCircularPixelProperty IsCircularPixelProperty
Public fieldStatic memberIsWorldSizeProperty IsWorldSizeProperty
Public fieldStatic memberPixelColorProperty PixelSizeProperty
Public fieldStatic memberPixelSizeProperty PixelSizeProperty
Top
Extension Methods
 NameDescription
Public Extension MethodClearDXAttribute Clears the value from DXAttributeType so that IsDXAttributeSet(Visual3D, DXAttributeType) method returns false for that DXAttributeType.
(Defined by Extensions)
Public Extension MethodGetDXAttribute Gets the value of the specified DXAttributeType from the specified Visual3D. If the attributeType does not exists then an exception is thrown. Use GetDXAttributeOrDefaultT(Visual3D, DXAttributeType) or GetDXAttributeOrDefaultT(Visual3D, DXAttributeType, T) to prevent throwing exception when the value is not set.
(Defined by Extensions)
Public Extension MethodGetDXAttributeCollection Gets a DXAttributeCollection will a collection of all DXEngine's attributes set to the specified WPF's object. Returns null when no DXAttributeCollection was attached to the WPF object.
(Defined by Extensions)
Public Extension MethodGetDXAttributeOrDefaultT Gets the value of the specified DXAttributeType from the specified Visual3D. If the attributeType does not exists then a default value for the type T is returned.
(Defined by Extensions)
Public Extension MethodGetDXAttributeOrDefaultT Gets the value of the specified DXAttributeType from the specified Visual3D. If the attributeType does not exists then the specified defaultValue is returned.
(Defined by Extensions)
Public Extension MethodIsDXAttributeSet Returns true if the specified attributeType was set (result is true even if the value is null).
(Defined by Extensions)
Public Extension MethodSetDXAttribute Annotates the specified wpfObject with adding or updating a DXEngine's attribute to it. The attribute is specified with attributeType and its value. This can be used to annotate WPF's objects with DXEngine's attributes.
(Defined by Extensions)
Top
Remarks

PixelsVisual3D is a Visual3D that can show many pixels with specified color and size and at the specified 3D positions.

Positions of the pixels is specified with the Positions array or Vector3 elements. When you change individual positions, you need to call UpdatePositions method for the changes to take effect.

When PixelColors array is set to an array of Color4 elements, then the color of each pixel is defined by the values in the array. In this case PixelColor property defines a color mask (color of each pixel is multiplied with the color specified in the PixelColor property). When using PixelColors array, it is also possible to hide pixels with setting the alpha color value to 0. When PixelColors array is not set (is null), then all pixels are colored with the color specified with the PixelColor property. When colors in the PixelColors array are changed, you need to call UpdatePixelColors method for the changes to take effect.

When some colors in the PixelColors array have transparent colors, the HasTransparentPixelColors property need to be set to true. This will use alpha blending to render the pixels. Note that to correctly render pixels with transparent colors the pixels would need to be sorted so that the pixels that are farther away from the camera are rendered before the pixels that are closer to the camera. Ab3d.DXEngin does not support sorting positions based on camera distance.

When PixelSizes array is set to an array of float values, then the size of each pixel is defined by the values in the array. In this case the PixelSize value is multiplied with each size defined in the PixelSizes array (set PixelSize to 1 to use the values specified in this array). When PixelSizes array is null, the size of all the pixels is set by the value defined by the PixelSize property. When individual values of PixelSizes are changed, you need to call UpdatePixelSizes method for the changes to take effect.

To hide an individual pixel from rendering, set its size in the PixelSizes to 0 or set its color in PixelColors to a color with alpha value if zero.

When PixelColors and / or PixelSizes are set, and if you want to change the number of positions, then you need to call ChangePositionArrays(Vector3, Color4, Single) method to change both Positions and PixelColors and / or PixelSizes.

By default, the size of the pixels is defined in screen coordinates. This means that the size of the pixel is always the same regardless of the distance from the camera. But IsWorldSize is set to true, then the size specified in 3D world coordinates. In this case and when using perspective camera, the size of the pixel is smaller when it is farther away from the camera.

By default, each rendered pixel is rectangular. When IsCircularPixel is set to true, then the pixels are rendered as circles.

To render pixels with textures (billboards), call SetTexture(ShaderResourceView, Size2, Color, SamplerState, BlendState) or SetTexture(ShaderResourceView, Size2, SamplerState, BlendState) methods.

When you know the area in which the pixels are rendered (bounding box of positions), it is recommended to set the PositionsBounds property. This way the bounds will not be calculated by the PixelsVisual3D.

IMPORTANT:
When an instance of PixelsVisual3D is not used anymore, user needs to call Dispose(Boolean) method to free DirectX resources that are created with this class.

See Also