X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene3d%2Fpublic-api%2Floader%2Fmesh-definition.cpp;h=7894b58ea6cec5a4187c6c85c8d7b854232311f6;hb=c1294f3111ae2eb199dca0374fd09171a6782735;hp=b23140fb286d1676a5a5d358980991137af9428e;hpb=30f8b41af892e67e267525b3d98eca2eac0c8980;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-scene3d/public-api/loader/mesh-definition.cpp b/dali-scene3d/public-api/loader/mesh-definition.cpp index b23140f..7894b58 100644 --- a/dali-scene3d/public-api/loader/mesh-definition.cpp +++ b/dali-scene3d/public-api/loader/mesh-definition.cpp @@ -15,8 +15,8 @@ * */ -// INTERNAL INCLUDES -#include "dali-scene3d/public-api/loader/mesh-definition.h" +// CLASS HEADER +#include // EXTERNAL INCLUDES #include @@ -27,44 +27,43 @@ #include #include -namespace Dali -{ -namespace Scene3D -{ -namespace Loader +namespace Dali::Scene3D::Loader { namespace { +template class IndexProvider { public: + using IndexType = typename std::conditional_t; IndexProvider(const uint16_t* indices) : mData(reinterpret_cast(indices)), mFunc(indices ? IncrementPointer : Increment) { } - uint16_t operator()() + IndexType operator()() { return mFunc(mData); } private: - static uint16_t Increment(uintptr_t& data) + static IndexType Increment(uintptr_t& data) { - return static_cast(data++); + // mData was 'zero' at construct time. Just simply return counter start with 0. + return static_cast(data++); } - static uint16_t IncrementPointer(uintptr_t& data) + static IndexType IncrementPointer(uintptr_t& data) { - auto iPtr = reinterpret_cast(data); + auto iPtr = reinterpret_cast(data); auto result = *iPtr; data = reinterpret_cast(++iPtr); return result; } uintptr_t mData; - uint16_t (*mFunc)(uintptr_t&); + IndexType (*mFunc)(uintptr_t&); }; const char* QUAD("quad"); @@ -91,11 +90,11 @@ bool ReadBlob(const MeshDefinition::Blob& descriptor, std::istream& source, uint uint32_t readSize = 0; uint32_t totalSize = (descriptor.mLength / descriptor.mElementSizeHint) * descriptor.mStride; while(readSize < totalSize && - source.read(reinterpret_cast(target), descriptor.mElementSizeHint) && - source.seekg(diff, std::istream::cur)) + source.read(reinterpret_cast(target), descriptor.mElementSizeHint)) { readSize += descriptor.mStride; target += descriptor.mElementSizeHint; + source.seekg(diff, std::istream::cur); } return readSize == totalSize; } @@ -114,7 +113,7 @@ void ReadValues(const std::vector& valuesBuffer, const std::vector* sparseIndices) { bool success = false; @@ -153,31 +152,63 @@ bool ReadAccessor(const MeshDefinition::Accessor& accessor, std::istream& source return false; } + // If non-null sparse indices vector, prepare it for output + if(sparseIndices) + { + sparseIndices->resize(accessor.mSparse->mCount); + } + switch(indices.mElementSizeHint) { case 1u: { ReadValues(valuesBuffer, indicesBuffer, target, accessor.mSparse->mCount, values.mElementSizeHint); + if(sparseIndices) + { + // convert 8-bit indices into 32-bit + std::transform(indicesBuffer.begin(), indicesBuffer.end(), sparseIndices->begin(), [](const uint8_t& value) { return uint32_t(value); }); + } break; } case 2u: { ReadValues(valuesBuffer, indicesBuffer, target, accessor.mSparse->mCount, values.mElementSizeHint); + if(sparseIndices) + { + // convert 16-bit indices into 32-bit + std::transform(reinterpret_cast(indicesBuffer.data()), + reinterpret_cast(indicesBuffer.data()) + accessor.mSparse->mCount, + sparseIndices->begin(), + [](const uint16_t& value) { + return uint32_t(value); + }); + } break; } case 4u: { ReadValues(valuesBuffer, indicesBuffer, target, accessor.mSparse->mCount, values.mElementSizeHint); + if(sparseIndices) + { + std::copy(indicesBuffer.begin(), indicesBuffer.end(), reinterpret_cast(sparseIndices->data())); + } break; } default: + { DALI_ASSERT_DEBUG(!"Unsupported type for an index"); + } } } return success; } +bool ReadAccessor(const MeshDefinition::Accessor& accessor, std::istream& source, uint8_t* target) +{ + return ReadAccessor(accessor, source, target, nullptr); +} + template void ReadJointAccessor(MeshDefinition::RawData& raw, const MeshDefinition::Accessor& accessor, std::istream& source, const std::string& meshPath) { @@ -212,13 +243,58 @@ void ReadJointAccessor(MeshDefinition::RawData& raw, const MeshDefinition::Acces raw.mAttribs.push_back({"aJoints", Property::VECTOR4, static_cast(outBufferSize / sizeof(Vector4)), std::move(buffer)}); } -void GenerateNormals(MeshDefinition::RawData& raw) +template +void ReadWeightAccessor(MeshDefinition::RawData& raw, const MeshDefinition::Accessor& accessor, std::istream& source, const std::string& meshPath) { + constexpr auto sizeofBlobUnit = sizeof(T) * 4; + + DALI_ASSERT_ALWAYS(((accessor.mBlob.mLength % sizeofBlobUnit == 0) || + accessor.mBlob.mStride >= sizeofBlobUnit) && + "weights buffer length not a multiple of element size"); + const auto inBufferSize = accessor.mBlob.GetBufferSize(); + const auto outBufferSize = (sizeof(Vector4) / sizeofBlobUnit) * inBufferSize; + + std::vector buffer(outBufferSize); + auto inBuffer = buffer.data() + outBufferSize - inBufferSize; + if(!ReadAccessor(accessor, source, inBuffer)) + { + ExceptionFlinger(ASSERT_LOCATION) << "Failed to read weights from '" << meshPath << "'."; + } + + if constexpr(sizeofBlobUnit != sizeof(Vector4)) + { + auto floats = reinterpret_cast(buffer.data()); + const auto end = inBuffer + inBufferSize; + while(inBuffer != end) + { + const auto value = *reinterpret_cast(inBuffer); + // Normalize weight value. value /= 255 for uint8_t weight, and value /= 65535 for uint16_t weight. + *floats = static_cast(value) / static_cast((1 << (sizeof(T) * 8)) - 1); + + inBuffer += sizeof(T); + ++floats; + } + } + raw.mAttribs.push_back({"aWeights", Property::VECTOR4, static_cast(outBufferSize / sizeof(Vector4)), std::move(buffer)}); +} + +template> +bool GenerateNormals(MeshDefinition::RawData& raw) +{ + using IndexType = typename IndexProviderType::IndexType; + + // mIndicies size must be even if we use 32bit indices. + if(DALI_UNLIKELY(use32BitsIndices && !raw.mIndices.empty() && !(raw.mIndices.size() % (sizeof(IndexType) / sizeof(uint16_t)) == 0))) + { + return false; + } + auto& attribs = raw.mAttribs; DALI_ASSERT_DEBUG(attribs.size() > 0); // positions - IndexProvider getIndex(raw.mIndices.data()); - const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast(raw.mIndices.size()); + IndexProviderType getIndex(raw.mIndices.data()); + + const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast(raw.mIndices.size() / (sizeof(IndexType) / sizeof(uint16_t))); auto* positions = reinterpret_cast(attribs[0].mData.data()); @@ -227,8 +303,8 @@ void GenerateNormals(MeshDefinition::RawData& raw) for(uint32_t i = 0; i < numIndices; i += 3) { - uint16_t indices[]{getIndex(), getIndex(), getIndex()}; - Vector3 pos[]{positions[indices[0]], positions[indices[1]], positions[indices[2]]}; + IndexType indices[]{getIndex(), getIndex(), getIndex()}; + Vector3 pos[]{positions[indices[0]], positions[indices[1]], positions[indices[2]]}; Vector3 a = pos[1] - pos[0]; Vector3 b = pos[2] - pos[0]; @@ -247,14 +323,24 @@ void GenerateNormals(MeshDefinition::RawData& raw) } attribs.push_back({"aNormal", Property::VECTOR3, attribs[0].mNumElements, std::move(buffer)}); + + return true; } -template, typename = std::enable_if_t<(std::is_same::value || std::is_same::value)>> +template, typename = std::enable_if_t<(std::is_same::value || std::is_same::value)>, typename IndexProviderType = IndexProvider> bool GenerateTangents(MeshDefinition::RawData& raw) { + using IndexType = typename IndexProviderType::IndexType; + + // mIndicies size must be even if we use 32bit indices. + if(DALI_UNLIKELY(use32BitsIndices && !raw.mIndices.empty() && !(raw.mIndices.size() % (sizeof(IndexType) / sizeof(uint16_t)) == 0))) + { + return false; + } + auto& attribs = raw.mAttribs; // Required positions, normals, uvs (if we have). If not, skip generation - if(attribs.size() < (2 + static_cast(hasUvs))) + if(DALI_UNLIKELY(attribs.size() < (2 + static_cast(hasUvs)))) { return false; } @@ -264,17 +350,18 @@ bool GenerateTangents(MeshDefinition::RawData& raw) if constexpr(hasUvs) { - IndexProvider getIndex(raw.mIndices.data()); - const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast(raw.mIndices.size()); + IndexProviderType getIndex(raw.mIndices.data()); + + const uint32_t numIndices = raw.mIndices.empty() ? attribs[0].mNumElements : static_cast(raw.mIndices.size() / (sizeof(IndexType) / sizeof(uint16_t))); auto* positions = reinterpret_cast(attribs[0].mData.data()); auto* uvs = reinterpret_cast(attribs[2].mData.data()); for(uint32_t i = 0; i < numIndices; i += 3) { - uint16_t indices[]{getIndex(), getIndex(), getIndex()}; - Vector3 pos[]{positions[indices[0]], positions[indices[1]], positions[indices[2]]}; - Vector2 uv[]{uvs[indices[0]], uvs[indices[1]], uvs[indices[2]]}; + IndexType indices[]{getIndex(), getIndex(), getIndex()}; + Vector3 pos[]{positions[indices[0]], positions[indices[1]], positions[indices[2]]}; + Vector2 uv[]{uvs[indices[0]], uvs[indices[1]], uvs[indices[2]]}; float x0 = pos[1].x - pos[0].x; float y0 = pos[1].y - pos[0].y; @@ -362,7 +449,7 @@ void CalculateTextureSize(uint32_t totalTextureSize, uint32_t& textureWidth, uin void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector& blendShapes, uint32_t numberOfVertices, float& blendShapeUnnormalizeFactor, BufferDefinition::Vector& buffers) { uint32_t geometryBufferIndex = 0u; - float maxDistance = 0.f; + float maxDistanceSquared = 0.f; Vector3* geometryBufferV3 = reinterpret_cast(geometryBuffer); for(const auto& blendShape : blendShapes) { @@ -372,21 +459,41 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector= sizeof(Vector3)) && "Blend Shape position buffer length not a multiple of element size"); - const auto bufferSize = blendShape.deltas.mBlob.GetBufferSize(); - std::vector buffer(bufferSize); - if(ReadAccessor(blendShape.deltas, buffers[blendShape.deltas.mBufferIdx].GetBufferStream(), buffer.data())) + const auto bufferSize = blendShape.deltas.mBlob.GetBufferSize(); + std::vector buffer(bufferSize); + std::vector sparseIndices{}; + + if(ReadAccessor(blendShape.deltas, buffers[blendShape.deltas.mBufferIdx].GetBufferStream(), buffer.data(), &sparseIndices)) { - blendShape.deltas.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data())); + blendShape.deltas.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data()), &sparseIndices); + // Calculate the difference with the original mesh. // Find the max distance to normalize the deltas. - const Vector3* const deltasBuffer = reinterpret_cast(buffer.data()); + const auto* const deltasBuffer = reinterpret_cast(buffer.data()); - for(uint32_t index = 0u; index < numberOfVertices; ++index) - { - Vector3& delta = geometryBufferV3[geometryBufferIndex++]; - delta = deltasBuffer[index]; + auto ProcessVertex = [&geometryBufferV3, &deltasBuffer, &maxDistanceSquared](uint32_t geometryBufferIndex, uint32_t deltaIndex) { + Vector3& delta = geometryBufferV3[geometryBufferIndex] = deltasBuffer[deltaIndex]; + delta = deltasBuffer[deltaIndex]; + return std::max(maxDistanceSquared, delta.LengthSquared()); + }; - maxDistance = std::max(maxDistance, delta.LengthSquared()); + if(sparseIndices.empty()) + { + for(uint32_t index = 0u; index < numberOfVertices; ++index) + { + maxDistanceSquared = ProcessVertex(geometryBufferIndex++, index); + } + } + else + { + // initialize blendshape texture + // TODO: there may be a case when sparse accessor uses a base buffer view for initial values. + std::fill(geometryBufferV3 + geometryBufferIndex, geometryBufferV3 + geometryBufferIndex + numberOfVertices, Vector3::ZERO); + for(auto index : sparseIndices) + { + maxDistanceSquared = ProcessVertex(geometryBufferIndex + index, index); + } + geometryBufferIndex += numberOfVertices; } } } @@ -397,20 +504,18 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector= sizeof(Vector3)) && "Blend Shape normals buffer length not a multiple of element size"); - const auto bufferSize = blendShape.normals.mBlob.GetBufferSize(); - std::vector buffer(bufferSize); - if(ReadAccessor(blendShape.normals, buffers[blendShape.normals.mBufferIdx].GetBufferStream(), buffer.data())) + const auto bufferSize = blendShape.normals.mBlob.GetBufferSize(); + std::vector buffer(bufferSize); + std::vector sparseIndices; + + if(ReadAccessor(blendShape.normals, buffers[blendShape.normals.mBufferIdx].GetBufferStream(), buffer.data(), &sparseIndices)) { - blendShape.normals.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data())); + blendShape.normals.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data()), &sparseIndices); // Calculate the difference with the original mesh, and translate to make all values positive. - const Vector3* const deltasBuffer = reinterpret_cast(buffer.data()); - - for(uint32_t index = 0u; index < numberOfVertices; ++index) - { - Vector3& delta = geometryBufferV3[geometryBufferIndex++]; - delta = deltasBuffer[index]; - + const Vector3* const deltasBuffer = reinterpret_cast(buffer.data()); + auto ProcessVertex = [&geometryBufferV3, &deltasBuffer, &maxDistanceSquared](uint32_t geometryBufferIndex, uint32_t deltaIndex) { + Vector3& delta = geometryBufferV3[geometryBufferIndex] = deltasBuffer[deltaIndex]; delta.x *= 0.5f; delta.y *= 0.5f; delta.z *= 0.5f; @@ -418,6 +523,23 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector= sizeof(Vector3)) && "Blend Shape tangents buffer length not a multiple of element size"); - const auto bufferSize = blendShape.tangents.mBlob.GetBufferSize(); - std::vector buffer(bufferSize); - if(ReadAccessor(blendShape.tangents, buffers[blendShape.tangents.mBufferIdx].GetBufferStream(), buffer.data())) + const auto bufferSize = blendShape.tangents.mBlob.GetBufferSize(); + std::vector buffer(bufferSize); + std::vector sparseIndices; + + if(ReadAccessor(blendShape.tangents, buffers[blendShape.tangents.mBufferIdx].GetBufferStream(), buffer.data(), &sparseIndices)) { - blendShape.tangents.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data())); + blendShape.tangents.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector3)), reinterpret_cast(buffer.data()), &sparseIndices); // Calculate the difference with the original mesh, and translate to make all values positive. - const Vector3* const deltasBuffer = reinterpret_cast(buffer.data()); - - for(uint32_t index = 0u; index < numberOfVertices; ++index) - { - Vector3& delta = geometryBufferV3[geometryBufferIndex++]; - delta = deltasBuffer[index]; - + const Vector3* const deltasBuffer = reinterpret_cast(buffer.data()); + auto ProcessVertex = [&geometryBufferV3, &deltasBuffer, &maxDistanceSquared](uint32_t geometryBufferIndex, uint32_t deltaIndex) { + Vector3& delta = geometryBufferV3[geometryBufferIndex] = deltasBuffer[deltaIndex]; delta.x *= 0.5f; delta.y *= 0.5f; delta.z *= 0.5f; @@ -449,12 +569,37 @@ void CalculateGltf2BlendShapes(uint8_t* geometryBuffer, const std::vector& min, std::vector& min, const std::vector& max, uint32_t count, float* values) +void MeshDefinition::Blob::ApplyMinMax(const std::vector& min, const std::vector& max, uint32_t count, float* values, std::vector* sparseIndices) { DALI_ASSERT_DEBUG(max.size() == min.size() || max.size() * min.size() == 0); const auto numComponents = std::max(min.size(), max.size()); @@ -559,16 +699,31 @@ void MeshDefinition::Blob::ApplyMinMax(const std::vector& min, const std: return; } - auto end = values + count * numComponents; - while(values != end) + // If there are sparse indices then process only relevant data + if(sparseIndices && !sparseIndices->empty()) { - auto nextElement = values + numComponents; - uint32_t i = 0; - while(values != nextElement) + for(auto elementIndex : *sparseIndices) { - clampFn(min.data(), max.data(), i, *values); - ++values; - ++i; + auto value = values + (elementIndex * numComponents); + for(auto i = 0u; i < numComponents; ++i) + { + clampFn(min.data(), max.data(), i, *value); + } + } + } + else // if there's no sparse indices process all vertices + { + auto end = values + count * numComponents; + while(values != end) + { + auto nextElement = values + numComponents; + uint32_t i = 0; + while(values != nextElement) + { + clampFn(min.data(), max.data(), i, *values); + ++values; + ++i; + } } } } @@ -593,9 +748,9 @@ void MeshDefinition::Blob::ComputeMinMax(uint32_t numComponents, uint32_t count, ComputeMinMax(mMin, mMax, numComponents, count, values); } -void MeshDefinition::Blob::ApplyMinMax(uint32_t count, float* values) const +void MeshDefinition::Blob::ApplyMinMax(uint32_t count, float* values, std::vector* sparseIndices) const { - ApplyMinMax(mMin, mMax, count, values); + ApplyMinMax(mMin, mMax, count, values, sparseIndices); } void MeshDefinition::RawData::Attrib::AttachBuffer(Geometry& g) const @@ -670,18 +825,6 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& { ExceptionFlinger(ASSERT_LOCATION) << "Failed to read indices from '" << path << "'."; } - - auto u16s = raw.mIndices.data(); - auto u32s = reinterpret_cast(raw.mIndices.data()); - auto end = u32s + indexCount; - while(u32s != end) - { - *u16s = static_cast(*u32s); - ++u16s; - ++u32s; - } - - raw.mIndices.resize(indexCount); } else if(MaskMatch(mFlags, U8_INDICES)) { @@ -689,7 +832,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& mIndices.mBlob.mStride >= sizeof(uint8_t)) && "Index buffer length not a multiple of element size"); const auto indexCount = mIndices.mBlob.GetBufferSize() / sizeof(uint8_t); - raw.mIndices.resize(indexCount); // NOTE: we need space for uint32_ts initially. + raw.mIndices.resize(indexCount); // NOTE: we need space for uint16_ts initially. std::string path; auto u8s = reinterpret_cast(raw.mIndices.data()) + indexCount; @@ -783,8 +926,20 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& else if(mNormals.mBlob.mLength != 0 && isTriangles) { DALI_ASSERT_DEBUG(mNormals.mBlob.mLength == mPositions.mBlob.GetBufferSize()); - GenerateNormals(raw); - hasNormals = true; + static const std::function GenerateNormalsFunction[2] = + { + GenerateNormals, + GenerateNormals, + }; + const bool generateSuccessed = GenerateNormalsFunction[MaskMatch(mFlags, U32_INDICES)](raw); + if(!generateSuccessed) + { + DALI_LOG_ERROR("Failed to generate normal\n"); + } + else + { + hasNormals = true; + } } const auto hasUvs = mTexCoords.IsDefined(); @@ -815,7 +970,7 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& } } - mTexCoords.mBlob.ApplyMinMax(static_cast(bufferSize / sizeof(Vector2)), reinterpret_cast(buffer.data())); + mTexCoords.mBlob.ApplyMinMax(static_cast(uvCount), reinterpret_cast(buffer.data())); raw.mAttribs.push_back({"aTexCoord", Property::VECTOR2, static_cast(uvCount), std::move(buffer)}); } @@ -842,18 +997,29 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& else if(mTangents.mBlob.mLength != 0 && hasNormals && isTriangles) { DALI_ASSERT_DEBUG(mTangents.mBlob.mLength == mNormals.mBlob.GetBufferSize()); - static const std::function GenerateTangentsFunction[2][2] = + static const std::function GenerateTangentsFunction[2][2][2] = { { - GenerateTangents, - GenerateTangents, + { + GenerateTangents, + GenerateTangents, + }, + { + GenerateTangents, + GenerateTangents, + }, }, { - GenerateTangents, - GenerateTangents, - }, - }; - const bool generateSuccessed = GenerateTangentsFunction[mTangentType == Property::VECTOR3][hasUvs](raw); + { + GenerateTangents, + GenerateTangents, + }, + { + GenerateTangents, + GenerateTangents, + }, + }}; + const bool generateSuccessed = GenerateTangentsFunction[MaskMatch(mFlags, U32_INDICES)][mTangentType == Property::VECTOR3][hasUvs](raw); if(!generateSuccessed) { DALI_LOG_ERROR("Failed to generate tangents\n"); @@ -883,6 +1049,18 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& raw.mAttribs.push_back({"aVertexColor", propertyType, static_cast(bufferSize / propertySize), std::move(buffer)}); } } + else + { + std::vector buffer(raw.mAttribs[0].mNumElements * sizeof(Vector4)); + auto colors = reinterpret_cast(buffer.data()); + + for(uint32_t i = 0; i < raw.mAttribs[0].mNumElements; i++) + { + colors[i] = Vector4::ONE; + } + + raw.mAttribs.push_back({"aVertexColor", Property::VECTOR4, raw.mAttribs[0].mNumElements, std::move(buffer)}); + } if(IsSkinned()) { @@ -901,20 +1079,20 @@ MeshDefinition::LoadRaw(const std::string& modelsPath, BufferDefinition::Vector& ReadJointAccessor(raw, mJoints0, streamJoint, pathJoint); } - DALI_ASSERT_ALWAYS(((mWeights0.mBlob.mLength % sizeof(Vector4) == 0) || - mWeights0.mBlob.mStride >= sizeof(Vector4)) && - "Weights buffer length not a multiple of element size"); - const auto bufferSize = mWeights0.mBlob.GetBufferSize(); - std::vector buffer(bufferSize); - std::string pathWeight; auto& streamWeight = GetAvailableData(fileStream, meshPath, buffers[mWeights0.mBufferIdx], pathWeight); - if(!ReadAccessor(mWeights0, streamWeight, buffer.data())) + if(MaskMatch(mFlags, U16_WEIGHT)) { - ExceptionFlinger(ASSERT_LOCATION) << "Failed to read weights from '" << pathWeight << "'."; + ReadWeightAccessor(raw, mWeights0, streamWeight, pathWeight); + } + else if(MaskMatch(mFlags, U8_WEIGHT)) + { + ReadWeightAccessor(raw, mWeights0, streamWeight, pathWeight); + } + else + { + ReadWeightAccessor(raw, mWeights0, streamWeight, pathWeight); } - - raw.mAttribs.push_back({"aWeights", Property::VECTOR4, static_cast(bufferSize / sizeof(Vector4)), std::move(buffer)}); } // Calculate the Blob for the blend shapes. @@ -1008,7 +1186,15 @@ MeshGeometry MeshDefinition::Load(RawData&& raw) const { if(!raw.mIndices.empty()) { - meshGeometry.geometry.SetIndexBuffer(raw.mIndices.data(), raw.mIndices.size()); + if(MaskMatch(mFlags, U32_INDICES)) + { + // TODO : We can only store indeces as uint16_type. Send Dali::Geometry that we use it as uint32_t actual. + meshGeometry.geometry.SetIndexBuffer(reinterpret_cast(raw.mIndices.data()), raw.mIndices.size() / 2); + } + else + { + meshGeometry.geometry.SetIndexBuffer(raw.mIndices.data(), raw.mIndices.size()); + } } for(auto& a : raw.mAttribs) @@ -1032,6 +1218,14 @@ MeshGeometry MeshDefinition::Load(RawData&& raw) const return meshGeometry; } -} // namespace Loader -} // namespace Scene3D -} // namespace Dali +void MeshDefinition::RetrieveBlendShapeComponents(bool& hasPositions, bool& hasNormals, bool& hasTangents) const +{ + for(const auto& blendShape : mBlendShapes) + { + hasPositions = hasPositions || blendShape.deltas.IsDefined(); + hasNormals = hasNormals || blendShape.normals.IsDefined(); + hasTangents = hasTangents || blendShape.tangents.IsDefined(); + } +} + +} // namespace Dali::Scene3D::Loader