MCPcopy Create free account
hub / github.com/defold/defold / LoadScene

Function LoadScene

engine/modelc/src/test/test_model.cpp:37–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37static dmModelImporter::Scene* LoadScene(const char* path, dmModelImporter::Options& options)
38{
39 uint32_t file_size = 0;
40 void* mem = dmModelImporter::ReadFile(path, &file_size);
41 if (!mem)
42 return 0;
43
44 const char* suffix = strrchr(path, '.') + 1;
45
46 char dirname[512];
47 dmStrlCpy(dirname, path, sizeof(dirname));
48 char* c = strrchr(dirname, '/');
49 if (!c)
50 c = strrchr(dirname, '\\');
51 if (c)
52 *c = 0;
53
54 dmModelImporter::Scene* scene = dmModelImporter::LoadFromBuffer(&options, suffix, mem, file_size);
55 if (!scene)
56 {
57 dmLogError("Failed to load scene '%s'", path);
58 return 0;
59 }
60
61 if (scene->m_LoadError && scene->m_LoadError[0])
62 {
63 dmLogError("%s", scene->m_LoadError);
64 dmModelImporter::DestroyScene(scene);
65 free(mem);
66 return 0;
67 }
68
69 if (dmModelImporter::NeedsResolve(scene))
70 {
71 for (uint32_t i = 0; i < scene->m_Buffers.Size(); ++i)
72 {
73 if (scene->m_Buffers[i].m_Buffer)
74 continue;
75 if (!scene->m_Buffers[i].m_Uri)
76 continue;
77
78 uint32_t buffermem_size = 0;
79 void* buffermem = BufferResolveUri(dirname, scene->m_Buffers[i].m_Uri, &buffermem_size);
80 dmModelImporter::ResolveBuffer(scene, scene->m_Buffers[i].m_Uri, buffermem, buffermem_size);
81 free(buffermem);
82 }
83
84 bool still_needs_resolve = dmModelImporter::NeedsResolve(scene);
85 if (still_needs_resolve)
86 {
87 dmLogError("There are still unresolved buffers");
88 }
89
90 if (g_AssertMode)
91 {
92 assert(!still_needs_resolve);
93 }
94

Callers 3

TESTFunction · 0.70
TestLoadingFunction · 0.70
TestStandaloneFunction · 0.70

Calls 12

dmStrlCpyFunction · 0.85
DestroySceneFunction · 0.85
freeFunction · 0.85
NeedsResolveFunction · 0.85
ResolveBufferFunction · 0.85
LoadFinalizeFunction · 0.85
ValidateFunction · 0.85
BufferResolveUriFunction · 0.70
ReadFileFunction · 0.50
LoadFromBufferFunction · 0.50
assertFunction · 0.50
SizeMethod · 0.45

Tested by

no test coverage detected