• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SCENE_SRC_MESH_MATERIAL_H
17 #define SCENE_SRC_MESH_MATERIAL_H
18 
19 #include <scene/ext/intf_create_entity.h>
20 #include <scene/ext/named_scene_object.h>
21 #include <scene/interface/intf_material.h>
22 
23 #include <meta/ext/implementation_macros.h>
24 #include <meta/ext/object.h>
25 
26 #include "component/material_component.h"
27 
SCENE_BEGIN_NAMESPACE()28 SCENE_BEGIN_NAMESPACE()
29 
30 class Material : public META_NS::IntroduceInterfaces<NamedSceneObject, IMaterial, ICreateEntity> {
31     META_OBJECT(Material, ClassId::Material, IntroduceInterfaces)
32 
33 public:
34     bool SetEcsObject(const IEcsObject::Ptr&) override;
35     bool InitDynamicProperty(const META_NS::IProperty::Ptr& p, BASE_NS::string_view path) override;
36 
37 public:
38     META_FORWARD_PROPERTY(MaterialType, Type, material_->Type())
39     META_FORWARD_PROPERTY(float, AlphaCutoff, material_->AlphaCutoff())
40 
41     META_BEGIN_STATIC_DATA()
42     SCENE_STATIC_DYNINIT_PROPERTY_DATA(IMaterial, IShader::Ptr, MaterialShader, "MaterialComponent.materialShader")
43     SCENE_STATIC_DYNINIT_PROPERTY_DATA(IMaterial, IShader::Ptr, DepthShader, "MaterialComponent.depthShader")
44     SCENE_STATIC_DYNINIT_PROPERTY_DATA(IMaterial, SCENE_NS::RenderSort, RenderSort, "")
45     SCENE_STATIC_DYNINIT_PROPERTY_DATA(IMaterial, SCENE_NS::LightingFlags, LightingFlags, "")
46     SCENE_STATIC_DYNINIT_ARRAY_PROPERTY_DATA(IMaterial, ITexture::Ptr, Textures, "")
47     META_END_STATIC_DATA()
48 
49     META_IMPLEMENT_PROPERTY(IShader::Ptr, MaterialShader)
50     META_IMPLEMENT_PROPERTY(IShader::Ptr, DepthShader)
51     META_IMPLEMENT_READONLY_ARRAY_PROPERTY(ITexture::Ptr, Textures)
52     META_IMPLEMENT_PROPERTY(SCENE_NS::RenderSort, RenderSort)
53     META_IMPLEMENT_PROPERTY(SCENE_NS::LightingFlags, LightingFlags)
54 
55     META_NS::IMetadata::Ptr GetCustomProperties() const override;
56     META_NS::IProperty::Ptr GetCustomProperty(BASE_NS::string_view name) const override;
57 
58     CORE_NS::Entity CreateEntity(const IInternalScene::Ptr& scene) override;
59 
60 private:
61     bool ConstructTextures(const META_NS::IProperty::Ptr& p);
62     /**
63      * @brief Synchronize custom properties from ECS to engine and construct engine values for them.
64      * @param synced_values If not null pointer, store the synced engine values here.
65      * @return True if succeeded, false otherwise.
66      */
67     bool SyncCustomProperties(BASE_NS::vector<META_NS::IEngineValue::Ptr>* synced_values) const;
68 
69 private:
70     IInternalMaterial::Ptr material_;
71 };
72 
73 SCENE_END_NAMESPACE()
74 
75 #endif