MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / LoadFromString

Method LoadFromString

external/tinygltf/tiny_gltf.h:5989–6688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5987} // end of namespace detail
5988
5989bool TinyGLTF::LoadFromString(Model *model, std::string *err, std::string *warn,
5990 const char *json_str,
5991 unsigned int json_str_length,
5992 const std::string &base_dir,
5993 unsigned int check_sections) {
5994 if (json_str_length < 4) {
5995 if (err) {
5996 (*err) = "JSON string too short.\n";
5997 }
5998 return false;
5999 }
6000
6001 detail::JsonDocument v;
6002
6003#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || \
6004 defined(_CPPUNWIND)) && \
6005 !defined(TINYGLTF_NOEXCEPTION)
6006 try {
6007 detail::JsonParse(v, json_str, json_str_length, true);
6008
6009 } catch (const std::exception &e) {
6010 if (err) {
6011 (*err) = e.what();
6012 }
6013 return false;
6014 }
6015#else
6016 {
6017 detail::JsonParse(v, json_str, json_str_length);
6018
6019 if (!detail::IsObject(v)) {
6020 // Assume parsing was failed.
6021 if (err) {
6022 (*err) = "Failed to parse JSON object\n";
6023 }
6024 return false;
6025 }
6026 }
6027#endif
6028
6029 if (!detail::IsObject(v)) {
6030 // root is not an object.
6031 if (err) {
6032 (*err) = "Root element is not a JSON object\n";
6033 }
6034 return false;
6035 }
6036
6037 {
6038 bool version_found = false;
6039 detail::json_const_iterator it;
6040 if (detail::FindMember(v, "asset", it) &&
6041 detail::IsObject(detail::GetValue(it))) {
6042 auto &itObj = detail::GetValue(it);
6043 detail::json_const_iterator version_it;
6044 std::string versionStr;
6045 if (detail::FindMember(itObj, "version", version_it) &&
6046 detail::GetString(detail::GetValue(version_it), versionStr)) {

Callers

nothing calls this directly

Calls 15

JsonParseFunction · 0.85
IsObjectFunction · 0.85
FindMemberFunction · 0.85
GetStringFunction · 0.85
IsArrayFunction · 0.85
ModelClass · 0.85
ParseAssetFunction · 0.85
ForEachInArrayFunction · 0.85
ParseBufferFunction · 0.85
ParseBufferViewFunction · 0.85
ParseAccessorFunction · 0.85
ParseMeshFunction · 0.85

Tested by

no test coverage detected