• 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_API_EXTERNAL_NODE_H
17 #define SCENE_API_EXTERNAL_NODE_H
18 
19 #include <scene/interface/intf_external_node.h>
20 #include <scene/interface/intf_node_import.h>
21 #include <scene/interface/intf_scene.h>
22 
23 #include <core/resources/intf_resource.h>
24 
25 #include <meta/interface/intf_attach.h>
26 
SCENE_BEGIN_NAMESPACE()27 SCENE_BEGIN_NAMESPACE()
28 
29 inline INode::Ptr AddExternalNode(INode& parent, const IScene::Ptr& external, BASE_NS::string_view nodeName)
30 {
31     INode::Ptr node;
32     if (auto i = interface_cast<INodeImport>(&parent)) {
33         node = i->ImportChildScene(external, nodeName).GetResult();
34         if (node) {
35             if (auto ext = META_NS::GetObjectRegistry().Create<IExternalNode>(ClassId::ExternalNode)) {
36                 if (auto att = interface_cast<META_NS::IAttach>(node)) {
37                     if (auto res = interface_cast<CORE_NS::IResource>(external)) {
38                         ext->SetResourceId(res->GetResourceId());
39                     }
40                     att->Attach(ext);
41                 }
42             }
43         }
44     }
45     return node;
46 }
47 
48 SCENE_END_NAMESPACE()
49 
50 #endif // SCENE_API_EXTERNAL_NODE_H
51