Class Material
A material with red, green, blue, alpha, and metallic factor components.
Examples
var x = 0.0;
var y = 0.0;
var z = 0.0;
var specularFactor = 0.0;
var glossinessFactor = 0.0;
var textData = new List<(Vector3, Vector3, Vector3, string, Color?)>();
var sphere = Mesh.Sphere(0.5, 20);
for (var r = 0.0; r <= 1.0; r += 0.2)
{
for (var g = 0.0; g <= 1.0; g += 0.2)
{
if (r == 0)
{
textData.Add((new Vector3(-1.5, y), Vector3.ZAxis, Vector3.XAxis, $"roughness: {1 - glossinessFactor:f2}", Colors.Black));
}
if (g == 0)
{
textData.Add((new Vector3(x, -1), Vector3.ZAxis, Vector3.XAxis, $"specular: {specularFactor:f2}", Colors.Black));
}
for (var b = 0.0; b <= 1.0; b += 0.2)
{
var color = new Color(r, g, b, 1 - b);
if (r == 1.0 && g == 0.0)
{
textData.Add((new Vector3(x + 1.5, y, z), Vector3.YAxis.Negate(), Vector3.XAxis, $"alpha: {color.Alpha:f2}", Colors.Black));
}
var material = new Material($"{r}_{g}_{b}", color, specularFactor, glossinessFactor);
Model.AddElement(new MeshElement(sphere, new Transform(new Vector3(x, y, z)), material));
z += 2.0;
}
z = 0;
y += 2.0;
glossinessFactor += 0.2;
}
glossinessFactor = 0.0;
y = 0;
x += 2.0;
specularFactor += 0.2;
}
Model.AddElement(new ModelText(textData, FontSize.PT72));
Implements
Inherited Members
Namespace: Elements
Assembly: Hypar.Elements.dll
Syntax
public class Material : Element, INotifyPropertyChanged
Constructors
Material()
Construct a material.
Declaration
public Material()
Material(Color, Double, Double, Boolean, String, Boolean, Boolean, String, Boolean, String, Double, Boolean, Guid, String)
Construct a material.
Declaration
[JsonConstructor]
public Material(Color color, double specularFactor, double glossinessFactor, bool unlit, string texture, bool doubleSided, bool repeatTexture, string normalTexture, bool interpolateTexture, string emissiveTexture, double emissiveFactor, bool drawInFront, Guid id = default(Guid), string name = null)
Parameters
Type | Name | Description |
---|---|---|
Color | color | The color component. |
System.Double | specularFactor | The specular component. |
System.Double | glossinessFactor | The glossiness factor. |
System.Boolean | unlit | Does this material have a constant color? |
System.String | texture | A path to an image texture for texture mapping. |
System.Boolean | doubleSided | Is this material double sided? |
System.Boolean | repeatTexture | Does the texture repeat? |
System.String | normalTexture | A path to an image texture for normal mapping. |
System.Boolean | interpolateTexture | Should the texture be interpolated? |
System.String | emissiveTexture | A path to an emissive image texture. |
System.Double | emissiveFactor | The scale, between 0.0 and 1.0, of the emissive texture's components. |
System.Boolean | drawInFront | Should objects with this material be drawn in front of all other objects? |
System.Guid | id | The id of the material. |
System.String | name | The name of the material. |
Material(String, Color, Double, Double, String, Boolean, Boolean, Boolean, String, Boolean, String, Double, Boolean, Guid)
Construct a material.
Declaration
public Material(string name, Color color, double specularFactor = 0.1, double glossinessFactor = 0.1, string texture = null, bool unlit = false, bool doubleSided = false, bool repeatTexture = true, string normalTexture = null, bool interpolateTexture = true, string emissiveTexture = null, double emissiveFactor = 0, bool drawInFront = false, Guid id = default(Guid))
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The identifier of the material. Identifiers should be unique within a model. |
Color | color | The RGBA color of the material. |
System.Double | specularFactor | The specular component of the color. Between 0.0 and 1.0. |
System.Double | glossinessFactor | The glossiness component of the color. Between 0.0 and 1.0. |
System.String | texture | A relative path to a jpg or png image file to be used as a texture. |
System.Boolean | unlit | Is this material affected by lights? |
System.Boolean | doubleSided | Is this material to be rendered from both sides? |
System.Boolean | repeatTexture | Should the texture be repeated? The RepeatTexture property determines whether textures are clamped in the [0,0]->[1,1] range or repeat continuously. |
System.String | normalTexture | A relative path to a jpg or png image file to be used as a normal texture. |
System.Boolean | interpolateTexture | Should the texture colors be interpolated between pixels? If false, renders hard pixels in the texture rather than fading between adjacent pixels. |
System.String | emissiveTexture | A relative path to a jpg or png image file to be used as en emissive texture. |
System.Double | emissiveFactor | The scale, between 0.0 and 1.0, of the emissive texture's components. |
System.Boolean | drawInFront | Should objects with this material be drawn in front of all other objects? |
System.Guid | id | The id of the material. |
Material(String, Guid)
Construct a material.
Declaration
public Material(string name, Guid id = default(Guid))
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the material. |
System.Guid | id | The id of the material. |
Properties
Color
The material's color.
Declaration
[JsonProperty("Color", Required = Required.Always)]
[Required]
public Color Color { get; set; }
Property Value
Type | Description |
---|---|
Color |
DoubleSided
Is this material to be rendered from both sides?
Declaration
[JsonProperty("DoubleSided", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public bool DoubleSided { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
DrawInFront
Should objects with this material be drawn in front of all other objects?
Declaration
[JsonProperty("Draw In Front", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)]
public bool DrawInFront { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
EdgeDisplaySettings
If provided, this controls how curves and lines will be drawn in the 3D view for supported viewers. This will not affect mesh / solid-based elements.
Declaration
public EdgeDisplaySettings EdgeDisplaySettings { get; set; }
Property Value
Type | Description |
---|---|
EdgeDisplaySettings |
EmissiveFactor
The scale, between 0.0 and 1.0, of the emissive texture's components.
Declaration
[JsonProperty("EmissiveFactor", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)]
public double EmissiveFactor { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
EmissiveTexture
A relative path to a jpg or png image file to be used as an emissive texture.
Declaration
[JsonProperty("EmissiveTexture", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)]
public string EmissiveTexture { get; set; }
Property Value
Type | Description |
---|---|
System.String |
GlossinessFactor
The glossiness factor between 0.0 and 1.0.
Declaration
[JsonProperty("GlossinessFactor", Required = Required.Always)]
[Range(0, 1)]
public double GlossinessFactor { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
InterpolateTexture
Should the texture colors be interpolated between pixels? If false, renders hard pixels in the texture rather than fading between adjacent pixels.
Declaration
[JsonProperty("InterpolateTexture", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public bool InterpolateTexture { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
NormalTexture
A relative path to a jpg or png image file to be used as a normal texture.
Declaration
[JsonProperty("NormalTexture", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)]
public string NormalTexture { get; set; }
Property Value
Type | Description |
---|---|
System.String |
RepeatTexture
Should the texture be repeated? The RepeatTexture property determines whether textures are clamped in the [0,0]->[1,1] range or repeat continuously.
Declaration
[JsonProperty("RepeatTexture", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public bool RepeatTexture { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
SpecularFactor
The specular factor between 0.0 and 1.0.
Declaration
[JsonProperty("SpecularFactor", Required = Required.Always)]
[Range(0, 1)]
public double SpecularFactor { get; set; }
Property Value
Type | Description |
---|---|
System.Double |
Texture
A relative file path to an image file to be used as a texture.
Declaration
[JsonProperty("Texture", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)]
public string Texture { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Unlit
Is this material affected by lights?
Declaration
[JsonProperty("Unlit", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
public bool Unlit { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
Equals(Object)
Is this material equal to the provided material?
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
GetHashCode()
Get the hash code for the material.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 |