diff --git a/code/glTFAsset.h b/code/glTFAsset.h index e34b05f5c..f105d6b6c 100644 --- a/code/glTFAsset.h +++ b/code/glTFAsset.h @@ -377,8 +377,8 @@ namespace glTF ComponentType componentType; //!< The datatype of components in the attribute. (required) unsigned int count; //!< The number of attributes referenced by this accessor. (required) AttribType::Value type; //!< Specifies if the attribute is a scalar, vector, or matrix. (required) - //std::vector max; //!< Maximum value of each component in this attribute. - //std::vector min; //!< Minimum value of each component in this attribute. + std::vector max; //!< Maximum value of each component in this attribute. + std::vector min; //!< Minimum value of each component in this attribute. unsigned int GetNumComponents(); unsigned int GetBytesPerComponent(); diff --git a/code/glTFAssetWriter.inl b/code/glTFAssetWriter.inl index 71b47473b..24c6c8c35 100644 --- a/code/glTFAssetWriter.inl +++ b/code/glTFAssetWriter.inl @@ -56,7 +56,16 @@ namespace glTF { inline Value& MakeValue(Value& val, float(&r)[N], MemoryPoolAllocator<>& al) { val.SetArray(); val.Reserve(N, al); - for (decltype(N) i = 0; i < N; ++i) { + for (decltype(N) i = 0; i < N; ++i) { + val.PushBack(r[i], al); + } + return val; + } + + inline Value& MakeValue(Value& val, const std::vector & r, MemoryPoolAllocator<>& al) { + val.SetArray(); + val.Reserve(r.size(), al); + for (int i = 0; i < r.size(); ++i) { val.PushBack(r[i], al); } return val; @@ -85,6 +94,10 @@ namespace glTF { obj.AddMember("componentType", int(a.componentType), w.mAl); obj.AddMember("count", a.count, w.mAl); obj.AddMember("type", StringRef(AttribType::ToString(a.type)), w.mAl); + + Value vTmpMax, vTmpMin; + obj.AddMember("max", MakeValue(vTmpMax, a.max, w.mAl), w.mAl); + obj.AddMember("min", MakeValue(vTmpMin, a.min, w.mAl), w.mAl); } inline void Write(Value& obj, Animation& a, AssetWriter& w) @@ -491,7 +504,7 @@ namespace glTF { asset.SetObject(); { char versionChar[10]; - snprintf(versionChar, sizeof(versionChar), "%d", mAsset.asset.version); + ai_snprintf(versionChar, sizeof(versionChar), "%d", 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 708570577..2da709cee 100644 --- a/code/glTFExporter.cpp +++ b/code/glTFExporter.cpp @@ -193,6 +193,31 @@ inline Ref ExportData(Asset& a, std::string& meshName, Ref& bu acc->count = count; acc->type = typeOut; + // calculate min and max values + { + // Allocate and initialize with large values. + float float_MAX = 10000000000000; + for (int i = 0 ; i < numCompsOut ; i++) { + acc->min.push_back( float_MAX); + acc->max.push_back(-float_MAX); + } + + // Search and set extreme values. + float valueTmp; + for (int i = 0 ; i < count ; i++) { + for (int j = 0 ; j < numCompsOut ; j++) { + + valueTmp = static_cast(data)[i][j]; + if (valueTmp < acc->min[j]) { + acc->min[j] = valueTmp; + } + if (valueTmp > acc->max[j]) { + acc->max[j] = valueTmp; + } + } + } + } + // copy the data acc->WriteData(count, data, numCompsIn*bytesPerComp);