8000 use gob file if it exists · raedatoui/learn-opengl-golang@a181d4d · GitHub
[go: up one dir, main page]

Skip to content

Commit a181d4d

Browse files
author
HUGE | Raed Atoui
committed
use gob file if it exists
1 parent f63bf20 commit a181d4d

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

utils/model.go

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func NewModel(b, f string, g bool) (Model, error) {
171171
gobFile := b + gf
172172
if _, err := os.Stat(gobFile); os.IsNotExist(err) {
173173
err := m.loadModel()
174-
//m.Export()
174+
m.Export()
175175
return m, err
176176
}
177177
err := m.Import()
@@ -210,26 +210,12 @@ func (m *Model) Import() error {
210210
defer dataFile.Close()
211211

212212
dataDecoder := gob.NewDecoder(dataFile)
213-
err = dataDecoder.Decode(&m)
214-
215-
if err != nil {
216-
return nil
217-
}
218-
for _, mesh := range m.Meshes {
219-
mesh.setup()
220-
221-
fmt.Printf("vertices: %d, indices: %d, textures: %d\n", len(mesh.Vertices), len(mesh.Indices), len(mesh.Textures))
222-
223-
for _, tex := range mesh.Textures {
224-
if val, ok := m.texturesLoaded[tex.Path]; ok {
225-
fmt.Println( val)
226-
} else {
227-
228-
tex.id = m.textureFromFile(tex.Path)
229-
m.texturesLoaded[tex.Path] = tex
230-
}
231-
}
213+
if err := dataDecoder.Decode(&m); err != nil {
214+
return err
232215
}
216+
217+
fmt.Printf("Creating model from gob file: %s\n", f)
218+
m.initGL()
233219
return nil
234220
}
235221

@@ -257,7 +243,11 @@ func (m *Model) loadModel() error {
257243
// Process ASSIMP's root node recursively
258244
m.processNode(scene.RootNode(), scene)
259245
m.wg.Wait()
246+
m.initGL()
247+
return nil
248+
}
260249

250+
func (m *Model) initGL() {
261251
// using a for loop with a range doesnt work here?!
262252
// also making a temp var inside the loop doesnt work either?!
263253
for i := 0; i < len(m.Meshes); i++ {
@@ -271,9 +261,7 @@ func (m *Model) loadModel() error {
271261
}
272262
m.Meshes[i].setup()
273263
}
274-
return nil
275264
}
276-
277265
func (m *Model) processNode(n *assimp.Node, s *assimp.Scene) {
278266
// Process each mesh located at the current node
279267
m.wg.Add(n.NumMeshes() + n.NumChildren())

0 commit comments

Comments
 (0)
0