From 83c9addbc98129267a4abf2ae3191e415dad51ff Mon Sep 17 00:00:00 2001 From: Angelo Scandaliato Date: Thu, 6 Oct 2016 13:01:03 -0700 Subject: [PATCH] removed duplicate function for ExportData --- code/glTFExporter.cpp | 78 +++---------------------------------------- 1 file changed, 5 insertions(+), 73 deletions(-) diff --git a/code/glTFExporter.cpp b/code/glTFExporter.cpp index e41747381..8892db0ba 100644 --- a/code/glTFExporter.cpp +++ b/code/glTFExporter.cpp @@ -630,74 +630,6 @@ void glTFExporter::ExportMetadata() asset.generator = buffer; } - -inline Ref ExportAnimationData(Asset& a, std::string& animId, Ref& buffer, - unsigned int count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType) -{ - if (!count || !data) return Ref(); - - unsigned int numCompsIn = AttribType::GetNumComponents(typeIn); - unsigned int numCompsOut = AttribType::GetNumComponents(typeOut); - unsigned int bytesPerComp = ComponentTypeSize(compType); - - size_t offset = buffer->byteLength; - size_t length = count * numCompsOut * bytesPerComp; - buffer->Grow(length); - - // bufferView - Ref bv = a.bufferViews.Create(a.FindUniqueID(animId, "view")); - bv->buffer = buffer; - bv->byteOffset = unsigned(offset); - bv->byteLength = length; //! The target that the WebGL buffer should be bound to. - // bv->target = isIndices ? BufferViewTarget_ELEMENT_ARRAY_BUFFER : BufferViewTarget_ARRAY_BUFFER; - bv->target = BufferViewTarget_ARRAY_BUFFER; - - // accessor - Ref acc = a.accessors.Create(a.FindUniqueID(animId, "accessor")); - acc->bufferView = bv; - acc->byteOffset = 0; - acc->byteStride = 0; - acc->componentType = compType; - 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++) { - - if (numCompsOut == 1) { - valueTmp = static_cast(data)[i]; - } else { - 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); - - return acc; -} - - inline void ExtractAnimationData(Asset& mAsset, std::string& animId, Ref& animRef, Ref& buffer, const aiNodeAnim* nodeChannel) { // Loop over the data and check to see if it exactly matches an existing buffer. @@ -716,7 +648,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, RefmPositionKeys[i].mTime; // Check if we have to cast type here. e.g. uint16_t() } - Ref timeAccessor = ExportAnimationData(mAsset, animId, buffer, nodeChannel->mNumPositionKeys, &timeData[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_FLOAT); + Ref timeAccessor = ExportData(mAsset, animId, buffer, nodeChannel->mNumPositionKeys, &timeData[0], AttribType::SCALAR, AttribType::SCALAR, ComponentType_FLOAT); if (timeAccessor) animRef->Parameters.TIME = timeAccessor; } @@ -728,7 +660,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, RefmPositionKeys[i].mValue; } - Ref tranAccessor = ExportAnimationData(mAsset, animId, buffer, nodeChannel->mNumPositionKeys, translationData, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); + Ref tranAccessor = ExportData(mAsset, animId, buffer, nodeChannel->mNumPositionKeys, translationData, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); if (tranAccessor) animRef->Parameters.translation = tranAccessor; } @@ -740,7 +672,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, RefmScalingKeys[i].mValue; } - Ref scaleAccessor = ExportAnimationData(mAsset, animId, buffer, nodeChannel->mNumScalingKeys, scaleData, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); + Ref scaleAccessor = ExportData(mAsset, animId, buffer, nodeChannel->mNumScalingKeys, scaleData, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); if (scaleAccessor) animRef->Parameters.scale = scaleAccessor; } @@ -752,7 +684,7 @@ inline void ExtractAnimationData(Asset& mAsset, std::string& animId, RefmRotationKeys[i].mValue; } - Ref rotAccessor = ExportAnimationData(mAsset, animId, buffer, nodeChannel->mNumRotationKeys, rotationData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT); + Ref rotAccessor = ExportData(mAsset, animId, buffer, nodeChannel->mNumRotationKeys, rotationData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT); if (rotAccessor) animRef->Parameters.rotation = rotAccessor; } } @@ -881,7 +813,7 @@ void glTFExporter::ExportSkins() } // End: for-loop mNumMeshes - Ref invBindMatrixAccessor = ExportAnimationData(*mAsset, skinName, bufferRef, aim->mNumBones, inverseBindMatricesData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT); + Ref invBindMatrixAccessor = ExportData(*mAsset, skinName, bufferRef, aim->mNumBones, inverseBindMatricesData, AttribType::MAT4, AttribType::MAT4, ComponentType_FLOAT); if (invBindMatrixAccessor) skinRef->inverseBindMatrices = invBindMatrixAccessor; } // End: for-loop mNumMeshes