-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmesh.go
86 lines (70 loc) · 1.92 KB
/
mesh.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
78
79
80
81
82
83
84
85
86
package ofbx
import (
"fmt"
"github.com/oakmound/oak/v2/alg/floatgeom"
)
// Mesh is a geometry made of polygon
// https://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_class_fbx_mesh_html
type Mesh struct {
Object
Geometry *Geometry
Materials []*Material
}
// NewMesh cretes a new stub Object
func NewMesh(scene *Scene, element *Element) *Mesh {
m := &Mesh{}
m.Object = *NewObject(scene, element)
m.Object.isNode = true
return m
}
// Animations returns the Animation Stacks connected to this mesh
func (m *Mesh) Animations() []*AnimationStack {
anims := m.scene.AnimationStacks
out := []*AnimationStack{}
animatableIds := map[uint64]bool{}
animatableIds[m.ID()] = true
for _, cluster := range m.Geometry.Skin.Clusters {
animatableIds[cluster.Link.ID()] = true
}
ANIMLOOP:
for _, a := range anims {
for _, l := range a.Layers {
fmt.Println("in Layer ", l.id)
for _, c := range l.CurveNodes {
if _, ok := animatableIds[c.Bone.ID()]; ok {
out = append(out, a)
continue ANIMLOOP
}
}
}
}
return out
}
// Type returns MESH
func (m *Mesh) Type() Type {
return MESH
}
func (m *Mesh) getGeometricMatrix() Matrix {
translation := resolveVec3Property(m, "GeometricTranslation", floatgeom.Point3{0, 0, 0})
rotation := resolveVec3Property(m, "GeometricRotation", floatgeom.Point3{0, 0, 0})
scale := resolveVec3Property(m, "GeometricScaling", floatgeom.Point3{1, 1, 1})
scaleMtx := makeIdentity()
scaleMtx.m[0] = scale.X()
scaleMtx.m[5] = scale.Y()
scaleMtx.m[10] = scale.Z()
mtx := EulerXYZ.rotationMatrix(rotation)
setTranslation(translation, &mtx)
return scaleMtx.Mul(mtx)
}
func (m *Mesh) String() string {
return m.stringPrefix("")
}
func (m *Mesh) stringPrefix(prefix string) string {
s := prefix + "Mesh:" + fmt.Sprintf("%v", m.ID()) + "\n"
s += m.Geometry.stringPrefix(prefix + "\t")
for _, mat := range m.Materials {
s += "\n"
s += mat.stringPrefix(prefix + "\t")
}
return s
}