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#include <scene_plugin/api/light_uid.h>
168bf80f4bSopenharmony_ci
178bf80f4bSopenharmony_ci#include <meta/ext/concrete_base_object.h>
188bf80f4bSopenharmony_ci
198bf80f4bSopenharmony_ci#include "bind_templates.inl"
208bf80f4bSopenharmony_ci#include "node_impl.h"
218bf80f4bSopenharmony_ci
228bf80f4bSopenharmony_cinamespace {
238bf80f4bSopenharmony_ciclass LightImpl
248bf80f4bSopenharmony_ci    : public META_NS::ConcreteBaseMetaObjectFwd<LightImpl, NodeImpl, SCENE_NS::ClassId::Light, SCENE_NS::ILight> {
258bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_COMPONENT_NAME = "LightComponent";
268bf80f4bSopenharmony_ci    static constexpr size_t LIGHT_COMPONENT_NAME_LEN = LIGHT_COMPONENT_NAME.size() + 1;
278bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_COLOR = "LightComponent.color";
288bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_INTENSITY = "LightComponent.intensity";
298bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_NEARPLANE = "LightComponent.nearPlane";
308bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_SHADOWENABLED = "LightComponent.shadowEnabled";
318bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_SHADOWSTRENGTH = "LightComponent.shadowStrength";
328bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_SHADOWDEPTHBIAS = "LightComponent.shadowDepthBias";
338bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_SHADOWNORMALBIAS = "LightComponent.shadowNormalBias";
348bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_SPOTINNERANGLE = "LightComponent.spotInnerAngle";
358bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_SPOTOUTERANGLE = "LightComponent.spotOuterAngle";
368bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_TYPE = "LightComponent.type";
378bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_ADDITIONALFACTOR = "LightComponent.additionalFactor";
388bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_LAYERMASK = "LightComponent.lightLayerMask";
398bf80f4bSopenharmony_ci    static constexpr BASE_NS::string_view LIGHT_SHADOWLAYERMASK = "LightComponent.shadowLayerMask";
408bf80f4bSopenharmony_ci
418bf80f4bSopenharmony_ci    bool Build(const IMetadata::Ptr& data) override
428bf80f4bSopenharmony_ci    {
438bf80f4bSopenharmony_ci        bool ret = false;
448bf80f4bSopenharmony_ci        if (ret = NodeImpl::Build(data); ret) {
458bf80f4bSopenharmony_ci            PropertyNameMask()[LIGHT_COMPONENT_NAME] = { LIGHT_COLOR.substr(LIGHT_COMPONENT_NAME_LEN),
468bf80f4bSopenharmony_ci                LIGHT_INTENSITY.substr(LIGHT_COMPONENT_NAME_LEN), LIGHT_NEARPLANE.substr(LIGHT_COMPONENT_NAME_LEN),
478bf80f4bSopenharmony_ci                LIGHT_SHADOWENABLED.substr(LIGHT_COMPONENT_NAME_LEN),
488bf80f4bSopenharmony_ci                LIGHT_SHADOWSTRENGTH.substr(LIGHT_COMPONENT_NAME_LEN),
498bf80f4bSopenharmony_ci                LIGHT_SHADOWDEPTHBIAS.substr(LIGHT_COMPONENT_NAME_LEN),
508bf80f4bSopenharmony_ci                LIGHT_SHADOWNORMALBIAS.substr(LIGHT_COMPONENT_NAME_LEN),
518bf80f4bSopenharmony_ci                LIGHT_SPOTINNERANGLE.substr(LIGHT_COMPONENT_NAME_LEN),
528bf80f4bSopenharmony_ci                LIGHT_SPOTOUTERANGLE.substr(LIGHT_COMPONENT_NAME_LEN), LIGHT_TYPE.substr(LIGHT_COMPONENT_NAME_LEN),
538bf80f4bSopenharmony_ci                LIGHT_ADDITIONALFACTOR.substr(LIGHT_COMPONENT_NAME_LEN),
548bf80f4bSopenharmony_ci                LIGHT_LAYERMASK.substr(LIGHT_COMPONENT_NAME_LEN),
558bf80f4bSopenharmony_ci                LIGHT_SHADOWLAYERMASK.substr(LIGHT_COMPONENT_NAME_LEN) };
568bf80f4bSopenharmony_ci            DisableInputHandling();
578bf80f4bSopenharmony_ci        }
588bf80f4bSopenharmony_ci        return ret;
598bf80f4bSopenharmony_ci    }
608bf80f4bSopenharmony_ci
618bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(
628bf80f4bSopenharmony_ci        SCENE_NS::ILight, SCENE_NS::Color, Color, SCENE_NS::Colors::WHITE)
638bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::ILight, float, Intensity, 1.f)
648bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::ILight, float, NearPlane, 0.5f)
658bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(
668bf80f4bSopenharmony_ci        SCENE_NS::ILight, bool, ShadowEnabled, true)
678bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(
688bf80f4bSopenharmony_ci        SCENE_NS::ILight, float, ShadowStrength, 1.0f)
698bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(
708bf80f4bSopenharmony_ci        SCENE_NS::ILight, float, ShadowDepthBias, 0.005f)
718bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(
728bf80f4bSopenharmony_ci        SCENE_NS::ILight, float, ShadowNormalBias, 0.025f)
738bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(
748bf80f4bSopenharmony_ci        SCENE_NS::ILight, float, SpotInnerAngle, 0.f)
758bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(
768bf80f4bSopenharmony_ci        SCENE_NS::ILight, float, SpotOuterAngle, 0.78539816339f)
778bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::ILight, uint8_t, Type,
788bf80f4bSopenharmony_ci        SCENE_NS::ILight::SceneLightType::SCENE_LIGHT_DIRECTIONAL)
798bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::ILight, BASE_NS::Math::Vec4, AdditionalFactor,
808bf80f4bSopenharmony_ci        BASE_NS::Math::Vec4(0.f, 0.f, 0.f, 0.f))
818bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::ILight, uint64_t, LightLayerMask, CORE3D_NS::CORE_LAYER_FLAG_BIT_ALL)
828bf80f4bSopenharmony_ci    META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::ILight, uint64_t, ShadowLayerMask, CORE3D_NS::CORE_LAYER_FLAG_BIT_ALL)
838bf80f4bSopenharmony_ci
848bf80f4bSopenharmony_ci    bool CompleteInitialization(const BASE_NS::string& path) override
858bf80f4bSopenharmony_ci    {
868bf80f4bSopenharmony_ci        if (!NodeImpl::CompleteInitialization(path)) {
878bf80f4bSopenharmony_ci            return false;
888bf80f4bSopenharmony_ci        }
898bf80f4bSopenharmony_ci
908bf80f4bSopenharmony_ci        auto meta = interface_pointer_cast<META_NS::IMetadata>(ecsObject_);
918bf80f4bSopenharmony_ci        BASE_NS::vector<size_t> slots = { 0, 0, 1, 1, 2, 2 };
928bf80f4bSopenharmony_ci        BindSlottedChanges<BASE_NS::Math::Vec3, SCENE_NS::Color>(
938bf80f4bSopenharmony_ci            propHandler_, META_ACCESS_PROPERTY(Color), meta, LIGHT_COLOR, slots);
948bf80f4bSopenharmony_ci        BindChanges<float>(propHandler_, META_ACCESS_PROPERTY(Intensity), meta, LIGHT_INTENSITY);
958bf80f4bSopenharmony_ci        BindChanges<float>(propHandler_, META_ACCESS_PROPERTY(NearPlane), meta, LIGHT_NEARPLANE);
968bf80f4bSopenharmony_ci        BindChanges<bool>(propHandler_, META_ACCESS_PROPERTY(ShadowEnabled), meta, LIGHT_SHADOWENABLED);
978bf80f4bSopenharmony_ci        BindChanges<float>(propHandler_, META_ACCESS_PROPERTY(ShadowStrength), meta, LIGHT_SHADOWSTRENGTH);
988bf80f4bSopenharmony_ci        BindChanges<float>(propHandler_, META_ACCESS_PROPERTY(ShadowDepthBias), meta, LIGHT_SHADOWDEPTHBIAS);
998bf80f4bSopenharmony_ci        BindChanges<float>(propHandler_, META_ACCESS_PROPERTY(ShadowNormalBias), meta, LIGHT_SHADOWNORMALBIAS);
1008bf80f4bSopenharmony_ci        BindChanges<float>(propHandler_, META_ACCESS_PROPERTY(SpotInnerAngle), meta, LIGHT_SPOTINNERANGLE);
1018bf80f4bSopenharmony_ci        BindChanges<float>(propHandler_, META_ACCESS_PROPERTY(SpotOuterAngle), meta, LIGHT_SPOTOUTERANGLE);
1028bf80f4bSopenharmony_ci        BindChanges<uint8_t>(propHandler_, META_ACCESS_PROPERTY(Type), meta, LIGHT_TYPE);
1038bf80f4bSopenharmony_ci        BindChanges<BASE_NS::Math::Vec4>(
1048bf80f4bSopenharmony_ci            propHandler_, META_ACCESS_PROPERTY(AdditionalFactor), meta, LIGHT_ADDITIONALFACTOR);
1058bf80f4bSopenharmony_ci        BindChanges<uint64_t>(propHandler_, META_ACCESS_PROPERTY(LightLayerMask), meta, LIGHT_LAYERMASK);
1068bf80f4bSopenharmony_ci        BindChanges<uint64_t>(propHandler_, META_ACCESS_PROPERTY(ShadowLayerMask), meta, LIGHT_SHADOWLAYERMASK);
1078bf80f4bSopenharmony_ci
1088bf80f4bSopenharmony_ci        return true;
1098bf80f4bSopenharmony_ci    }
1108bf80f4bSopenharmony_ci
1118bf80f4bSopenharmony_ci    virtual ~LightImpl() {}
1128bf80f4bSopenharmony_ci};
1138bf80f4bSopenharmony_ci} // namespace
1148bf80f4bSopenharmony_ciSCENE_BEGIN_NAMESPACE()
1158bf80f4bSopenharmony_civoid RegisterLightImpl()
1168bf80f4bSopenharmony_ci{
1178bf80f4bSopenharmony_ci    META_NS::GetObjectRegistry().RegisterObjectType<LightImpl>();
1188bf80f4bSopenharmony_ci}
1198bf80f4bSopenharmony_civoid UnregisterLightImpl()
1208bf80f4bSopenharmony_ci{
1218bf80f4bSopenharmony_ci    META_NS::GetObjectRegistry().UnregisterObjectType<LightImpl>();
1228bf80f4bSopenharmony_ci}
1238bf80f4bSopenharmony_ciSCENE_END_NAMESPACE()