-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPbrMaterial.cs
68 lines (59 loc) · 1.82 KB
/
PbrMaterial.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace RevitGltfExporter
{
[JsonConverter(typeof(StringEnumConverter))]
public enum AlphaMode
{
OPAQUE,
BLEND
}
public class ColorTexture
{
public int index;
public ColorTexture(int index)
{
this.index = index;
}
}
public struct PbrMetallicRoughness
{
public double metallicFactor;
public double roughnessFactor;
public ColorTexture baseColorTexture;
public double[] baseColorFactor;
}
interface IPbrMaterial
{
string name { get; }
bool doubleSided { get; }
AlphaMode alphaMode { get; }
PbrMetallicRoughness pbrMetallicRoughness { get; }
}
partial class RenderingMaterial : IPbrMaterial
{
public string name => null != _name ? _name : _id.ToString();
public bool doubleSided => !backfaceCull;
public AlphaMode alphaMode => transparency < Double.PositiveInfinity ? AlphaMode.OPAQUE : AlphaMode.BLEND;
public PbrMetallicRoughness pbrMetallicRoughness
{
get
{
var ret = new PbrMetallicRoughness();
ret.metallicFactor = isMetal ? 1.0 : 0.0;
ret.roughnessFactor = 1 - glossiness;
if (null != diffuseImageTexture)
{
ret.baseColorTexture = new ColorTexture(Gltf.Instance.indexOfTexture(diffuseImageTexture.path));
}
else
{
var color = diffuseColor != null ? diffuseColor : _color;
ret.baseColorFactor = new double[] { color[0], color[1], color[2], 1 - transparency };
}
return ret;
}
}
}
}