calculate and write min and max attributes for accessors
parent
3e322495f2
commit
e89e98291a
|
@ -377,8 +377,8 @@ namespace glTF
|
||||||
ComponentType componentType; //!< The datatype of components in the attribute. (required)
|
ComponentType componentType; //!< The datatype of components in the attribute. (required)
|
||||||
unsigned int count; //!< The number of attributes referenced by this accessor. (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)
|
AttribType::Value type; //!< Specifies if the attribute is a scalar, vector, or matrix. (required)
|
||||||
//std::vector<float> max; //!< Maximum value of each component in this attribute.
|
std::vector<float> max; //!< Maximum value of each component in this attribute.
|
||||||
//std::vector<float> min; //!< Minimum value of each component in this attribute.
|
std::vector<float> min; //!< Minimum value of each component in this attribute.
|
||||||
|
|
||||||
unsigned int GetNumComponents();
|
unsigned int GetNumComponents();
|
||||||
unsigned int GetBytesPerComponent();
|
unsigned int GetBytesPerComponent();
|
||||||
|
|
|
@ -62,6 +62,15 @@ namespace glTF {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Value& MakeValue(Value& val, const std::vector<float> & 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;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void AddRefsVector(Value& obj, const char* fieldId, std::vector< Ref<T> >& v, MemoryPoolAllocator<>& al) {
|
inline void AddRefsVector(Value& obj, const char* fieldId, std::vector< Ref<T> >& v, MemoryPoolAllocator<>& al) {
|
||||||
if (v.empty()) return;
|
if (v.empty()) return;
|
||||||
|
@ -85,6 +94,10 @@ namespace glTF {
|
||||||
obj.AddMember("componentType", int(a.componentType), w.mAl);
|
obj.AddMember("componentType", int(a.componentType), w.mAl);
|
||||||
obj.AddMember("count", a.count, w.mAl);
|
obj.AddMember("count", a.count, w.mAl);
|
||||||
obj.AddMember("type", StringRef(AttribType::ToString(a.type)), 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)
|
inline void Write(Value& obj, Animation& a, AssetWriter& w)
|
||||||
|
@ -491,7 +504,7 @@ namespace glTF {
|
||||||
asset.SetObject();
|
asset.SetObject();
|
||||||
{
|
{
|
||||||
char versionChar[10];
|
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("version", Value(versionChar, mAl).Move(), mAl);
|
||||||
|
|
||||||
asset.AddMember("generator", Value(mAsset.asset.generator, mAl).Move(), mAl);
|
asset.AddMember("generator", Value(mAsset.asset.generator, mAl).Move(), mAl);
|
||||||
|
|
|
@ -193,6 +193,31 @@ inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& bu
|
||||||
acc->count = count;
|
acc->count = count;
|
||||||
acc->type = typeOut;
|
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<aiVector3D*>(data)[i][j];
|
||||||
|
if (valueTmp < acc->min[j]) {
|
||||||
|
acc->min[j] = valueTmp;
|
||||||
|
}
|
||||||
|
if (valueTmp > acc->max[j]) {
|
||||||
|
acc->max[j] = valueTmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// copy the data
|
// copy the data
|
||||||
acc->WriteData(count, data, numCompsIn*bytesPerComp);
|
acc->WriteData(count, data, numCompsIn*bytesPerComp);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue