irrlicht/source/Irrlicht/CB3DJSONMeshFileLoader.cpp

80 lines
1.8 KiB
C++
Raw Normal View History

2023-11-26 08:53:55 +01:00
#include "CB3DJSONMeshFileLoader.h"
#include "coreutil.h"
2023-11-26 07:43:26 +01:00
#include "IAnimatedMesh.h"
#include "IReadFile.h"
#include "path.h"
2023-11-26 08:39:42 +01:00
#include "json/json.hpp"
2023-11-26 09:37:35 +01:00
#include "os.h"
using json = nlohmann::json;
2023-11-26 07:48:13 +01:00
namespace irr
{
namespace scene
{
2023-11-26 09:09:50 +01:00
//! Remember to remove this function. It's very dumb.
void println(const char* data) {
2023-11-26 09:37:35 +01:00
printf(data);
printf("\n");
2023-11-26 09:09:50 +01:00
}
const char * const boolToString(bool b)
{
return b ? "true" : "false";
}
2023-11-26 09:09:50 +01:00
2023-11-26 08:53:55 +01:00
// Class methods.
2023-11-26 08:03:32 +01:00
CB3DJSONMeshFileLoader::CB3DJSONMeshFileLoader()
{
2023-11-26 08:53:55 +01:00
2023-11-26 08:03:32 +01:00
}
2023-11-26 07:48:13 +01:00
2023-11-26 08:03:32 +01:00
bool CB3DJSONMeshFileLoader::isALoadableFileExtension(
const io::path& fileName) const
{
2023-11-26 08:53:55 +01:00
//* we could do multiple accepted extensions, like b3dj jb3d, j3d, etc. Talk with core devs about this.
2023-11-26 09:21:28 +01:00
//? For now, just JSON because it has vscode linting.
return core::hasFileExtension(fileName, "json");
2023-11-26 08:03:32 +01:00
}
2023-11-26 07:48:13 +01:00
2023-11-26 08:53:55 +01:00
IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) {
2023-11-26 09:09:50 +01:00
// Less than zero? What is this file a black hole?
if (file->getSize() <= 0) {
2023-11-26 09:37:35 +01:00
os::Printer::log("B3D JSON severe error! File size is 0!", ELL_WARNING);
2023-11-26 09:09:50 +01:00
return nullptr;
}
2023-11-26 09:37:35 +01:00
println("I am loading your cool file, yay");
printf("the file is called: ");
println(file->getFileName().c_str());
// So here we turn this mangled disaster into a C string.
// These two hold error message pointers, basically.
// std::string err {};
// std::string warn {};
2023-11-26 09:37:35 +01:00
// Try changing the type from auto to see why it's auto.
auto buffer = std::make_unique<char[]>(file->getSize());
// Now we read that dang JSON.
file->read(buffer.get(), file->getSize());
const json data = json::parse("{\"hi\": 1}");
const auto test = data["hi"];
printf("is this a number? ");
println(boolToString(test.is_number()));
println(test.dump().c_str());
2023-11-26 09:37:35 +01:00
2023-11-26 08:53:55 +01:00
//! I'm sure this isn't a horrible idea!
return nullptr;
}
2023-11-26 07:48:13 +01:00
} // namespace scene
} // namespace irr