-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
translate_attribute.go
58 lines (44 loc) · 1.54 KB
/
translate_attribute.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
package meshops
import (
"github.com/EliCDavis/polyform/modeling"
"github.com/EliCDavis/polyform/nodes"
"github.com/EliCDavis/vector/vector3"
)
type TranslateAttribute3DTransformer struct {
Attribute string
Amount vector3.Float64
}
func (tat TranslateAttribute3DTransformer) attribute() string {
return tat.Attribute
}
func (tat TranslateAttribute3DTransformer) Transform(m modeling.Mesh) (results modeling.Mesh, err error) {
attribute := getAttribute(tat, modeling.PositionAttribute)
if err = RequireV3Attribute(m, attribute); err != nil {
return
}
return TranslateAttribute3D(m, attribute, tat.Amount), nil
}
func TranslateAttribute3D(m modeling.Mesh, attribute string, amount vector3.Float64) modeling.Mesh {
if err := RequireV3Attribute(m, attribute); err != nil {
panic(err)
}
oldData := m.Float3Attribute(attribute)
scaledData := make([]vector3.Float64, oldData.Len())
for i := 0; i < oldData.Len(); i++ {
scaledData[i] = oldData.At(i).Add(amount)
}
return m.SetFloat3Attribute(attribute, scaledData)
}
type TranslateAttribute3DNode = nodes.StructNode[modeling.Mesh, TranslateAttribute3DNodeData]
type TranslateAttribute3DNodeData struct {
Attribute nodes.NodeOutput[string]
Mesh nodes.NodeOutput[modeling.Mesh]
Amount nodes.NodeOutput[vector3.Float64]
}
func (ta3dn TranslateAttribute3DNodeData) Process() (modeling.Mesh, error) {
attr := modeling.PositionAttribute
if ta3dn.Attribute != nil {
attr = ta3dn.Attribute.Value()
}
return TranslateAttribute3D(ta3dn.Mesh.Value(), attr, ta3dn.Amount.Value()), nil
}