• 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 "scene_type.h"
17 
18 #include <scene/ext/util.h>
19 #include <scene/interface/serialization/intf_scene_exporter.h>
20 #include <scene/interface/serialization/intf_scene_importer.h>
21 
SCENE_BEGIN_NAMESPACE()22 SCENE_BEGIN_NAMESPACE()
23 
24 bool SceneResourceType::Build(const META_NS::IMetadata::Ptr& d)
25 {
26     bool res = Super::Build(d);
27     if (res) {
28         auto context = GetInterfaceBuildArg<IRenderContext>(d, "RenderContext");
29         if (!context) {
30             CORE_LOG_E("Invalid arguments to construct SceneResourceType");
31             return false;
32         }
33         opts_ = GetBuildArg<SceneOptions>(d, "Options");
34         context_ = context;
35     }
36     return res;
37 }
GetResourceName() const38 BASE_NS::string SceneResourceType::GetResourceName() const
39 {
40     return "SceneResource";
41 }
GetResourceType() const42 BASE_NS::Uid SceneResourceType::GetResourceType() const
43 {
44     return ClassId::SceneResource.Id().ToUid();
45 }
LoadResource(const StorageInfo & s) const46 CORE_NS::IResource::Ptr SceneResourceType::LoadResource(const StorageInfo& s) const
47 {
48     CORE_NS::IResource::Ptr res;
49     if (s.payload) {
50         auto md = CreateRenderContextArg(context_.lock());
51         if (md) {
52             md->AddProperty(META_NS::ConstructProperty<SceneOptions>("Options", opts_));
53         }
54         auto importer = META_NS::GetObjectRegistry().Create<ISceneImporter>(ClassId::SceneImporter, md);
55         res = interface_pointer_cast<CORE_NS::IResource>(importer->ImportScene(*s.payload));
56     }
57     return res;
58 }
SaveResource(const CORE_NS::IResource::ConstPtr & p,const StorageInfo & s) const59 bool SceneResourceType::SaveResource(const CORE_NS::IResource::ConstPtr& p, const StorageInfo& s) const
60 {
61     bool res = true;
62     if (s.payload) {
63         if (auto scene = interface_pointer_cast<IScene>(p)) {
64             auto exporter = META_NS::GetObjectRegistry().Create<ISceneExporter>(
65                 ClassId::SceneExporter, CreateRenderContextArg(context_.lock()));
66             res = exporter->ExportScene(*s.payload, scene);
67         }
68     }
69     return res;
70 }
ReloadResource(const StorageInfo &,const CORE_NS::IResource::Ptr &) const71 bool SceneResourceType::ReloadResource(const StorageInfo&, const CORE_NS::IResource::Ptr&) const
72 {
73     // todo
74     return false;
75 }
76 
77 SCENE_END_NAMESPACE()
78