forked from Lngramos/three
-
Notifications
You must be signed in to change notification settings - Fork 7
/
geometries_buffer_geometry.go
49 lines (40 loc) · 1.67 KB
/
geometries_buffer_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
package three
//go:generate go run geometry_method_generator/main.go -geometryType BufferGeometry -geometrySlug buffer_geometry
import "github.com/gopherjs/gopherjs/js"
// BufferGeometry is an efficient representation of mesh, line, or point geometry. Includes vertex positions, face
// indices, normals, colors, UVs, and custom attributes within buffers, reducing the cost of passing all this
// data to the GPU.
// It's a counterpart of three.js' core/BufferGeometry object.
type BufferGeometry struct {
*js.Object
Vertices []Vector3 `js:"vertices"`
Attributes *BufferAttribute `js:"attributes"`
}
// NewBufferGeometry creates a new Buffer Geometry.
func NewBufferGeometry() *BufferGeometry {
return &BufferGeometry{
Object: three.Get("BufferGeometry").New(),
}
}
// AddVertice adds new vertice to the geometry, specified by its coordinates.
func (bg *BufferGeometry) AddVertice(x, y, z float64) {
vec := NewVector3(x, y, z)
bg.Vertices = append(bg.Vertices, vec)
}
// AddFace adds new Face3 (triangle) to the geometry, specified by its vertice indicies.
func (bg *BufferGeometry) AddFace(a, b, c int) {
face := NewFace3(float64(a), float64(b), float64(c))
bg.Get("faces").Call("push", face)
}
// AddAttribute adds a new attribute like 'position' to the BufferGeometry.
func (bg *BufferGeometry) AddAttribute(name string, attr *BufferAttribute) {
bg.Call("addAttribute", name, attr)
}
// GetAttribute retruns BufferGeometry's attribute by name (should be added first by
// AddAttribute call, see threejs docs for explanations.
func (bg *BufferGeometry) GetAttribute(name string) *BufferAttribute {
obj := bg.Call("getAttribute", name)
return &BufferAttribute{
Object: obj,
}
}