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// clang-format off
178bf80f4bSopenharmony_ci#include <meta/interface/object_macros.h>
188bf80f4bSopenharmony_ci#include <meta/interface/intf_object_registry.h>
198bf80f4bSopenharmony_ci// clang-format on
208bf80f4bSopenharmony_ci
218bf80f4bSopenharmony_ci#include <scene_plugin/api/material.h>
228bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_ecs_scene.h>
238bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_environment.h>
248bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_nodes.h>
258bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_scene.h>
268bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_scene_presenter.h>
278bf80f4bSopenharmony_ci
288bf80f4bSopenharmony_ci#include <3d/implementation_uids.h>
298bf80f4bSopenharmony_ci#include <core/intf_engine.h>
308bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin.h>
318bf80f4bSopenharmony_ci#include <core/plugin/intf_plugin_register.h>
328bf80f4bSopenharmony_ci#include <render/implementation_uids.h>
338bf80f4bSopenharmony_ci
348bf80f4bSopenharmony_ci#include <meta/base/plugin.h>
358bf80f4bSopenharmony_ci
368bf80f4bSopenharmony_ci#include "ecs_animation.h"
378bf80f4bSopenharmony_ci#include "intf_node_private.h"
388bf80f4bSopenharmony_ci
398bf80f4bSopenharmony_cinamespace {
408bf80f4bSopenharmony_cistatic CORE_NS::IPluginRegister* gPluginRegistry { nullptr };
418bf80f4bSopenharmony_ci} // namespace
428bf80f4bSopenharmony_ci
438bf80f4bSopenharmony_ciCORE_BEGIN_NAMESPACE()
448bf80f4bSopenharmony_ciIPluginRegister& GetPluginRegister()
458bf80f4bSopenharmony_ci{
468bf80f4bSopenharmony_ci    return *gPluginRegistry;
478bf80f4bSopenharmony_ci}
488bf80f4bSopenharmony_ciCORE_END_NAMESPACE()
498bf80f4bSopenharmony_ci
508bf80f4bSopenharmony_ciusing namespace CORE_NS;
518bf80f4bSopenharmony_ci
528bf80f4bSopenharmony_ciSCENE_BEGIN_NAMESPACE()
538bf80f4bSopenharmony_citemplate<typename T, const META_NS::ClassInfo& Info>
548bf80f4bSopenharmony_ciclass PendingRequestImpl : public META_NS::ObjectFwd<PendingRequestImpl<T, Info>, Info, META_NS::ClassId::Object,
558bf80f4bSopenharmony_ci                               SCENE_NS::IPendingRequest<T>, SCENE_NS::IPendingRequestData<T>> {
568bf80f4bSopenharmony_ci    META_IMPLEMENT_EVENT(META_NS::IOnChanged, OnReady)
578bf80f4bSopenharmony_ci
588bf80f4bSopenharmony_ci    void Add(const T& data) override
598bf80f4bSopenharmony_ci    {
608bf80f4bSopenharmony_ci        data_.push_back(data);
618bf80f4bSopenharmony_ci    }
628bf80f4bSopenharmony_ci
638bf80f4bSopenharmony_ci    void MarkReady() override
648bf80f4bSopenharmony_ci    {
658bf80f4bSopenharmony_ci        applicationData_.clear();
668bf80f4bSopenharmony_ci        META_NS::Invoke<META_NS::IOnChanged>(OnReady());
678bf80f4bSopenharmony_ci    }
688bf80f4bSopenharmony_ci
698bf80f4bSopenharmony_ci    const BASE_NS::vector<T>& GetResults() const override
708bf80f4bSopenharmony_ci    {
718bf80f4bSopenharmony_ci        return data_;
728bf80f4bSopenharmony_ci    }
738bf80f4bSopenharmony_ci
748bf80f4bSopenharmony_ci    BASE_NS::vector<T>& MutableData() override
758bf80f4bSopenharmony_ci    {
768bf80f4bSopenharmony_ci        return data_;
778bf80f4bSopenharmony_ci    }
788bf80f4bSopenharmony_ci
798bf80f4bSopenharmony_ci    BASE_NS::vector<BASE_NS::string>& MetaData() override
808bf80f4bSopenharmony_ci    {
818bf80f4bSopenharmony_ci        return applicationData_;
828bf80f4bSopenharmony_ci    }
838bf80f4bSopenharmony_ci
848bf80f4bSopenharmony_ci    BASE_NS::vector<T> data_;
858bf80f4bSopenharmony_ci    BASE_NS::vector<BASE_NS::string> applicationData_;
868bf80f4bSopenharmony_ci};
878bf80f4bSopenharmony_ci
888bf80f4bSopenharmony_civoid RegisterNodes();
898bf80f4bSopenharmony_civoid UnregisterNodes();
908bf80f4bSopenharmony_ci
918bf80f4bSopenharmony_civoid RegisterSceneImpl();
928bf80f4bSopenharmony_civoid UnregisterSceneImpl();
938bf80f4bSopenharmony_ci
948bf80f4bSopenharmony_civoid RegisterEcsObject();
958bf80f4bSopenharmony_civoid UnregisterEcsObject();
968bf80f4bSopenharmony_ci
978bf80f4bSopenharmony_civoid RegisterNodeHierarchyController();
988bf80f4bSopenharmony_civoid UnregisterNodeHierarchyController();
998bf80f4bSopenharmony_ci
1008bf80f4bSopenharmony_civoid RegisterEngineAccess();
1018bf80f4bSopenharmony_civoid UnregisterEngineAccess();
1028bf80f4bSopenharmony_ci
1038bf80f4bSopenharmony_ciSCENE_END_NAMESPACE()
1048bf80f4bSopenharmony_ci
1058bf80f4bSopenharmony_ciclass SceneBitmap : public META_NS::ObjectFwd<SceneBitmap, SCENE_NS::ClassId::Bitmap, META_NS::ClassId::Object,
1068bf80f4bSopenharmony_ci                        SCENE_NS::IBitmap, META_NS::INamed> {
1078bf80f4bSopenharmony_ciprotected:
1088bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(META_NS::INamed, BASE_NS::string, Name)
1098bf80f4bSopenharmony_ci
1108bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::IBitmap, BASE_NS::string, Uri, {})
1118bf80f4bSopenharmony_ci
1128bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_READONLY_PROPERTY(SCENE_NS::IBitmap, BASE_NS::Math::UVec2, Size,
1138bf80f4bSopenharmony_ci        BASE_NS::Math::UVec2(0, 0), META_NS::DEFAULT_PROPERTY_FLAGS_NO_SER)
1148bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_EVENT(SCENE_NS::IBitmap, META_NS::IOnChanged, ResourceChanged)
1158bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_READONLY_PROPERTY(SCENE_NS::IBitmap, SCENE_NS::IBitmap::BitmapStatus, Status,
1168bf80f4bSopenharmony_ci        SCENE_NS::IBitmap::BitmapStatus::NOT_INITIALIZED, META_NS::DEFAULT_PROPERTY_FLAGS_NO_SER)
1178bf80f4bSopenharmony_ci
1188bf80f4bSopenharmony_ci    bool Build(const IMetadata::Ptr& data) override
1198bf80f4bSopenharmony_ci    {
1208bf80f4bSopenharmony_ci        return true;
1218bf80f4bSopenharmony_ci    }
1228bf80f4bSopenharmony_ci    void SetRenderHandle(RENDER_NS::RenderHandleReference handle, const BASE_NS::Math::UVec2 size) override
1238bf80f4bSopenharmony_ci    {
1248bf80f4bSopenharmony_ci        auto cs = META_ACCESS_PROPERTY_VALUE(Size);
1258bf80f4bSopenharmony_ci        if (size != cs) {
1268bf80f4bSopenharmony_ci            META_ACCESS_PROPERTY(Size)->SetValue(size);
1278bf80f4bSopenharmony_ci        }
1288bf80f4bSopenharmony_ci        handle_ = handle;
1298bf80f4bSopenharmony_ci        if (RENDER_NS::RenderHandleUtil::IsValid(handle.GetHandle())) {
1308bf80f4bSopenharmony_ci            META_ACCESS_PROPERTY(Status)->SetValue(SCENE_NS::IBitmap::BitmapStatus::COMPLETED);
1318bf80f4bSopenharmony_ci        } else {
1328bf80f4bSopenharmony_ci            META_ACCESS_PROPERTY(Status)->SetValue(SCENE_NS::IBitmap::BitmapStatus::NOT_INITIALIZED);
1338bf80f4bSopenharmony_ci        }
1348bf80f4bSopenharmony_ci        META_ACCESS_EVENT(ResourceChanged)->Invoke();
1358bf80f4bSopenharmony_ci    }
1368bf80f4bSopenharmony_ci    RENDER_NS::RenderHandleReference GetRenderHandle() const override
1378bf80f4bSopenharmony_ci    {
1388bf80f4bSopenharmony_ci        return handle_;
1398bf80f4bSopenharmony_ci    }
1408bf80f4bSopenharmony_ci
1418bf80f4bSopenharmony_ci    RENDER_NS::RenderHandleReference handle_;
1428bf80f4bSopenharmony_ci};
1438bf80f4bSopenharmony_ci
1448bf80f4bSopenharmony_ciPluginToken RegisterInterfaces(IPluginRegister& pluginRegistry)
1458bf80f4bSopenharmony_ci{
1468bf80f4bSopenharmony_ci    // Initializing dynamic plugin.
1478bf80f4bSopenharmony_ci    // Pluginregistry access via the provided registry instance which is saved here.
1488bf80f4bSopenharmony_ci    gPluginRegistry = &pluginRegistry;
1498bf80f4bSopenharmony_ci    auto& objreg = META_NS::GetObjectRegistry();
1508bf80f4bSopenharmony_ci    objreg.RegisterObjectType<SceneBitmap>();
1518bf80f4bSopenharmony_ci
1528bf80f4bSopenharmony_ci    SCENE_NS::RegisterEcsObject();
1538bf80f4bSopenharmony_ci    SCENE_NS::RegisterNodes();
1548bf80f4bSopenharmony_ci    SCENE_NS::RegisterSceneImpl();
1558bf80f4bSopenharmony_ci    SCENE_NS::RegisterNodeHierarchyController();
1568bf80f4bSopenharmony_ci    SCENE_NS::RegisterEngineAccess();
1578bf80f4bSopenharmony_ci
1588bf80f4bSopenharmony_ci    SCENE_NS::RegisterEcsAnimationObjectType();
1598bf80f4bSopenharmony_ci    META_NS::GetObjectRegistry()
1608bf80f4bSopenharmony_ci        .RegisterObjectType<
1618bf80f4bSopenharmony_ci            SCENE_NS::PendingRequestImpl<SCENE_NS::NodeDistance, SCENE_NS::ClassId::PendingDistanceRequest>>();
1628bf80f4bSopenharmony_ci    META_NS::GetObjectRegistry()
1638bf80f4bSopenharmony_ci        .RegisterObjectType<
1648bf80f4bSopenharmony_ci            SCENE_NS::PendingRequestImpl<RENDER_NS::GraphicsState, SCENE_NS::ClassId::PendingGraphicsStateRequest>>();
1658bf80f4bSopenharmony_ci    META_NS::GetObjectRegistry()
1668bf80f4bSopenharmony_ci        .RegisterObjectType<SCENE_NS::PendingRequestImpl<BASE_NS::Math::Vec3, SCENE_NS::ClassId::PendingVec3Request>>();
1678bf80f4bSopenharmony_ci    return {};
1688bf80f4bSopenharmony_ci}
1698bf80f4bSopenharmony_civoid UnregisterInterfaces(PluginToken)
1708bf80f4bSopenharmony_ci{
1718bf80f4bSopenharmony_ci    /* META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IBloom>();
1728bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IBlur>();
1738bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::ICamera>();
1748bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IColorConversion>();
1758bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IColorFringe>();
1768bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IDepthOfField>();
1778bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IDither>();
1788bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IEcsAnimation>();
1798bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IEcsObject>();
1808bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IEcsScene>();
1818bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IEcsTrackAnimation>();
1828bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IEnvironment>();
1838bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IFxaa>();
1848bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IGraphicsState>();
1858bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::ILight>();
1868bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IMaterial>();
1878bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IMesh>();
1888bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IMultiMeshProxy>();
1898bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IModel>();
1908bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IMotionBlur>();
1918bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::INode>();
1928bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IPostProcess>();
1938bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IPrefab>();
1948bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IPrefabInstance>();
1958bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IScene>();
1968bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IScenePresenter>();
1978bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IShader>();
1988bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::ISubMesh>();
1998bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::ITaa>();
2008bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::ITextureInfo>();
2018bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::ITonemap>();
2028bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IViewNode>();
2038bf80f4bSopenharmony_ci     META_NS::UnRegisterInterfacePropertyType<SCENE_NS::IVignette>();
2048bf80f4bSopenharmony_ci */
2058bf80f4bSopenharmony_ci    SCENE_NS::UnregisterEcsObject();
2068bf80f4bSopenharmony_ci    SCENE_NS::UnregisterNodes();
2078bf80f4bSopenharmony_ci    SCENE_NS::UnregisterSceneImpl();
2088bf80f4bSopenharmony_ci    SCENE_NS::UnregisterNodeHierarchyController();
2098bf80f4bSopenharmony_ci    SCENE_NS::UnregisterEngineAccess();
2108bf80f4bSopenharmony_ci
2118bf80f4bSopenharmony_ci    SCENE_NS::UnregisterEcsAnimationObjectType();
2128bf80f4bSopenharmony_ci
2138bf80f4bSopenharmony_ci    META_NS::GetObjectRegistry()
2148bf80f4bSopenharmony_ci        .UnregisterObjectType<
2158bf80f4bSopenharmony_ci            SCENE_NS::PendingRequestImpl<SCENE_NS::NodeDistance, SCENE_NS::ClassId::PendingDistanceRequest>>();
2168bf80f4bSopenharmony_ci    META_NS::GetObjectRegistry()
2178bf80f4bSopenharmony_ci        .UnregisterObjectType<
2188bf80f4bSopenharmony_ci            SCENE_NS::PendingRequestImpl<RENDER_NS::GraphicsState, SCENE_NS::ClassId::PendingGraphicsStateRequest>>();
2198bf80f4bSopenharmony_ci    META_NS::GetObjectRegistry()
2208bf80f4bSopenharmony_ci        .UnregisterObjectType<
2218bf80f4bSopenharmony_ci            SCENE_NS::PendingRequestImpl<BASE_NS::Math::Vec3, SCENE_NS::ClassId::PendingVec3Request>>();
2228bf80f4bSopenharmony_ci}
2238bf80f4bSopenharmony_ciconst char* VersionString()
2248bf80f4bSopenharmony_ci{
2258bf80f4bSopenharmony_ci    return "1.0";
2268bf80f4bSopenharmony_ci}
2278bf80f4bSopenharmony_ci
2288bf80f4bSopenharmony_ciconst BASE_NS::Uid plugin_deps[] { RENDER_NS::UID_RENDER_PLUGIN, CORE3D_NS::UID_3D_PLUGIN,
2298bf80f4bSopenharmony_ci    META_NS::META_OBJECT_PLUGIN_UID };
2308bf80f4bSopenharmony_ci
2318bf80f4bSopenharmony_ciextern "C" {
2328bf80f4bSopenharmony_ci#if _MSC_VER
2338bf80f4bSopenharmony_ci_declspec(dllexport)
2348bf80f4bSopenharmony_ci#else
2358bf80f4bSopenharmony_ci__attribute__((visibility("default")))
2368bf80f4bSopenharmony_ci#endif
2378bf80f4bSopenharmony_ci    CORE_NS::IPlugin gPluginData { IPlugin::UID, "Scene",
2388bf80f4bSopenharmony_ci        /** Version information of the plugin. */
2398bf80f4bSopenharmony_ci        Version { SCENE_NS::UID_SCENE_PLUGIN, VersionString }, RegisterInterfaces, UnregisterInterfaces, plugin_deps };
2408bf80f4bSopenharmony_ci}
241