-
Notifications
You must be signed in to change notification settings - Fork 1
/
geometries_buffer_geometry.go
53 lines (44 loc) · 1.81 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
50
51
52
53
package three
//go:generate go run codegen/geometry_method_generator/main.go -typeName BufferGeometry -typeSlug buffer_geometry
import "syscall/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 {
// Vertices []Vector3 `js:"vertices"`
// Attributes *BufferAttribute `js:"attributes"`
js.Value
}
// NewBufferGeometry creates a new Buffer Geometry.
func NewBufferGeometry() BufferGeometry {
return BufferGeometry{
Value: three.Get("BufferGeometry").New(),
}
}
// AddVertex adds new vertex to the geometry, specified by its coordinates.
// func (bg *BufferGeometry) AddVertex(x, y, z float64) {
// vec := NewVector3(x, y, z)
// bg.Vertices = append(bg.Vertices, vec)
// }
// AddVertices adds new vertices to the geometry.
// func (bg *BufferGeometry) AddVertices(v ...Vector3) {
// bg.Vertices = append(bg.Vertices, v...)
// }
// 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) SetAttribute(name string, attr BufferAttribute) {
bg.Call("setAttribute", name, attr.Value)
}
// 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{
Value: obj,
}
}