-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper_arrow.go
77 lines (65 loc) · 1.61 KB
/
helper_arrow.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
72
73
74
75
76
77
package three
//go:generate go run codegen/object3d_method_generator/main.go -typeName ArrowHelper -typeSlug arrow_helper
import "syscall/js"
type ArrowHelper struct {
// Origin Vector3 `js:"position"`
// Line Line `js:"line"`
// // Quaternion Quaternion `js:"quaternion"`
// Cone Mesh `js:"cone"`
js.Value
}
type ArrowHelperParameters struct {
Dir Vector3
Origin Vector3
Length float64
Color *Color
ArrowHeadParameters
}
type ArrowHeadParameters struct {
HeadLength float64
HeadWidth float64
}
func NewArrowHelper(params ArrowHelperParameters) ArrowHelper {
if !params.Dir.Truthy() {
params.Dir = NewVector3(0, 0, 1)
}
if !params.Origin.Truthy() {
params.Origin = NewVector3(0, 0, 0)
}
if params.Length == 0 {
params.Length = 1
}
if params.Color == nil {
params.Color = NewColorHex(0xffff00)
}
if params.HeadLength == 0 {
params.HeadLength = 0.2 * params.Length
}
if params.HeadWidth == 0 {
params.HeadWidth = 0.2 * params.HeadLength
}
return ArrowHelper{
Value: three.Get("ArrowHelper").New(
params.Dir.Value,
params.Origin.Value,
params.Length,
params.Color.Value,
params.HeadLength,
params.HeadWidth,
),
}
}
func (g ArrowHelper) SetColor(color Color) {
g.Value.Call("setColor", color.Value)
}
func (g ArrowHelper) SetLength(length float64, head *ArrowHeadParameters) {
if head == nil {
g.Value.Call("setColor", length)
return
}
g.Value.Call("setColor", length, head.HeadLength, head.HeadWidth)
}
// SetDirection Sets the desired direction. Must be a unit vector.
func (g ArrowHelper) SetDirection(dir Vector3) {
g.Value.Call("setDirection", dir.Value)
}