Class Material
A material contains all the information that describes how to render a mesh. E.g. textures, colors, and render states. Internally all this information is stored as key-value pair properties. The class contains many convienence methods and properties for accessing non-texture/texture properties without having to know the Assimp material key names. Not all properties may be present, and if they aren't a default value will be returned.
Implements
Inherited Members
Namespace: SharpAssimp
Assembly: SharpAssimp.dll
Syntax
public sealed class Material : IMarshalable<Material, AiMaterial>
Constructors
| Edit this page View SourceMaterial()
Constructs a new instance of the Material class.
Declaration
public Material()
Properties
| Edit this page View SourceBlendMode
Gets the blending mode. Default value is Default.
Declaration
public BlendMode BlendMode { get; set; }
Property Value
| Type | Description |
|---|---|
| BlendMode |
BumpScaling
Gets the bump scaling. Default value is 0.0f;
Declaration
public float BumpScaling { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ColorAmbient
Gets the color ambient. Default value is (.2f, .2f, .2f, 1.0f).
Declaration
public Vector4 ColorAmbient { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
ColorDiffuse
Gets the color diffuse. Default value is white.
Declaration
public Vector4 ColorDiffuse { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
ColorEmissive
Gets the color emissive. Default value is black.
Declaration
public Vector4 ColorEmissive { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
ColorReflective
Gets the color reflective. Default value is black.
Declaration
public Vector4 ColorReflective { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
ColorSpecular
Gets the color specular. Default value is black.
Declaration
public Vector4 ColorSpecular { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
ColorTransparent
Gets the color transparent. Default value is black.
Declaration
public Vector4 ColorTransparent { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector4 |
HasBlendMode
Checks if the material has a blend mode property.
Declaration
public bool HasBlendMode { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasBumpScaling
Checks if the material has a bump scaling property.
Declaration
public bool HasBumpScaling { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasColorAmbient
Checks if the material has a color ambient property.
Declaration
public bool HasColorAmbient { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasColorDiffuse
Checks if the material has a color diffuse property.
Declaration
public bool HasColorDiffuse { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasColorEmissive
Checks if the material has a color emissive property.
Declaration
public bool HasColorEmissive { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasColorReflective
Checks if the material has a color reflective property.
Declaration
public bool HasColorReflective { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasColorSpecular
Checks if the material has a color specular property.
Declaration
public bool HasColorSpecular { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasColorTransparent
Checks if the material has a color transparent property.
Declaration
public bool HasColorTransparent { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasName
Checks if the material has a name property.
Declaration
public bool HasName { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasOpacity
Checks if the material has an opacity property.
Declaration
public bool HasOpacity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasReflectivity
Checks if the material has a reflectivty property.
Declaration
public bool HasReflectivity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasShaders
Gets if the material has embedded shader source code.
Declaration
public bool HasShaders { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasShadingMode
Checks if the material has a shading-mode property.
Declaration
public bool HasShadingMode { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasShininess
Checks if the material has a shininess property.
Declaration
public bool HasShininess { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasShininessStrength
Checks if the material has a shininess strength property.
Declaration
public bool HasShininessStrength { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureAmbient
Gets if the material has a ambient texture in the first texture index.
Declaration
public bool HasTextureAmbient { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureAmbientOcclusion
Gets if the material has an ambient occlusion map in in the first texture index.
Declaration
public bool HasTextureAmbientOcclusion { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureDiffuse
Gets if the material has a diffuse texture in the first texture index.
Declaration
public bool HasTextureDiffuse { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureDisplacement
Gets if the material has a displacement texture in the first texture index.
Declaration
public bool HasTextureDisplacement { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureEmissive
Gets if the material has a emissive texture in the first texture index.
Declaration
public bool HasTextureEmissive { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureHeight
Gets if the material has a height texture in the first texture index.
Declaration
public bool HasTextureHeight { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureLightMap
Gets if the material has a light map texture in the first texture index.
Declaration
public bool HasTextureLightMap { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureNormal
Gets if the material has a normal texture in the first texture index.
Declaration
public bool HasTextureNormal { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureOpacity
Gets if the material has an opacity texture in the first texture index.
Declaration
public bool HasTextureOpacity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureReflection
Gets if the material has a reflection texture in the first texture index.
Declaration
public bool HasTextureReflection { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTextureSpecular
Gets if the material has a specular texture in the first texture index.
Declaration
public bool HasTextureSpecular { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTransparencyFactor
Checks if the material has a transparency factor property.
Declaration
public bool HasTransparencyFactor { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasTwoSided
Checks if the material has a two-sided property.
Declaration
public bool HasTwoSided { get; }
Property Value
| Type | Description |
|---|---|
| bool |
HasWireFrame
Checks if the material has a wireframe property.
Declaration
public bool HasWireFrame { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsPBRMaterial
Determines if the material is part of a PBR workflow or not.
Declaration
public bool IsPBRMaterial { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsTwoSided
Gets if the material should be rendered as two-sided. Default value is false.
Declaration
public bool IsTwoSided { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
IsWireFrameEnabled
Gets if wireframe should be enabled. Default value is false.
Declaration
public bool IsWireFrameEnabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Name
Gets the material name value, if any. Default value is an empty string.
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Opacity
Gets the opacity. Default value is 1.0f.
Declaration
public float Opacity { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
PBR
Gets a group accessor for any PBR properties in the material.
Declaration
public Material.PBRMaterialProperties PBR { get; }
Property Value
| Type | Description |
|---|---|
| Material.PBRMaterialProperties |
PropertyCount
Gets the number of properties contained in the material.
Declaration
public int PropertyCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Reflectivity
Gets the reflectivity. Default value is 0.0f;
Declaration
public float Reflectivity { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Shaders
Gets a group accessor for any embedded shader source code in the material.
Declaration
public Material.ShaderMaterialProperties Shaders { get; }
Property Value
| Type | Description |
|---|---|
| Material.ShaderMaterialProperties |
ShadingMode
Gets the shading mode. Default value is None, meaning it is not defined.
Declaration
public ShadingMode ShadingMode { get; set; }
Property Value
| Type | Description |
|---|---|
| ShadingMode |
Shininess
Gets the shininess. Default value is 0.0f;
Declaration
public float Shininess { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
ShininessStrength
Gets the shininess strength. Default vaulue is 1.0f.
Declaration
public float ShininessStrength { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
TextureAmbient
Gets or sets ambient texture properties in the first texture index.
Declaration
public TextureSlot TextureAmbient { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureAmbientOcclusion
Gets or sets ambient occlusion texture properties in the first texture index.
Declaration
public TextureSlot TextureAmbientOcclusion { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureDiffuse
Gets or sets diffuse texture properties in the first texture index.
Declaration
public TextureSlot TextureDiffuse { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureDisplacement
Gets or sets displacement texture properties in the first texture index.
Declaration
public TextureSlot TextureDisplacement { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureEmissive
Gets or sets emissive texture properties in the first texture index.
Declaration
public TextureSlot TextureEmissive { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureHeight
Gets or sets height texture properties in the first texture index.
Declaration
public TextureSlot TextureHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureLightMap
Gets or sets light map texture properties in the first texture index.
Declaration
public TextureSlot TextureLightMap { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureNormal
Gets or sets normal texture properties in the first texture index.
Declaration
public TextureSlot TextureNormal { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureOpacity
Gets or sets opacity texture properties in the first texture index.
Declaration
public TextureSlot TextureOpacity { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureReflection
Gets or sets reflection texture properties in the first texture index.
Declaration
public TextureSlot TextureReflection { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TextureSpecular
Gets or sets specular texture properties in the first texture index.
Declaration
public TextureSlot TextureSpecular { get; set; }
Property Value
| Type | Description |
|---|---|
| TextureSlot |
TransparencyFactor
Gets the transparency factor. This is used to make a surface more or less opaque (0 = opaque, 1 = transparent). Default value is 0.0f.
Declaration
public float TransparencyFactor { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
Methods
| Edit this page View SourceAddMaterialTexture(in TextureSlot)
Adds a texture to the material - this bulk creates a property for each field. This will either create properties or overwrite existing properties. If the texture has no file path, nothing is added.
Declaration
public bool AddMaterialTexture(in TextureSlot texture)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureSlot | texture | Texture to add |
Returns
| Type | Description |
|---|---|
| bool | True if the texture properties were added or modified |
AddMaterialTexture(in TextureSlot, bool)
Adds a texture to the material - this bulk creates a property for each field. This will either create properties or overwrite existing properties. If the texture has no file path, nothing is added.
Declaration
public bool AddMaterialTexture(in TextureSlot texture, bool onlySetFilePath)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureSlot | texture | Texture to add |
| bool | onlySetFilePath | True to only set the texture's file path, false otherwise |
Returns
| Type | Description |
|---|---|
| bool | True if the texture properties were added or modified |
AddProperty(MaterialProperty)
Adds a property to this material.
Declaration
public bool AddProperty(MaterialProperty matProp)
Parameters
| Type | Name | Description |
|---|---|---|
| MaterialProperty | matProp | Material property |
Returns
| Type | Description |
|---|---|
| bool | True if the property was successfully added, false otherwise (e.g. null or key already present). |
Clear()
Removes all properties from the material;
Declaration
public void Clear()
CreateFullyQualifiedName(string, TextureType, int)
Helper method to construct a fully qualified name from the input parameters. All the input parameters are combined into the fully qualified name: {baseName},{texType},{texIndex}. E.g. "$clr.diffuse,0,0" or "$tex.file,1,0". This is the name that is used as the material dictionary key.
Declaration
public static string CreateFullyQualifiedName(string baseName, TextureType texType, int texIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | baseName | Key basename, this must not be null or empty |
| TextureType | texType | Texture type; non-texture properties should leave this None |
| int | texIndex | Texture index; non-texture properties should leave this zero. |
Returns
| Type | Description |
|---|---|
| string | The fully qualified name |
FreeNative(nint, bool)
Frees unmanaged memory created by ToNative(nint, out Native).
Declaration
public static void FreeNative(nint nativeValue, bool freeNative)
Parameters
| Type | Name | Description |
|---|---|---|
| nint | nativeValue | Native value to free |
| bool | freeNative | True if the unmanaged memory should be freed, false otherwise. |
GetAllMaterialTextures()
Gets all textures in the material.
Declaration
public IEnumerable<TextureSlot> GetAllMaterialTextures()
Returns
| Type | Description |
|---|---|
| IEnumerable<TextureSlot> | The array of textures |
GetAllProperties()
Gets -all- properties contained in the Material.
Declaration
public MaterialProperty[] GetAllProperties()
Returns
| Type | Description |
|---|---|
| MaterialProperty[] | All properties in the material property map. |
GetMaterialTexture(TextureType, int, out TextureSlot)
Gets a texture that corresponds to the type/index.
Declaration
public bool GetMaterialTexture(TextureType texType, int texIndex, out TextureSlot texture)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureType | texType | Texture type |
| int | texIndex | Texture index |
| TextureSlot | texture | Texture description |
Returns
| Type | Description |
|---|---|
| bool | True if the texture was found in the material |
GetMaterialTextureCount(TextureType)
Gets all the number of textures that are of the specified texture type.
Declaration
public int GetMaterialTextureCount(TextureType texType)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureType | texType | Texture type |
Returns
| Type | Description |
|---|---|
| int | Texture count |
GetMaterialTextures(TextureType)
Gets all textures that correspond to the type.
Declaration
public TextureSlot[] GetMaterialTextures(TextureType type)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureType | type | Texture type |
Returns
| Type | Description |
|---|---|
| TextureSlot[] | The array of textures |
GetNonTextureProperty(string)
Gets the non-texture properties contained in this Material. The name should be the "base name", as in it should not contain texture type/texture index information. E.g. "$clr.diffuse" rather than "$clr.diffuse,0,0". The extra data will be filled in automatically.
Declaration
public MaterialProperty? GetNonTextureProperty(string baseName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | baseName | Key basename |
Returns
| Type | Description |
|---|---|
| MaterialProperty | The material property, if it exists |
GetProperty(string)
Gets the material property by its fully qualified name. The format is: {baseName},{texType},{texIndex}. E.g. "$clr.diffuse,0,0" or "$tex.file,1,0".
Declaration
public MaterialProperty? GetProperty(string fullyQualifiedName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fullyQualifiedName | Fully qualified name of the property |
Returns
| Type | Description |
|---|---|
| MaterialProperty | The material property, if it exists |
GetProperty(string, TextureType, int)
Gets the material property. All the input parameters are combined into the fully qualified name: {baseName},{texType},{texIndex}. E.g. "$clr.diffuse,0,0" or "$tex.file,1,0".
Declaration
public MaterialProperty? GetProperty(string baseName, TextureType texType, int texIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | baseName | Key basename |
| TextureType | texType | Texture type; non-texture properties should leave this None |
| int | texIndex | Texture index; non-texture properties should leave this zero. |
Returns
| Type | Description |
|---|---|
| MaterialProperty | The material property, if it exists |
HasNonTextureProperty(string)
Checks if the material has the specified non-texture property. The name should be the "base name", as in it should not contain texture type/texture index information. E.g. "$clr.diffuse" rather than "$clr.diffuse,0,0". The extra data will be filled in automatically.
Declaration
public bool HasNonTextureProperty(string baseName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | baseName | Key basename |
Returns
| Type | Description |
|---|---|
| bool | True if the property exists, false otherwise. |
HasProperty(string)
Checks if the material has the specified property by looking up its fully qualified name. The format is: {baseName},{texType},{texIndex}. E.g. "$clr.diffuse,0,0" or "$tex.file,1,0".
Declaration
public bool HasProperty(string fullyQualifiedName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fullyQualifiedName | Fully qualified name of the property |
Returns
| Type | Description |
|---|---|
| bool | True if the property exists, false otherwise. |
HasProperty(string, TextureType, int)
Checks if the material has the specified property. All the input parameters are combined into the fully qualified name: {baseName},{texType},{texIndex}. E.g. "$clr.diffuse,0,0" or "$tex.file,1,0".
Declaration
public bool HasProperty(string baseName, TextureType texType, int texIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | baseName | Key basename |
| TextureType | texType | Texture type; non-texture properties should leave this None |
| int | texIndex | Texture index; non-texture properties should leave this zero. |
Returns
| Type | Description |
|---|---|
| bool | True if the property exists, false otherwise. |
RemoveMaterialTexture(in TextureSlot)
Removes a texture from the material - this bulk removes a property for each field. If the texture has no file path, nothing is removed
Declaration
public bool RemoveMaterialTexture(in TextureSlot texture)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureSlot | texture | Texture to remove |
Returns
| Type | Description |
|---|---|
| bool | True if the texture was removed, false otherwise. |
RemoveNonTextureProperty(string)
Removes a non-texture property from the material.
Declaration
public bool RemoveNonTextureProperty(string baseName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | baseName | Property name |
Returns
| Type | Description |
|---|---|
| bool | True if the property was removed, false otherwise |
RemoveProperty(string)
Removes a property from the material.
Declaration
public bool RemoveProperty(string fullyQualifiedName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | fullyQualifiedName | Fully qualified name of the property ({basename},{texType},{texIndex}) |
Returns
| Type | Description |
|---|---|
| bool | True if the property was removed, false otherwise |
RemoveProperty(string, TextureType, int)
Removes a property from the material.
Declaration
public bool RemoveProperty(string baseName, TextureType texType, int texIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | baseName | Name of the property |
| TextureType | texType | Property texture type |
| int | texIndex | Property texture index |
Returns
| Type | Description |
|---|---|
| bool | True if the property was removed, false otherwise |