-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPrimitive.cs
65 lines (60 loc) · 1.87 KB
/
Primitive.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
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace RevitGltfExporter
{
public class Primitive
{
[JsonConverter(typeof(StringEnumConverter))]
public enum Attribute
{
POSITION,
NORMAL,
TEXCOORD_0
};
[JsonIgnore]
public readonly int meshId;
private string _indicesId;
private string _positionId;
private string _normalId;
private string _uvId;
public int indices => Gltf.Instance.indexOfAccessor(_indicesId);
private int position => Gltf.Instance.indexOfAccessor(_positionId);
private int normal => Gltf.Instance.indexOfAccessor(_normalId);
public int? material;
private int? uv
{
get
{
if (_uvId != null) return Gltf.Instance.indexOfAccessor(_uvId);
return null;
}
}
public Dictionary<Attribute, int> attributes
{
get
{
Dictionary<Attribute, int> ret = new Dictionary<Attribute, int> { { Attribute.POSITION, position }, { Attribute.NORMAL, normal } };
if (material.HasValue && uv.HasValue)
{
ret.Add(Attribute.TEXCOORD_0, uv.Value);
}
return ret;
}
}
public Primitive(int meshId, string indicesId, string positionId, string normalId, int material = -1, string uvId = null)
{
this.meshId = meshId;
this._indicesId = indicesId;
this._positionId = positionId;
this._normalId = normalId;
if (material == -1)
this.material = null;
else
{
this.material = material;
}
this._uvId = uvId;
}
}
}