mirror of
https://github.com/minetest/irrlicht.git
synced 2025-02-22 22:00:26 +01:00
Now we're going to very carefully implement b3d
This commit is contained in:
parent
26d5d8f076
commit
80e5da381d
@ -156,31 +156,39 @@ bool parseNode(json data, SMeshBuffer* meshBuffer) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IAnimatedMesh* parseModel(json data) {
|
// Returns success.
|
||||||
|
bool load(json data) {
|
||||||
|
|
||||||
//! Remember: This is basically a linked tree.
|
//! Remember: This is basically a linked tree.
|
||||||
|
|
||||||
SMesh* baseMesh(new SMesh {});
|
// SMesh* baseMesh(new SMesh {});
|
||||||
|
|
||||||
SMeshBuffer* meshBuffer(new SMeshBuffer {});
|
// SMeshBuffer* meshBuffer(new SMeshBuffer {});
|
||||||
|
|
||||||
// And now we begin the recursion!
|
// And now we begin the recursion!
|
||||||
|
|
||||||
std::cout << data["NODE"] << "\n";
|
// std::cout << data["NODE"] << "\n";
|
||||||
|
|
||||||
if (data.contains("NODE") && data["NODE"].is_object()) {
|
// if (data.contains("NODE") && data["NODE"].is_object()) {
|
||||||
println("Yep, that's a node!");
|
// println("Yep, that's a node!");
|
||||||
|
|
||||||
// If it fails, give up basically.
|
// // If it fails, give up basically.
|
||||||
if (parseNode(data["NODE"], meshBuffer)) {
|
// if (parseNode(data["NODE"], meshBuffer)) {
|
||||||
return nullptr;
|
// return nullptr;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
SAnimatedMesh* animatedMesh(new SAnimatedMesh {});
|
// SAnimatedMesh* animatedMesh(new SAnimatedMesh {});
|
||||||
animatedMesh->addMesh(baseMesh);
|
// animatedMesh->addMesh(baseMesh);
|
||||||
|
|
||||||
return animatedMesh;
|
// return animatedMesh;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CB3DJSONMeshFileLoader::cleanUp(std::string failure) {
|
||||||
|
os::Printer::log(failure.c_str(), ELL_WARNING);
|
||||||
|
AnimatedMesh->drop();
|
||||||
|
AnimatedMesh = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) {
|
IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) {
|
||||||
@ -188,18 +196,18 @@ IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) {
|
|||||||
|
|
||||||
// Less than zero? What is this file a black hole?
|
// Less than zero? What is this file a black hole?
|
||||||
if (file->getSize() <= 0) {
|
if (file->getSize() <= 0) {
|
||||||
os::Printer::log("B3D JSON severe error! File size is 0!", ELL_WARNING);
|
this->cleanUp("B3D JSON severe error! File size is 0!");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// So here we turn this mangled disaster into a C string.
|
// So here we turn this mangled disaster into a C string.
|
||||||
// Please consider this the equivalent of duct taping a chainsaw onto a car to cut your lawn.
|
// Please consider this the equivalent of duct taping a chainsaw onto a car to cut your lawn.
|
||||||
// char* buffer = new char[file->getSize()];
|
|
||||||
auto buffer = std::make_unique<char[]>(file->getSize());
|
auto buffer = std::make_unique<char[]>(file->getSize());
|
||||||
|
|
||||||
// Now we read that dang JSON.
|
// Now we read that dang JSON.
|
||||||
file->read(buffer.get(), file->getSize());
|
file->read(buffer.get(), file->getSize());
|
||||||
|
|
||||||
|
// This is the same pointer as buffer, but it's easier to read as "output".
|
||||||
char* output = buffer.get();
|
char* output = buffer.get();
|
||||||
|
|
||||||
// Irrlicht doesn't null terminate the raw output. So we must doe it ourself.
|
// Irrlicht doesn't null terminate the raw output. So we must doe it ourself.
|
||||||
@ -207,7 +215,6 @@ IAnimatedMesh* CB3DJSONMeshFileLoader::createMesh(io::IReadFile* file) {
|
|||||||
|
|
||||||
// We have to catch a JSON parse error or else the game will segfault.
|
// We have to catch a JSON parse error or else the game will segfault.
|
||||||
json data;
|
json data;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = json::parse(output);
|
data = json::parse(output);
|
||||||
} catch (const json::parse_error& e) {
|
} catch (const json::parse_error& e) {
|
||||||
|
@ -16,6 +16,7 @@ class CB3DJSONMeshFileLoader : public IMeshLoader
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CSkinnedMesh* AnimatedMesh;
|
CSkinnedMesh* AnimatedMesh;
|
||||||
|
void cleanUp(std::string);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user