Merge branch 'master' into master

pull/3487/head
Kim Kulling 2020-11-25 16:57:49 +01:00 committed by GitHub
commit 4590f06756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 10 deletions

View File

@ -641,7 +641,11 @@ void ParseVectorDataArray(std::vector<aiVector3D>& out, const Element& el)
ReadBinaryDataArray(type, count, data, end, buff, el);
ai_assert(data == end);
ai_assert(buff.size() == count * (type == 'd' ? 8 : 4));
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
ai_assert(buff.size() == dataToRead);
if (dataToRead > buff.size()) {
ParseError("Invalid read size (binary)",&el);
}
const uint32_t count3 = count / 3;
out.reserve(count3);
@ -728,7 +732,11 @@ void ParseVectorDataArray(std::vector<aiColor4D>& out, const Element& el)
ReadBinaryDataArray(type, count, data, end, buff, el);
ai_assert(data == end);
ai_assert(buff.size() == count * (type == 'd' ? 8 : 4));
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
ai_assert(buff.size() == dataToRead);
if (dataToRead > buff.size()) {
ParseError("Invalid read size (binary)",&el);
}
const uint32_t count4 = count / 4;
out.reserve(count4);
@ -807,7 +815,11 @@ void ParseVectorDataArray(std::vector<aiVector2D>& out, const Element& el)
ReadBinaryDataArray(type, count, data, end, buff, el);
ai_assert(data == end);
ai_assert(buff.size() == count * (type == 'd' ? 8 : 4));
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
ai_assert(buff.size() == dataToRead);
if (dataToRead > buff.size()) {
ParseError("Invalid read size (binary)",&el);
}
const uint32_t count2 = count / 2;
out.reserve(count2);
@ -879,7 +891,11 @@ void ParseVectorDataArray(std::vector<int>& out, const Element& el)
ReadBinaryDataArray(type, count, data, end, buff, el);
ai_assert(data == end);
ai_assert(buff.size() == count * 4);
uint64_t dataToRead = static_cast<uint64_t>(count) * 4;
ai_assert(buff.size() == dataToRead);
if (dataToRead > buff.size()) {
ParseError("Invalid read size (binary)",&el);
}
out.reserve(count);
@ -937,7 +953,11 @@ void ParseVectorDataArray(std::vector<float>& out, const Element& el)
ReadBinaryDataArray(type, count, data, end, buff, el);
ai_assert(data == end);
ai_assert(buff.size() == count * (type == 'd' ? 8 : 4));
uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4);
ai_assert(buff.size() == dataToRead);
if (dataToRead > buff.size()) {
ParseError("Invalid read size (binary)",&el);
}
if (type == 'd') {
const double* d = reinterpret_cast<const double*>(&buff[0]);
@ -998,7 +1018,11 @@ void ParseVectorDataArray(std::vector<unsigned int>& out, const Element& el)
ReadBinaryDataArray(type, count, data, end, buff, el);
ai_assert(data == end);
ai_assert(buff.size() == count * 4);
uint64_t dataToRead = static_cast<uint64_t>(count) * 4;
ai_assert(buff.size() == dataToRead);
if (dataToRead > buff.size()) {
ParseError("Invalid read size (binary)",&el);
}
out.reserve(count);
@ -1063,7 +1087,11 @@ void ParseVectorDataArray(std::vector<uint64_t>& out, const Element& el)
ReadBinaryDataArray(type, count, data, end, buff, el);
ai_assert(data == end);
ai_assert(buff.size() == count * 8);
uint64_t dataToRead = static_cast<uint64_t>(count) * 8;
ai_assert(buff.size() == dataToRead);
if (dataToRead > buff.size()) {
ParseError("Invalid read size (binary)",&el);
}
out.reserve(count);
@ -1121,7 +1149,11 @@ void ParseVectorDataArray(std::vector<int64_t>& out, const Element& el)
ReadBinaryDataArray(type, count, data, end, buff, el);
ai_assert(data == end);
ai_assert(buff.size() == count * 8);
uint64_t dataToRead = static_cast<uint64_t>(count) * 8;
ai_assert(buff.size() == dataToRead);
if (dataToRead > buff.size()) {
ParseError("Invalid read size (binary)",&el);
}
out.reserve(count);

View File

@ -863,6 +863,7 @@ struct Sampler : public Object {
};
struct Scene : public Object {
std::string name;
std::vector<Ref<Node>> nodes;
Scene() {}

View File

@ -1400,6 +1400,11 @@ inline void Node::Read(Value &obj, Asset &r) {
}
inline void Scene::Read(Value &obj, Asset &r) {
if (Value *scene_name = FindString(obj, "name")) {
if (scene_name->IsString()) {
this->name = scene_name->GetString();
}
}
if (Value *array = FindArray(obj, "nodes")) {
for (unsigned int i = 0; i < array->Size(); ++i) {
if (!(*array)[i].IsUint()) continue;

View File

@ -1400,6 +1400,9 @@ void glTF2Importer::InternReadFile(const std::string &pFile, aiScene *pScene, IO
// read the asset file
glTF2::Asset asset(pIOHandler);
asset.Load(pFile, GetExtension(pFile) == "glb");
if (asset.scene) {
pScene->mName = asset.scene->name;
}
//
// Copy the data out

View File

@ -335,12 +335,15 @@ struct aiScene
/**
* @brief The global metadata assigned to the scene itself.
*
* This data contains global metadata which belongs to the scene like
* unit-conversions, versions, vendors or other model-specific data. This
* This data contains global metadata which belongs to the scene like
* unit-conversions, versions, vendors or other model-specific data. This
* can be used to store format-specific metadata as well.
*/
C_STRUCT aiMetadata* mMetaData;
/** The name of the scene itself.
*/
C_STRUCT aiString mName;
#ifdef __cplusplus