forked from oakmound/ofbx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscene.go
107 lines (98 loc) · 2.05 KB
/
scene.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package ofbx
import (
"fmt"
"io"
)
// A Scene is an overarching FBX costruct containing objects and animations
type Scene struct {
RootElement *Element
RootNode *Node
FrameRate float32 // = -1
Settings
ObjectMap map[uint64]Obj
Meshes []*Mesh
AnimationStacks []*AnimationStack
Connections []Connection
TakeInfos []TakeInfo
}
func (s *Scene) String() string {
if s == nil {
return "nil Scene"
}
st := "Scene: " + "\n"
st += "frameRate=" + fmt.Sprintf("%f", s.FrameRate) + "\n"
st += "setttings=" + fmt.Sprintf("%+v", s.Settings) + "\n"
if s.Meshes != nil {
st += "meshes="
for _, mesh := range s.Meshes {
st += "\n"
st += mesh.stringPrefix("\t")
}
st += "\n"
}
if s.AnimationStacks != nil {
st += "animations="
for _, anim := range s.AnimationStacks {
st += "\n"
st += anim.stringPrefix("\t")
}
st += "\n"
}
if len(s.Connections) > 0 {
st += "connections=" + "\n"
for _, c := range s.Connections {
st += "\t" + c.String() + "\n"
}
}
if len(s.TakeInfos) > 0 {
st += "takeInfos=" + "\n"
for _, tk := range s.TakeInfos {
st += "\t" + tk.String()
}
}
return st
}
// Geometries returns a scene's geometries
func (s *Scene) Geometries() []*Geometry {
out := make([]*Geometry, 0)
for _, o := range s.ObjectMap {
elem := o.Element()
if elem == nil {
continue
}
if elem.ID.String() == "Geometry" {
out = append(out, o.(*Geometry))
}
}
return out
}
func (s *Scene) getTakeInfo(name string) *TakeInfo {
for _, info := range s.TakeInfos {
if info.name.String() == name {
return &info
}
}
return nil
}
// Load tries to load a scene
func Load(r io.Reader) (*Scene, error) {
s := &Scene{}
s.ObjectMap = make(map[uint64]Obj)
root, err := tokenize(r)
// Todo: reimplement text
if err != nil {
return nil, err
}
s.RootElement = root
if ok, err := parseConnection(root, s); !ok {
return nil, err
}
if ok, err := parseTakes(s); !ok {
return nil, err
}
if ok, err := parseObjects(root, s); !ok {
return nil, err
}
parseGlobalSettings(root, s)
return s, nil
}