/* This file is part of Magnum. Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Vladimír Vondruš Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define _MAGNUM_NO_DEPRECATED_FLATTENMESHHIERARCHY /* So it doesn't yell here */ #include "FlattenMeshHierarchy.h" #include #include #include #include "Magnum/DimensionTraits.h" #include "Magnum/Math/Matrix3.h" #include "Magnum/Math/Matrix4.h" #include "Magnum/SceneTools/FlattenTransformationHierarchy.h" #include "Magnum/Trade/SceneData.h" namespace Magnum { namespace SceneTools { namespace { template struct DimensionTraits; template<> struct DimensionTraits<2> { static Containers::Array flatten(const Trade::SceneData& scene, const UnsignedInt fieldId, const Matrix3& globalTransformation) { return flattenTransformationHierarchy2D(scene, fieldId, globalTransformation); } static void flattenInto(const Trade::SceneData& scene, const UnsignedInt fieldId, const Containers::StridedArrayView1D& transformations, const Matrix3& globalTransformation) { return flattenTransformationHierarchy2DInto(scene, fieldId, transformations, globalTransformation); } }; template<> struct DimensionTraits<3> { static Containers::Array flatten(const Trade::SceneData& scene, const UnsignedInt fieldId, const Matrix4& globalTransformation) { return flattenTransformationHierarchy3D(scene, fieldId, globalTransformation); } static void flattenInto(const Trade::SceneData& scene, const UnsignedInt fieldId, const Containers::StridedArrayView1D& transformations, const Matrix4& globalTransformation) { return flattenTransformationHierarchy3DInto(scene, fieldId, transformations, globalTransformation); } }; template void flattenMeshHierarchyIntoImplementation(const Trade::SceneData& scene, const Containers::StridedArrayView1D>& outputTransformations, const MatrixTypeFor& globalTransformation) { const Containers::Optional meshFieldId = scene.findFieldId(Trade::SceneField::Mesh); /* If there's no mesh field in the file, nothing to do. This is how the original API behaved, it's an assertion in the new one. */ if(!meshFieldId) return; DimensionTraits::flattenInto(scene, *meshFieldId, outputTransformations, globalTransformation); } template Containers::Array>> flattenMeshHierarchyImplementation(const Trade::SceneData& scene, const MatrixTypeFor& globalTransformation) { const Containers::Optional meshFieldId = scene.findFieldId(Trade::SceneField::Mesh); /* If there's no mesh field in the file, nothing to do. This is how the original API behaved, it's an assertion in the new one. */ if(!meshFieldId) return {}; /* Get the transformations. This will be a no-op if the mesh field isn't present, but will go through other assertions that may still be rather valuable */ Containers::Array>> out{NoInit, scene.fieldSize(*meshFieldId)}; DimensionTraits::flattenInto(scene, *meshFieldId, stridedArrayView(out).slice(&decltype(out)::Type::third), globalTransformation); /* Fetch the additional mesh and material ID as well, which are in the same order */ scene.meshesMaterialsInto(nullptr, stridedArrayView(out).slice(&decltype(out)::Type::first), stridedArrayView(out).slice(&decltype(out)::Type::second)); return out; } } Containers::Array> flattenMeshHierarchy2D(const Trade::SceneData& scene, const Matrix3& globalTransformation) { return flattenMeshHierarchyImplementation<2>(scene, globalTransformation); } Containers::Array> flattenMeshHierarchy2D(const Trade::SceneData& scene) { return flattenMeshHierarchyImplementation<2>(scene, {}); } void flattenMeshHierarchy2DInto(const Trade::SceneData& scene, const Containers::StridedArrayView1D& transformations, const Matrix3& globalTransformation) { return flattenMeshHierarchyIntoImplementation<2>(scene, transformations, globalTransformation); } void flattenMeshHierarchy2DInto(const Trade::SceneData& scene, const Containers::StridedArrayView1D& transformations) { return flattenMeshHierarchyIntoImplementation<2>(scene, transformations, {}); } Containers::Array> flattenMeshHierarchy3D(const Trade::SceneData& scene, const Matrix4& globalTransformation) { return flattenMeshHierarchyImplementation<3>(scene, globalTransformation); } Containers::Array> flattenMeshHierarchy3D(const Trade::SceneData& scene) { return flattenMeshHierarchyImplementation<3>(scene, {}); } void flattenMeshHierarchy3DInto(const Trade::SceneData& scene, const Containers::StridedArrayView1D& transformations, const Matrix4& globalTransformation) { return flattenMeshHierarchyIntoImplementation<3>(scene, transformations, globalTransformation); } void flattenMeshHierarchy3DInto(const Trade::SceneData& scene, const Containers::StridedArrayView1D& transformations) { return flattenMeshHierarchyIntoImplementation<3>(scene, transformations, {}); } }}