Click or drag to resize
AB4D logo

MaterialTypeConverter Class

MaterialTypeConverter is type converter that can convert simple color name to a DiffuseMaterial with SolidColorBrush or image resource name into a DiffuseMaterial with ImageBrush. It can also create SpecualMaterial or EmissiveMaterial from simple text.
Inheritance Hierarchy
SystemObject
  System.ComponentModelTypeConverter
    Ab3d.CommonMaterialTypeConverter

Namespace: Ab3d.Common
Assembly: Ab3d.PowerToys (in Ab3d.PowerToys.dll) Version: 11.2.9104.2045
Syntax
C#
public class MaterialTypeConverter : TypeConverter

The MaterialTypeConverter type exposes the following members.

Constructors
 NameDescription
Public methodMaterialTypeConverterInitializes a new instance of the MaterialTypeConverter class
Top
Methods
 NameDescription
Public methodCanConvertFrom Returns whether this converter can convert an object of the given type to the type of this converter.
(Overrides TypeConverterCanConvertFrom(ITypeDescriptorContext, Type))
Public methodCanConvertTo Returns whether this converter can convert the object to the specified type.
(Overrides TypeConverterCanConvertTo(ITypeDescriptorContext, Type))
Public methodConvertFrom Converts the given value to the type of this converter.
(Overrides TypeConverterConvertFrom(ITypeDescriptorContext, CultureInfo, Object))
Public methodConvertTo Converts the given value object to the specified type, using the arguments.
(Overrides TypeConverterConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type))
Top
Fields
 NameDescription
Public fieldStatic memberImmediatelyLoadTextureFiles ImmediatelyLoadTextureFiles specifies if image files are immediately loaded with using file stream. This prevents locking the file after it was loaded. This is the default value. When false, the file is created with OnDemand CacheOption. This is set as default value when used inside DXEngine - this prevents loading image as WPF Bitmap and allows loading texture directly into DirectX buffer.
Top
Remarks

The new MaterialTypeConverter can be used only on Material and BackMaterial properties on Abd3.Visuals (not on other WPF Visual3D objects - it is not possible to add TypeConverter attribute to existing properties).

The material type converter can be used to create:

example
DiffuseMaterial with SolidColorBrushRed
Blue
#FF5555
DiffuseMaterial with ImageBrush/Resources/PowerToysTexture.png (for Resource and Content build action)
c:\images\PowerToysTexture.png
http://www.mysite.com/images/myImage.jpg
EmissiveMateriale:Yellow
emissive:Yellow
Diffuse + Specular materials:32;Blue (SpecularPower = 32; SpecularBrush = White; DiffuseMaterial = Blue)
specular:64;PowerToysTexture.png (SpecularPower = 64; SpecularBrush = White; DiffuseMaterial = PowerToysTexture.png)

When ImageBrush is created from file, its BitmapImage can be either immediately created or delayed created until it is used. This is controlled with ImmediatelyLoadTextureFiles static field.

The Brush used in SpecularMaterial is always White (used almost always and this keeps the syntax clear).

Emissive material is created with a group with black DiffuseMaterial and EmissiveMaterial with brush defined with used text.

Example

Without MaterialTypeConverter the 3D Box visual can be defined with the following XAML:

XAML
<visuals:BoxVisual3D CenterPosition="0 5 -10" Size="10 10 10">
    <visuals:BoxVisual3D.Material>
        <DiffuseMaterial Brush="LightGreen"/>
    </visuals:BoxVisual3D.Material>
</visuals:BoxVisual3D>

With MaterialTypeConverter the same box can be defined in one XAML line:

XAML
<visuals:BoxVisual3D CenterPosition="0 5 -10" Size="10 10 10" Material="LightGreen"/>

The following example creates a DiffuseMaterial with ImageBrush from a PowerToysTexture.png that is stored under Resources folder (the image Build Action should be set to Resource):

XAML
<visuals:BoxVisual3D CenterPosition="0 5 -10" Size="10 10 10" Material="/Resources/PowerToysTexture.png"/>

The following example creates a DiffuseMaterial with Blue brush and SpecularMaterial with SpecularPower = 64:

XAML
<visuals:BoxVisual3D CenterPosition="0 5 -10" Size="10 10 10" Material="Specular:64;Blue"/>
See Also