| 562 | // *********************************************************************** |
| 563 | |
| 564 | int 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 | }; |
no test coverage detected