-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgeometry.go
71 lines (58 loc) · 1.61 KB
/
geometry.go
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
package three
import "github.com/go-gl/mathgl/mgl32"
// Shape is the interface which defines the shape of a
// 3D object.
type Shape interface {
Vertices() []mgl32.Vec3
UVs() []mgl32.Vec2
Normals() []mgl32.Vec3
Faces() []*Face
ArrayCount() int
}
// Geometry is a base struct with fields for Vertices and UVs.
type Geometry struct {
vertices []mgl32.Vec3
uvs []mgl32.Vec2
normals []mgl32.Vec3
faces []*Face
}
// SetVertices stores the given vertices in an internal field.
func (g *Geometry) SetVertices(vertices []mgl32.Vec3) {
g.vertices = vertices
}
// Vertices returns the vertices for the geometry.
func (g *Geometry) Vertices() []mgl32.Vec3 {
return g.vertices
}
// SetNormals stores the given normals in an internal field.
func (g *Geometry) SetNormals(normals []mgl32.Vec3) {
g.normals = normals
}
// Normals returns the normals for the geometry.
func (g *Geometry) Normals() []mgl32.Vec3 {
return g.normals
}
// SetFaces stores the given faces in an internal field.
func (g *Geometry) SetFaces(faces []*Face) {
g.faces = faces
}
// Faces returns the triangle faces for the geometry.
func (g *Geometry) Faces() []*Face {
return g.faces
}
// SetUVs stores the given uv mappings in an internal field.
func (g *Geometry) SetUVs(uvs []mgl32.Vec2) {
g.uvs = uvs
}
// UVs returns the uv mappings for the geometry.
func (g *Geometry) UVs() []mgl32.Vec2 {
return g.uvs
}
// ArrayCount returns the number of elements to draw in the draw call.
// Faces * 3 if faces are used or number of vertices.
func (g *Geometry) ArrayCount() int {
if len(g.faces) > 0 {
return len(g.faces) * 3
}
return len(g.vertices)
}