From 7a4a32625cd788ee4326f00f368eeb7f5c544885 Mon Sep 17 00:00:00 2001 From: Daniel Hritzkiv Date: Wed, 9 Aug 2017 10:45:54 -0400 Subject: [PATCH 1/3] Ensure gltf asset version is printed as \d.0 --- code/glTF2Asset.h | 6 +++--- code/glTF2Asset.inl | 13 +++++++------ code/glTF2AssetWriter.inl | 4 ++-- code/glTF2Exporter.cpp | 2 +- code/glTFAsset.h | 4 ++-- code/glTFAsset.inl | 8 ++++---- code/glTFAssetWriter.inl | 4 ++-- code/glTFExporter.cpp | 2 +- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/code/glTF2Asset.h b/code/glTF2Asset.h index bbef4413e..100ed9d58 100644 --- a/code/glTF2Asset.h +++ b/code/glTF2Asset.h @@ -177,7 +177,7 @@ namespace glTF2 struct GLB_Header { uint8_t magic[4]; //!< Magic number: "glTF" - uint32_t version; //!< Version number + float_t version; //!< Version number uint32_t length; //!< Total length of the Binary glTF, including header, scene, and body, in bytes uint32_t sceneLength; //!< Length, in bytes, of the glTF scene uint32_t sceneFormat; //!< Specifies the format of the glTF scene (see the SceneFormat enum) @@ -1074,13 +1074,13 @@ namespace glTF2 std::string version; //!< Specifies the target rendering API (default: "1.0.3") } profile; //!< Specifies the target rendering API and version, e.g., WebGL 1.0.3. (default: {}) - int version; //!< The glTF format version + float version; //!< The glTF format version void Read(Document& doc); AssetMetadata() : premultipliedAlpha(false) - , version(0) + , version(0.) { } }; diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index 33598e243..915e4e11c 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -1229,7 +1229,7 @@ inline void Scene::Read(Value& obj, Asset& r) inline void AssetMetadata::Read(Document& doc) { // read the version, etc. - int statedVersion = 0; + float statedVersion = 0.; if (Value* obj = FindObject(doc, "asset")) { ReadMember(*obj, "copyright", copyright); ReadMember(*obj, "generator", generator); @@ -1244,14 +1244,15 @@ inline void AssetMetadata::Read(Document& doc) } version = std::max(statedVersion, version); - if (version == 0) { - // if missing version, we'll assume version 1... - version = 1; + + if (version == 0.) { + // if missing version, we'll assume version 1.0... + version = 1.; } - if (version != 1) { + if (version != 1.) { char msg[128]; - ai_snprintf(msg, 128, "GLTF: Unsupported glTF version: %d", version); + ai_snprintf(msg, 128, "GLTF: Unsupported glTF version: %.1f", version); throw DeadlyImportError(msg); } } diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index 6e1865bbf..250f425c8 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -574,7 +574,7 @@ namespace glTF2 { GLB_Header header; memcpy(header.magic, AI_GLB_MAGIC_NUMBER, sizeof(header.magic)); - header.version = 2; + header.version = 2.; AI_SWAP4(header.version); header.length = uint32_t(sizeof(header) + sceneLength + bodyLength); @@ -600,7 +600,7 @@ namespace glTF2 { asset.SetObject(); { char versionChar[10]; - ai_snprintf(versionChar, sizeof(versionChar), "%d", mAsset.asset.version); + ai_snprintf(versionChar, sizeof(versionChar), "%.1f", mAsset.asset.version); asset.AddMember("version", Value(versionChar, mAl).Move(), mAl); asset.AddMember("generator", Value(mAsset.asset.generator, mAl).Move(), mAl); diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index b6a2efdd0..8f968f952 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -845,7 +845,7 @@ void glTF2Exporter::ExportScene() void glTF2Exporter::ExportMetadata() { AssetMetadata& asset = mAsset->asset; - asset.version = 2; + asset.version = 2.; char buffer[256]; ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%d)", diff --git a/code/glTFAsset.h b/code/glTFAsset.h index 41d0dfd06..ff9376556 100644 --- a/code/glTFAsset.h +++ b/code/glTFAsset.h @@ -177,7 +177,7 @@ namespace glTF struct GLB_Header { uint8_t magic[4]; //!< Magic number: "glTF" - uint32_t version; //!< Version number (always 1 as of the last update) + float_t version; //!< Version number (always 1 as of the last update) uint32_t length; //!< Total length of the Binary glTF, including header, scene, and body, in bytes uint32_t sceneLength; //!< Length, in bytes, of the glTF scene uint32_t sceneFormat; //!< Specifies the format of the glTF scene (see the SceneFormat enum) @@ -1058,7 +1058,7 @@ namespace glTF std::string version; //!< Specifies the target rendering API (default: "1.0.3") } profile; //!< Specifies the target rendering API and version, e.g., WebGL 1.0.3. (default: {}) - int version; //!< The glTF format version (should be 1) + float version; //!< The glTF format version (should be 1.0) void Read(Document& doc); diff --git a/code/glTFAsset.inl b/code/glTFAsset.inl index fe29dde70..48aeaf855 100644 --- a/code/glTFAsset.inl +++ b/code/glTFAsset.inl @@ -1228,7 +1228,7 @@ inline void Scene::Read(Value& obj, Asset& r) inline void AssetMetadata::Read(Document& doc) { // read the version, etc. - int statedVersion = 0; + float statedVersion = 0.; if (Value* obj = FindObject(doc, "asset")) { ReadMember(*obj, "copyright", copyright); ReadMember(*obj, "generator", generator); @@ -1243,14 +1243,14 @@ inline void AssetMetadata::Read(Document& doc) } version = std::max(statedVersion, version); - if (version == 0) { + if (version == 0.) { // if missing version, we'll assume version 1... version = 1; } - if (version != 1) { + if (version != 1.) { char msg[128]; - ai_snprintf(msg, 128, "GLTF: Unsupported glTF version: %d", version); + ai_snprintf(msg, 128, "GLTF: Unsupported glTF version: %.0f", version); throw DeadlyImportError(msg); } } diff --git a/code/glTFAssetWriter.inl b/code/glTFAssetWriter.inl index d3a553c27..95fc87791 100644 --- a/code/glTFAssetWriter.inl +++ b/code/glTFAssetWriter.inl @@ -582,7 +582,7 @@ namespace glTF { GLB_Header header; memcpy(header.magic, AI_GLB_MAGIC_NUMBER, sizeof(header.magic)); - header.version = 1; + header.version = 1.; AI_SWAP4(header.version); header.length = uint32_t(sizeof(header) + sceneLength + bodyLength); @@ -608,7 +608,7 @@ namespace glTF { asset.SetObject(); { char versionChar[10]; - ai_snprintf(versionChar, sizeof(versionChar), "%d", mAsset.asset.version); + ai_snprintf(versionChar, sizeof(versionChar), "%.0f", mAsset.asset.version); asset.AddMember("version", Value(versionChar, mAl).Move(), mAl); asset.AddMember("generator", Value(mAsset.asset.generator, mAl).Move(), mAl); diff --git a/code/glTFExporter.cpp b/code/glTFExporter.cpp index aeb5069aa..0de843d75 100644 --- a/code/glTFExporter.cpp +++ b/code/glTFExporter.cpp @@ -834,7 +834,7 @@ void glTFExporter::ExportScene() void glTFExporter::ExportMetadata() { glTF::AssetMetadata& asset = mAsset->asset; - asset.version = 1; + asset.version = 1.; char buffer[256]; ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%d)", From 83bfa61f8d213bcf2b860d5bbb18b76834800ff9 Mon Sep 17 00:00:00 2001 From: Daniel Hritzkiv Date: Wed, 9 Aug 2017 11:07:08 -0400 Subject: [PATCH 2/3] version in glb header is stored as uint32_t Validator complains about `1` not being a valid version, however. --- code/glTF2Asset.h | 2 +- code/glTFAsset.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/glTF2Asset.h b/code/glTF2Asset.h index 100ed9d58..416c9e7bc 100644 --- a/code/glTF2Asset.h +++ b/code/glTF2Asset.h @@ -177,7 +177,7 @@ namespace glTF2 struct GLB_Header { uint8_t magic[4]; //!< Magic number: "glTF" - float_t version; //!< Version number + uint32_t version; //!< Version number uint32_t length; //!< Total length of the Binary glTF, including header, scene, and body, in bytes uint32_t sceneLength; //!< Length, in bytes, of the glTF scene uint32_t sceneFormat; //!< Specifies the format of the glTF scene (see the SceneFormat enum) diff --git a/code/glTFAsset.h b/code/glTFAsset.h index ff9376556..30d0bc056 100644 --- a/code/glTFAsset.h +++ b/code/glTFAsset.h @@ -177,7 +177,7 @@ namespace glTF struct GLB_Header { uint8_t magic[4]; //!< Magic number: "glTF" - float_t version; //!< Version number (always 1 as of the last update) + uint32_t version; //!< Version number (always 1 as of the last update) uint32_t length; //!< Total length of the Binary glTF, including header, scene, and body, in bytes uint32_t sceneLength; //!< Length, in bytes, of the glTF scene uint32_t sceneFormat; //!< Specifies the format of the glTF scene (see the SceneFormat enum) From 5b3b80cbc2fa252ebbe6f95c189cada366a2d63f Mon Sep 17 00:00:00 2001 From: Daniel Hritzkiv Date: Wed, 9 Aug 2017 11:36:22 -0400 Subject: [PATCH 3/3] Formatting --- code/glTF2Asset.h | 2 +- code/glTF2Asset.inl | 8 ++++---- code/glTF2AssetWriter.inl | 2 +- code/glTF2Exporter.cpp | 6 +++--- code/glTFAsset.inl | 6 +++--- code/glTFAssetWriter.inl | 2 +- code/glTFExporter.cpp | 6 +++--- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/code/glTF2Asset.h b/code/glTF2Asset.h index 416c9e7bc..52bc18268 100644 --- a/code/glTF2Asset.h +++ b/code/glTF2Asset.h @@ -1080,7 +1080,7 @@ namespace glTF2 AssetMetadata() : premultipliedAlpha(false) - , version(0.) + , version(0) { } }; diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index 915e4e11c..44a1cce00 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -1229,7 +1229,7 @@ inline void Scene::Read(Value& obj, Asset& r) inline void AssetMetadata::Read(Document& doc) { // read the version, etc. - float statedVersion = 0.; + float statedVersion = 0; if (Value* obj = FindObject(doc, "asset")) { ReadMember(*obj, "copyright", copyright); ReadMember(*obj, "generator", generator); @@ -1245,12 +1245,12 @@ inline void AssetMetadata::Read(Document& doc) version = std::max(statedVersion, version); - if (version == 0.) { + if (version == 0) { // if missing version, we'll assume version 1.0... - version = 1.; + version = 1; } - if (version != 1.) { + if (version != 1) { char msg[128]; ai_snprintf(msg, 128, "GLTF: Unsupported glTF version: %.1f", version); throw DeadlyImportError(msg); diff --git a/code/glTF2AssetWriter.inl b/code/glTF2AssetWriter.inl index 250f425c8..ed8ee80ea 100644 --- a/code/glTF2AssetWriter.inl +++ b/code/glTF2AssetWriter.inl @@ -574,7 +574,7 @@ namespace glTF2 { GLB_Header header; memcpy(header.magic, AI_GLB_MAGIC_NUMBER, sizeof(header.magic)); - header.version = 2.; + header.version = 2; AI_SWAP4(header.version); header.length = uint32_t(sizeof(header) + sceneLength + bodyLength); diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 8f968f952..11694a89d 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -466,8 +466,8 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, RefmWeights[idx_weights].mWeight; // A vertex can only have at most four joint weights. Ignore all others. - if (jointsPerVertex[vertexId] > 3) { - continue; + if (jointsPerVertex[vertexId] > 3) { + continue; } vertexJointData[vertexId][jointsPerVertex[vertexId]] = jointNamesIndex; @@ -845,7 +845,7 @@ void glTF2Exporter::ExportScene() void glTF2Exporter::ExportMetadata() { AssetMetadata& asset = mAsset->asset; - asset.version = 2.; + asset.version = 2; char buffer[256]; ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%d)", diff --git a/code/glTFAsset.inl b/code/glTFAsset.inl index 48aeaf855..91d36c59b 100644 --- a/code/glTFAsset.inl +++ b/code/glTFAsset.inl @@ -1228,7 +1228,7 @@ inline void Scene::Read(Value& obj, Asset& r) inline void AssetMetadata::Read(Document& doc) { // read the version, etc. - float statedVersion = 0.; + float statedVersion = 0; if (Value* obj = FindObject(doc, "asset")) { ReadMember(*obj, "copyright", copyright); ReadMember(*obj, "generator", generator); @@ -1243,12 +1243,12 @@ inline void AssetMetadata::Read(Document& doc) } version = std::max(statedVersion, version); - if (version == 0.) { + if (version == 0) { // if missing version, we'll assume version 1... version = 1; } - if (version != 1.) { + if (version != 1) { char msg[128]; ai_snprintf(msg, 128, "GLTF: Unsupported glTF version: %.0f", version); throw DeadlyImportError(msg); diff --git a/code/glTFAssetWriter.inl b/code/glTFAssetWriter.inl index 95fc87791..166b84fd1 100644 --- a/code/glTFAssetWriter.inl +++ b/code/glTFAssetWriter.inl @@ -582,7 +582,7 @@ namespace glTF { GLB_Header header; memcpy(header.magic, AI_GLB_MAGIC_NUMBER, sizeof(header.magic)); - header.version = 1.; + header.version = 1; AI_SWAP4(header.version); header.length = uint32_t(sizeof(header) + sceneLength + bodyLength); diff --git a/code/glTFExporter.cpp b/code/glTFExporter.cpp index 0de843d75..f3fa5e526 100644 --- a/code/glTFExporter.cpp +++ b/code/glTFExporter.cpp @@ -469,8 +469,8 @@ void ExportSkin(Asset& mAsset, const aiMesh* aimesh, Ref& meshRef, RefmWeights[idx_weights].mWeight; // A vertex can only have at most four joint weights. Ignore all others. - if (jointsPerVertex[vertexId] > 3) { - continue; + if (jointsPerVertex[vertexId] > 3) { + continue; } vertexJointData[vertexId][jointsPerVertex[vertexId]] = jointNamesIndex; @@ -834,7 +834,7 @@ void glTFExporter::ExportScene() void glTFExporter::ExportMetadata() { glTF::AssetMetadata& asset = mAsset->asset; - asset.version = 1.; + asset.version = 1; char buffer[256]; ai_snprintf(buffer, 256, "Open Asset Import Library (assimp v%d.%d.%d)",