Jump to content

Recommended Posts

Posted

This is using json for modern C++. I don't know how to navigate the json data, but at least I can load it:

		nlohmann::json j3;

		int sz = stream->GetSize();
		if (sz <= 4) return false;

		if (stream->ReadString(4) == "glTF")
		{
			if (sz <= 20) return false;
			int version = stream->ReadInt();
			int length = stream->ReadInt();
			int model_length = stream->ReadInt();
			int model_format = stream->ReadInt();
			int binstart = 20 + model_length;
			int binsize = sz - 20 - model_length;

			if (20 + model_length > sz or model_length < 1 or model_format != 0x4E4F534A) return false;
			
			std::vector<uint8_t> data;
			data.resize(model_length);
			Assert(data.size() == model_length);
			stream->Read(&data[0], model_length);
			j3 = nlohmann::json::parse(data);			
		}
		else
		{
			stream->Seek(0);
			std::string contents;
			while (!stream->Ended())
			{
				contents += stream->ReadLine() + "\n";
			}
			j3 = nlohmann::json::parse(contents.c_str());
		}

		//Now interpret json data and build model...
		if (j3.type() != nlohmann::json::value_t::object)
		{
			return false;
		}

		//auto obj = j3.value.get_impl_ptr();//????

 

Let's build cool stuff and have fun. :)

Posted

Wonder how long till someone YAMLs or BSONs it for file size?

JSON is great, I work with it everyday, but it's it's a little heavy around the waist since it's notation/markup is a bit excessive.  Being a Ctype struct expression, it moves between languages very easily as well.

Now we should ditch lua and go javascript rite? :P hue

Coding for Christ.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...