18bf80f4bSopenharmony_ci/*
28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License.
58bf80f4bSopenharmony_ci * You may obtain a copy of the License at
68bf80f4bSopenharmony_ci *
78bf80f4bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88bf80f4bSopenharmony_ci *
98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and
138bf80f4bSopenharmony_ci * limitations under the License.
148bf80f4bSopenharmony_ci */
158bf80f4bSopenharmony_ci
168bf80f4bSopenharmony_ci#include "asset_migration.h"
178bf80f4bSopenharmony_ci
188bf80f4bSopenharmony_ci#include <3d/ecs/components/animation_output_component.h>
198bf80f4bSopenharmony_ci#include <core/property/property_types.h>
208bf80f4bSopenharmony_ci
218bf80f4bSopenharmony_ciusing namespace BASE_NS;
228bf80f4bSopenharmony_ciusing namespace CORE_NS;
238bf80f4bSopenharmony_ciusing namespace CORE3D_NS;
248bf80f4bSopenharmony_ci
258bf80f4bSopenharmony_ciSCENE_BEGIN_NAMESPACE()
268bf80f4bSopenharmony_ci
278bf80f4bSopenharmony_cinamespace {
288bf80f4bSopenharmony_cistruct Conversion {
298bf80f4bSopenharmony_ci    PropertyTypeDecl oldVersion;
308bf80f4bSopenharmony_ci    PropertyTypeDecl newVersion;
318bf80f4bSopenharmony_ci};
328bf80f4bSopenharmony_ci
338bf80f4bSopenharmony_ci// Add all datatype conversions here.
348bf80f4bSopenharmony_ciconstexpr Conversion conversions[] = {
358bf80f4bSopenharmony_ci
368bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::IVec2), PropertyType::IVEC2_T }, // Math::IVec2 to BASE_NS::Math::IVec2
378bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::IVec3), PropertyType::IVEC3_T }, // Math::IVec3 to BASE_NS::Math::IVec3
388bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::IVec4), PropertyType::IVEC4_T }, // Math::IVec4 to BASE_NS::Math::IVec4
398bf80f4bSopenharmony_ci
408bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::UVec2), PropertyType::UVEC2_T }, // Math::UVec2 to BASE_NS::Math::UVec2
418bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::UVec3), PropertyType::UVEC3_T }, // Math::UVec3 to BASE_NS::Math::UVec3
428bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::UVec4), PropertyType::UVEC4_T }, // Math::UVec4 to BASE_NS::Math::UVec4
438bf80f4bSopenharmony_ci
448bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::Vec2), PropertyType::VEC2_T }, // Math::Vec2 to BASE_NS::Math::Vec2
458bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::Vec3), PropertyType::VEC3_T }, // Math::Vec3 to BASE_NS::Math::Vec3
468bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::Vec4), PropertyType::VEC4_T }, // Math::Vec4 to BASE_NS::Math::Vec4
478bf80f4bSopenharmony_ci
488bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::Quat), PropertyType::QUAT_T },     // Math::Quat to BASE_NS::Math::Quat
498bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::Mat3X3), PropertyType::MAT3X3_T }, // Math::Mat3X3 to BASE_NS::Math::Mat3X3
508bf80f4bSopenharmony_ci    { PROPERTYTYPE(Math::Mat4X4), PropertyType::MAT4X4_T }, // Math::Mat4X4 to BASE_NS::Math::Mat4X4
518bf80f4bSopenharmony_ci
528bf80f4bSopenharmony_ci    { PROPERTYTYPE(Uid), PropertyType::UID_T },       // Uid to BASE_NS::Uid
538bf80f4bSopenharmony_ci    { PROPERTYTYPE(string), PropertyType::STRING_T }, // string to BASE_NS::string
548bf80f4bSopenharmony_ci
558bf80f4bSopenharmony_ci    // Array types.
568bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::IVec2), PropertyType::IVEC2_ARRAY_T }, // Math::IVec2 to BASE_NS::Math::IVec2
578bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::IVec3), PropertyType::IVEC3_ARRAY_T }, // Math::IVec3 to BASE_NS::Math::IVec3
588bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::IVec4), PropertyType::IVEC4_ARRAY_T }, // Math::IVec4 to BASE_NS::Math::IVec4
598bf80f4bSopenharmony_ci
608bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::UVec2), PropertyType::UVEC2_ARRAY_T }, // Math::UVec2 to BASE_NS::Math::UVec2
618bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::UVec3), PropertyType::UVEC3_ARRAY_T }, // Math::UVec3 to BASE_NS::Math::UVec3
628bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::UVec4), PropertyType::UVEC4_ARRAY_T }, // Math::UVec4 to BASE_NS::Math::UVec4
638bf80f4bSopenharmony_ci
648bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::Vec2), PropertyType::VEC2_ARRAY_T }, // Math::Vec2 to BASE_NS::Math::Vec2
658bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::Vec3), PropertyType::VEC3_ARRAY_T }, // Math::Vec3 to BASE_NS::Math::Vec3
668bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::Vec4), PropertyType::VEC4_ARRAY_T }, // Math::Vec4 to BASE_NS::Math::Vec4
678bf80f4bSopenharmony_ci
688bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::Quat), PropertyType::QUAT_ARRAY_T },     // Math::Quat to BASE_NS::Math::Quat
698bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::Mat3X3), PropertyType::MAT3X3_ARRAY_T }, // Math::Mat3X3 to BASE_NS::Math::Mat3X3
708bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Math::Mat4X4), PropertyType::MAT4X4_ARRAY_T }, // Math::Mat4X4 to BASE_NS::Math::Mat4X4
718bf80f4bSopenharmony_ci
728bf80f4bSopenharmony_ci    { PROPERTYTYPE_ARRAY(Uid), PropertyType::UID_ARRAY_T }, // Uid to BASE_NS::Uid
738bf80f4bSopenharmony_ci
748bf80f4bSopenharmony_ci    { PROPERTYTYPE(vector<float>), PropertyType::FLOAT_VECTOR_T },
758bf80f4bSopenharmony_ci    { PROPERTYTYPE(vector<Math::Mat4X4>), PropertyType::MAT4X4_VECTOR_T },
768bf80f4bSopenharmony_ci    { PROPERTYTYPE(vector<EntityReference>), PropertyType::ENTITY_REFERENCE_VECTOR_T }
778bf80f4bSopenharmony_ci
788bf80f4bSopenharmony_ci};
798bf80f4bSopenharmony_ci
808bf80f4bSopenharmony_cisize_t NUMBER_OF_CONVERSIONS = sizeof(conversions) / sizeof(conversions[0]);
818bf80f4bSopenharmony_ci} // namespace
828bf80f4bSopenharmony_ci
838bf80f4bSopenharmony_civoid MigrateAnimation(IEntityCollection& collection)
848bf80f4bSopenharmony_ci{
858bf80f4bSopenharmony_ci    auto* aocm = GetManager<IAnimationOutputComponentManager>(collection.GetEcs());
868bf80f4bSopenharmony_ci    if (aocm) {
878bf80f4bSopenharmony_ci        vector<EntityReference> entities;
888bf80f4bSopenharmony_ci        collection.GetEntitiesRecursive(false, entities);
898bf80f4bSopenharmony_ci        for (const auto& entity : entities) {
908bf80f4bSopenharmony_ci            if (aocm->HasComponent(entity)) {
918bf80f4bSopenharmony_ci                if (auto handle = aocm->Write(entity); handle) {
928bf80f4bSopenharmony_ci                    for (auto i = 0; i < NUMBER_OF_CONVERSIONS; ++i) {
938bf80f4bSopenharmony_ci                        if (handle->type == conversions[i].oldVersion.typeHash) {
948bf80f4bSopenharmony_ci                            handle->type = conversions[i].newVersion.typeHash;
958bf80f4bSopenharmony_ci                            break;
968bf80f4bSopenharmony_ci                        }
978bf80f4bSopenharmony_ci                    }
988bf80f4bSopenharmony_ci                }
998bf80f4bSopenharmony_ci            }
1008bf80f4bSopenharmony_ci        }
1018bf80f4bSopenharmony_ci    }
1028bf80f4bSopenharmony_ci}
1038bf80f4bSopenharmony_ci
1048bf80f4bSopenharmony_ciSCENE_END_NAMESPACE()
105