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/environment_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_ciusing namespace BASE_NS; 238bf80f4bSopenharmony_ciusing namespace META_NS; 248bf80f4bSopenharmony_ciusing namespace CORE_NS; 258bf80f4bSopenharmony_ciusing namespace SCENE_NS; 268bf80f4bSopenharmony_ci 278bf80f4bSopenharmony_cinamespace { 288bf80f4bSopenharmony_ci 298bf80f4bSopenharmony_cistatic constexpr Math::Vec4 ZERO = Math::Vec4(0.0f, 0.0f, 0.0f, 0.0f); 308bf80f4bSopenharmony_cistatic constexpr Math::Vec4 ONE = Math::Vec4(1.0f, 1.0f, 1.0f, 1.0f); 318bf80f4bSopenharmony_ci 328bf80f4bSopenharmony_ciclass EnvImpl : public ConcreteBaseMetaObjectFwd<EnvImpl, NodeImpl, SCENE_NS::ClassId::Environment, IEnvironment> { 338bf80f4bSopenharmony_ci using Super = ConcreteBaseMetaObjectFwd<EnvImpl, NodeImpl, SCENE_NS::ClassId::Environment, IEnvironment>; 348bf80f4bSopenharmony_ci 358bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY( 368bf80f4bSopenharmony_ci IEnvironment, IEnvironment::BackgroundType, Background, IEnvironment::BackgroundType::NONE) 378bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(IEnvironment, Math::Vec4, IndirectDiffuseFactor, ONE) 388bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(IEnvironment, Math::Vec4, IndirectSpecularFactor, ONE) 398bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(IEnvironment, Math::Vec4, EnvMapFactor, ONE) 408bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::IEnvironment, IBitmap::Ptr, RadianceImage, {}) 418bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(IEnvironment, uint32_t, RadianceCubemapMipCount, 0) 428bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::IEnvironment, IBitmap::Ptr, EnvironmentImage, {}) 438bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(IEnvironment, float, EnvironmentMapLodLevel, 0.0f) 448bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_ARRAY_PROPERTY( 458bf80f4bSopenharmony_ci IEnvironment, Math::Vec3, IrradianceCoefficients, {}) 468bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(IEnvironment, Math::Quat, EnvironmentRotation, Math::Quat(0.f, 0.f, 0.f, 1.f)) 478bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY(SCENE_NS::IEnvironment, Math::Vec4, AdditionalFactor, ZERO) 488bf80f4bSopenharmony_ci META_IMPLEMENT_INTERFACE_PROPERTY( 498bf80f4bSopenharmony_ci IEnvironment, uint64_t, ShaderHandle, CORE_NS::Entity {}.id) 508bf80f4bSopenharmony_ci 518bf80f4bSopenharmony_ci static constexpr string_view ENV_COMPONENT_NAME = "EnvironmentComponent"; 528bf80f4bSopenharmony_ci static constexpr size_t ENV_COMPONENT_NAME_LEN = ENV_COMPONENT_NAME.size() + 1; 538bf80f4bSopenharmony_ci static constexpr string_view ENV_BG = "EnvironmentComponent.background"; 548bf80f4bSopenharmony_ci static constexpr string_view ENV_DF = "EnvironmentComponent.indirectDiffuseFactor"; 558bf80f4bSopenharmony_ci static constexpr string_view ENV_SF = "EnvironmentComponent.indirectSpecularFactor"; 568bf80f4bSopenharmony_ci static constexpr string_view ENV_MF = "EnvironmentComponent.envMapFactor"; 578bf80f4bSopenharmony_ci static constexpr string_view ENV_CH = "EnvironmentComponent.radianceCubemap"; 588bf80f4bSopenharmony_ci static constexpr string_view ENV_CMC = "EnvironmentComponent.radianceCubemapMipCount"; 598bf80f4bSopenharmony_ci static constexpr string_view ENV_MH = "EnvironmentComponent.envMap"; 608bf80f4bSopenharmony_ci static constexpr string_view ENV_MLL = "EnvironmentComponent.envMapLodLevel"; 618bf80f4bSopenharmony_ci static constexpr string_view ENV_IC = "EnvironmentComponent.irradianceCoefficients"; 628bf80f4bSopenharmony_ci static constexpr size_t ENV_IC_SIZE = ENV_IC.size(); 638bf80f4bSopenharmony_ci static constexpr string_view ENV_ER = "EnvironmentComponent.environmentRotation"; 648bf80f4bSopenharmony_ci static constexpr string_view ENV_AF = "EnvironmentComponent.additionalFactor"; 658bf80f4bSopenharmony_ci static constexpr string_view ENV_SH = "EnvironmentComponent.shader"; 668bf80f4bSopenharmony_ci 678bf80f4bSopenharmony_ci bool Build(const IMetadata::Ptr& data) override 688bf80f4bSopenharmony_ci { 698bf80f4bSopenharmony_ci bool ret = false; 708bf80f4bSopenharmony_ci if (ret = Super::Build(data); ret) { 718bf80f4bSopenharmony_ci PropertyNameMask()[ENV_COMPONENT_NAME] = { ENV_BG.substr(ENV_COMPONENT_NAME_LEN), 728bf80f4bSopenharmony_ci ENV_DF.substr(ENV_COMPONENT_NAME_LEN), ENV_SF.substr(ENV_COMPONENT_NAME_LEN), 738bf80f4bSopenharmony_ci ENV_MF.substr(ENV_COMPONENT_NAME_LEN), ENV_CH.substr(ENV_COMPONENT_NAME_LEN), 748bf80f4bSopenharmony_ci ENV_CMC.substr(ENV_COMPONENT_NAME_LEN), ENV_MH.substr(ENV_COMPONENT_NAME_LEN), 758bf80f4bSopenharmony_ci ENV_MLL.substr(ENV_COMPONENT_NAME_LEN), ENV_IC.substr(ENV_COMPONENT_NAME_LEN), 768bf80f4bSopenharmony_ci ENV_ER.substr(ENV_COMPONENT_NAME_LEN), ENV_AF.substr(ENV_COMPONENT_NAME_LEN), 778bf80f4bSopenharmony_ci ENV_SH.substr(ENV_COMPONENT_NAME_LEN) }; 788bf80f4bSopenharmony_ci DisableInputHandling(); 798bf80f4bSopenharmony_ci } 808bf80f4bSopenharmony_ci return ret; 818bf80f4bSopenharmony_ci } 828bf80f4bSopenharmony_ci 838bf80f4bSopenharmony_ci bool CompleteInitialization(const string& path) override 848bf80f4bSopenharmony_ci { 858bf80f4bSopenharmony_ci if (!NodeImpl::CompleteInitialization(path)) { 868bf80f4bSopenharmony_ci return false; 878bf80f4bSopenharmony_ci } 888bf80f4bSopenharmony_ci 898bf80f4bSopenharmony_ci if (auto meta = interface_pointer_cast<IMetadata>(ecsObject_)) { 908bf80f4bSopenharmony_ci ConvertBindChanges<IEnvironment::BackgroundType, uint8_t>( 918bf80f4bSopenharmony_ci propHandler_, META_ACCESS_PROPERTY(Background), meta, ENV_BG); 928bf80f4bSopenharmony_ci BindChanges<Math::Vec4>(propHandler_, META_ACCESS_PROPERTY(IndirectDiffuseFactor), meta, ENV_DF); 938bf80f4bSopenharmony_ci BindChanges<Math::Vec4>(propHandler_, META_ACCESS_PROPERTY(IndirectSpecularFactor), meta, ENV_SF); 948bf80f4bSopenharmony_ci BindChanges<Math::Vec4>(propHandler_, META_ACCESS_PROPERTY(EnvMapFactor), meta, ENV_MF); 958bf80f4bSopenharmony_ci 968bf80f4bSopenharmony_ci ConvertBindChanges<IBitmap::Ptr, EntityReference, ImageConverter>( 978bf80f4bSopenharmony_ci propHandler_, META_ACCESS_PROPERTY(RadianceImage), meta, ENV_CH); 988bf80f4bSopenharmony_ci 998bf80f4bSopenharmony_ci ConvertBindChanges<IBitmap::Ptr, EntityReference, ImageConverter>( 1008bf80f4bSopenharmony_ci propHandler_, META_ACCESS_PROPERTY(EnvironmentImage), meta, ENV_MH); 1018bf80f4bSopenharmony_ci 1028bf80f4bSopenharmony_ci BindChanges<uint32_t>(propHandler_, META_ACCESS_PROPERTY(RadianceCubemapMipCount), meta, ENV_CMC); 1038bf80f4bSopenharmony_ci BindChanges<float>(propHandler_, META_ACCESS_PROPERTY(EnvironmentMapLodLevel), meta, ENV_MLL); 1048bf80f4bSopenharmony_ci BindChanges<Math::Quat>(propHandler_, META_ACCESS_PROPERTY(EnvironmentRotation), meta, ENV_ER); 1058bf80f4bSopenharmony_ci BindChanges<Math::Vec4>(propHandler_, META_ACCESS_PROPERTY(AdditionalFactor), meta, ENV_AF); 1068bf80f4bSopenharmony_ci BindChanges<uint64_t>(propHandler_, META_ACCESS_PROPERTY(ShaderHandle), meta, ENV_SH); 1078bf80f4bSopenharmony_ci 1088bf80f4bSopenharmony_ci BindChanges<Math::Vec3>(propHandler_, META_ACCESS_PROPERTY(IrradianceCoefficients), meta, ENV_IC); 1098bf80f4bSopenharmony_ci } 1108bf80f4bSopenharmony_ci 1118bf80f4bSopenharmony_ci return true; 1128bf80f4bSopenharmony_ci } 1138bf80f4bSopenharmony_ci 1148bf80f4bSopenharmony_ci}; 1158bf80f4bSopenharmony_ci} // namespace 1168bf80f4bSopenharmony_ciSCENE_BEGIN_NAMESPACE() 1178bf80f4bSopenharmony_ci 1188bf80f4bSopenharmony_civoid RegisterEnvImpl() 1198bf80f4bSopenharmony_ci{ 1208bf80f4bSopenharmony_ci auto& registry = GetObjectRegistry(); 1218bf80f4bSopenharmony_ci registry.RegisterObjectType<EnvImpl>(); 1228bf80f4bSopenharmony_ci} 1238bf80f4bSopenharmony_civoid UnregisterEnvImpl() 1248bf80f4bSopenharmony_ci{ 1258bf80f4bSopenharmony_ci auto& registry = GetObjectRegistry(); 1268bf80f4bSopenharmony_ci registry.UnregisterObjectType<EnvImpl>(); 1278bf80f4bSopenharmony_ci} 1288bf80f4bSopenharmony_ciSCENE_END_NAMESPACE() 129