forked from lazytiger/unityai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_mesh.go
More file actions
163 lines (131 loc) · 3.19 KB
/
Copy pathdynamic_mesh.go
File metadata and controls
163 lines (131 loc) · 3.19 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package unityai
const kNumVerts = 6
type PolyStatus uint8
const (
kOriginalPolygon PolyStatus = iota
kGeneratedPolygon = 1
)
type Poly struct {
m_Neighbours [kNumVerts]uint16
m_VertexIDs [kNumVerts]uint16
m_VertexCount uint8
m_Status PolyStatus
}
type DataType int32
type Hull []Plane
func (this *Hull) emplace_back_uninitialized() *Plane {
*this = append(*this, Plane{})
return &(*this)[len(*this)-1]
}
type HullContainer []Hull
type Polygon []Vector3f
func (this *Polygon) resize_uninitialized(size int) {
if cap(*this) >= size {
*this = (*this)[:size]
} else {
*this = append(*this, make([]Vector3f, size-len(*this))...)
}
}
func (this *Polygon) emplace_back_uninitialized() *Vector3f {
*this = append(*this, Vector3f{})
return &(*this)[len(*this)-1]
}
func (this *Polygon) push_back(vert Vector3f) {
*this = append(*this, vert)
}
func (this *Polygon) clone() Polygon {
ret := make([]Vector3f, len(*this))
copy(ret, *this)
return ret
}
type PolygonContainer []Polygon
func (this *PolygonContainer) clear() {
*this = (*this)[:0]
}
func (this *PolygonContainer) push_back(tri Polygon) {
*this = append(*this, tri)
}
func (this *PolygonContainer) erase(index int) {
if index == len(*this)-1 {
*this = (*this)[:len(*this)-1]
} else if index == 0 {
*this = (*this)[1:]
} else {
tmp := make([]Polygon, len(*this)-1)
copy(tmp[:index], (*this)[:index])
copy(tmp[index:], (*this)[index+1:])
*this = tmp
}
}
type DetailHull struct {
hull Hull
polysIds []int // Polygon ids to carve
}
type DetailHullContainer []DetailHull
func NewDetailHull() *DetailHull {
return &DetailHull{}
}
type Edge struct {
v1, v2, p1, p2, c1, c2 uint16
}
type EdgeList []Edge
func (this *EdgeList) resize_uninitialized(size int) {
if cap(*this) > size {
*this = (*this)[:size]
} else {
*this = append(*this, make([]Edge, size-len(*this))...)
}
}
type PolyList []Poly
func (l *PolyList) resize_uninitialized(size int) {
if cap(*l) >= size {
*l = (*l)[:size]
} else {
*l = append(*l, make([]Poly, size-len(*l))...)
}
}
func (this *PolyList) erase(index int) {
if index == len(*this)-1 {
*this = (*this)[:len(*this)-1]
} else if index == 0 {
*this = (*this)[1:]
} else {
tmp := make([]Poly, len(*this)-1)
copy(tmp[:index], (*this)[:index])
copy(tmp[index:], (*this)[index+1:])
*this = tmp
}
}
type DynamicMesh struct {
m_Polygons PolyList
m_Vertices []Vector3f
m_Data []DataType
m_Welder *VertexWelder //BucketCount=2048
m_QuantFactor float32
}
func (this *DynamicMesh) PolyCount() int {
return len(this.m_Polygons)
}
func (this *DynamicMesh) VertCount() int {
return len(this.m_Vertices)
}
func (this *DynamicMesh) GetVertex(i int) Vector3f {
return this.m_Vertices[i]
}
func (this *DynamicMesh) SetVertex(i int, v Vector3f) {
this.m_Vertices[i] = v
}
func (this *DynamicMesh) GetPoly(i int) *Poly {
return &this.m_Polygons[i]
}
func (this *DynamicMesh) GetData(i int) *DataType {
return &this.m_Data[i]
}
func NewDynamicMesh(quantFactor float32) *DynamicMesh {
mesh := &DynamicMesh{
m_QuantFactor: quantFactor,
m_Welder: NewVertexWelder(2048, nil, quantFactor),
}
mesh.m_Welder.SetVertexArray(&mesh.m_Vertices)
return mesh
}