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

Function LoadFromPath

engine/modelc/src/modelimporter.cpp:290–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290Scene* LoadFromPath(Options* options, const char* path)
291{
292 const char* suffix = strrchr(path, '.') + 1;
293
294 uint32_t file_size = 0;
295 void* data = ReadFile(path, &file_size);
296 if (!data)
297 {
298 printf("Failed to load '%s'\n", path);
299 return 0;
300 }
301
302 Scene* scene = LoadFromBuffer(options, suffix, data, file_size);
303 if (!scene)
304 {
305 dmLogError("Failed to create scene from path '%s'", path);
306 free(data);
307 return 0;
308 }
309
310 if (scene->m_LoadError && scene->m_LoadError[0])
311 {
312 char errbuf[512];
313 errbuf[0] = 0;
314 dmStrlCpy(errbuf, scene->m_LoadError, sizeof(errbuf));
315 DestroyScene(scene);
316 printf("Failed to load '%s'\n", path);
317 if (errbuf[0])
318 dmLogError("%s", errbuf);
319 free(data);
320 return 0;
321 }
322
323 char dirname[512];
324 dmStrlCpy(dirname, path, sizeof(dirname));
325 char* c = strrchr(dirname, '/');
326 if (!c)
327 c = strrchr(dirname, '\\');
328 if (c)
329 *c = 0;
330
331 if (dmModelImporter::NeedsResolve(scene))
332 {
333 for (uint32_t i = 0; i < scene->m_Buffers.Size(); ++i)
334 {
335 if (scene->m_Buffers[i].m_Buffer)
336 continue;
337
338 uint32_t mem_size = 0;
339 void* mem = BufferResolveUri(dirname, scene->m_Buffers[i].m_Uri, &mem_size);
340 dmModelImporter::ResolveBuffer(scene, scene->m_Buffers[i].m_Uri, mem, mem_size);
341 }
342 }
343
344 if (!dmModelImporter::LoadFinalize(scene))
345 {
346 char errbuf[512];
347 errbuf[0] = 0;

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected