MCPcopy Create free account
hub / github.com/DavidColson/Polybox / ImportFile

Function ImportFile

source/asset_importer.cpp:564–613  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

562// ***********************************************************************
563
564int ImportFile(Arena* pScratchArena, u8 format, String source, String output) {
565
566 NormalizePath(source);
567 NormalizePath(output);
568
569 Log::Info("Importing %S", source);
570
571 if (FileExists(source)) {
572 // check we've been given a valid output filename
573 if (output[output.length-1] == '/' || output[output.length-1] == '\\' || TakeAfterLastDot(output) == "") {
574 Log::Warn("Please give a valid filename as an output %S", output);
575 return -1;
576 }
577
578 // Create a lua state, seems a bit odd here I know, but the serialization code is designed to work
579 // on lua tables, and so we're just using the lua state to hold those tables, won't actually run any lua code really
580 lua_State* L = lua_newstate(LuaAllocator, nullptr);
581 BindSerialization(L);
582 BindUserData(L);
583
584 String outputFilepath = TempPrint("system/%S", output);
585
586 // Actually do the import, depending on the file type
587 String extension = TakeAfterLastDot(source);
588 if (extension == "gltf") {
589 if (!ImportGltf(pScratchArena, L, format, source)) {
590 return -1;
591 }
592 }
593 else if (extension == "png") {
594 Log::Warn("TODO: implement png import");
595 return -1;
596 }
597 else {
598 Log::Warn("Unsupported filename give as input: %S", source);
599 return -1;
600 }
601
602 // after import the result table will be left on the stack
603 // so we can write it out now
604 WriteLuaTableToFile(L, format, outputFilepath);
605 lua_pop(L, 1); // pop the asset off the stack
606 }
607 else {
608 Log::Warn("Source input does not exist");
609 return -1;
610 }
611
612 return 0;
613}
614
615};

Callers 2

LoadAppFunction · 0.85
mainFunction · 0.85

Calls 4

BindSerializationFunction · 0.85
BindUserDataFunction · 0.85
ImportGltfFunction · 0.85
WriteLuaTableToFileFunction · 0.85

Tested by

no test coverage detected