• 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 #include "light_node.h"
17 
18 #include <3d/ecs/components/light_component.h>
19 #include <3d/ecs/components/local_matrix_component.h>
20 #include <3d/ecs/components/name_component.h>
21 #include <3d/ecs/components/node_component.h>
22 #include <3d/ecs/components/transform_component.h>
23 #include <3d/ecs/components/world_matrix_component.h>
24 #include <core/ecs/intf_ecs.h>
25 
SCENE_BEGIN_NAMESPACE()26 SCENE_BEGIN_NAMESPACE()
27 
28 CORE_NS::Entity LightNode::CreateEntity(const IInternalScene::Ptr& scene)
29 {
30     // make directly light entity by hand, we don't want to upgrade (and wait fix) Lume3D to use sceneUtil.CreateLight
31     // (will be used in future)
32     auto ecs = scene->GetEcsContext().GetNativeEcs();
33 
34     auto lmm = CORE_NS::GetManager<CORE3D_NS::ILocalMatrixComponentManager>(*ecs);
35     auto wmm = CORE_NS::GetManager<CORE3D_NS::IWorldMatrixComponentManager>(*ecs);
36     auto ncm = CORE_NS::GetManager<CORE3D_NS::INodeComponentManager>(*ecs);
37     auto nameM = CORE_NS::GetManager<CORE3D_NS::INameComponentManager>(*ecs);
38     auto tcm = CORE_NS::GetManager<CORE3D_NS::ITransformComponentManager>(*ecs);
39     auto lcm = CORE_NS::GetManager<CORE3D_NS::ILightComponentManager>(*ecs);
40     if (!lmm || !wmm || !ncm || !nameM || !tcm || !lcm) {
41         return {};
42     }
43 
44     auto light = ecs->GetEntityManager().Create();
45 
46     lmm->Create(light);
47     wmm->Create(light);
48     ncm->Create(light);
49     nameM->Create(light);
50     nameM->Write(light)->name = "Light";
51     tcm->Create(light);
52     lcm->Create(light);
53 
54     return light;
55 }
56 
SetEcsObject(const IEcsObject::Ptr & o)57 bool LightNode::SetEcsObject(const IEcsObject::Ptr& o)
58 {
59     if (Super::SetEcsObject(o)) {
60         auto att = GetSelf<META_NS::IAttach>()->GetAttachments<ILight>();
61         if (!att.empty()) {
62             return true;
63         }
64     }
65     return false;
66 }
67 
68 SCENE_END_NAMESPACE()