-
Notifications
You must be signed in to change notification settings - Fork 18
/
library.go
51 lines (46 loc) · 1.73 KB
/
library.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
package tetra3d
// Library represents a collection of Scenes, Meshes, Animations, etc., as loaded from an intermediary file format (.dae or .gltf / .glb).
type Library struct {
Scenes []*Scene // A slice of Scenes
ExportedScene *Scene // The scene that was open when the library was exported from the modeler
Meshes map[string]*Mesh // A Map of Meshes to their names
Animations map[string]*Animation // A Map of Animations to their names
Materials map[string]*Material // A Map of Materials to their names
Worlds map[string]*World // A Map of Worlds to their names
}
// NewLibrary creates a new Library.
func NewLibrary() *Library {
return &Library{
Scenes: []*Scene{},
Meshes: map[string]*Mesh{},
Animations: map[string]*Animation{},
Materials: map[string]*Material{},
Worlds: map[string]*World{},
}
}
// SceneByName searches all scenes in a Library to find the one with the provided name. If a scene with the given name isn't found,
// SceneByName will return nil.
func (lib *Library) SceneByName(name string) *Scene {
for _, scene := range lib.Scenes {
if scene.Name == name {
return scene
}
}
return nil
}
func (lib *Library) AddScene(sceneName string) *Scene {
newScene := NewScene(sceneName)
newScene.library = lib
lib.Scenes = append(lib.Scenes, newScene)
return newScene
}
// NodeByName allows you to find a node by name by searching through each of a Library's scenes. If the Node with the given name isn't found,
// NodeByName will return nil.
func (lib *Library) NodeByName(objectName string) INode {
for _, scene := range lib.Scenes {
if n := scene.Root.SearchTree().ByName(objectName).First(); n != nil {
return n
}
}
return nil
}