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 "gltf_scene_type.h"
17
18 #include <scene/ext/util.h>
19 #include <scene/interface/intf_scene_manager.h>
20 #include <scene/interface/serialization/intf_scene_exporter.h>
21 #include <scene/interface/serialization/intf_scene_importer.h>
22
SCENE_BEGIN_NAMESPACE()23 SCENE_BEGIN_NAMESPACE()
24
25 bool GltfSceneResourceType::Build(const META_NS::IMetadata::Ptr& d)
26 {
27 bool res = Super::Build(d);
28 if (res) {
29 auto context = GetInterfaceBuildArg<IRenderContext>(d, "RenderContext");
30 if (!context) {
31 CORE_LOG_E("Invalid arguments to construct GltfSceneResourceType");
32 return false;
33 }
34 context_ = context;
35 }
36 return res;
37 }
GetResourceName() const38 BASE_NS::string GltfSceneResourceType::GetResourceName() const
39 {
40 return "GltfSceneResource";
41 }
GetResourceType() const42 BASE_NS::Uid GltfSceneResourceType::GetResourceType() const
43 {
44 return ClassId::GltfSceneResource.Id().ToUid();
45 }
LoadResource(const StorageInfo & s) const46 CORE_NS::IResource::Ptr GltfSceneResourceType::LoadResource(const StorageInfo& s) const
47 {
48 CORE_NS::IResource::Ptr res;
49 if (s.payload) {
50 if (auto m = META_NS::GetObjectRegistry().Create<ISceneManager>(
51 ClassId::SceneManager, CreateRenderContextArg(context_.lock()))) {
52 if (auto scene = m->CreateScene(s.path).GetResult()) {
53 res = interface_pointer_cast<CORE_NS::IResource>(scene);
54 }
55 }
56 }
57 return res;
58 }
SaveResource(const CORE_NS::IResource::ConstPtr & p,const StorageInfo & s) const59 bool GltfSceneResourceType::SaveResource(const CORE_NS::IResource::ConstPtr& p, const StorageInfo& s) const
60 {
61 return true;
62 }
ReloadResource(const StorageInfo &,const CORE_NS::IResource::Ptr &) const63 bool GltfSceneResourceType::ReloadResource(const StorageInfo&, const CORE_NS::IResource::Ptr&) const
64 {
65 // todo
66 return false;
67 }
68
69 SCENE_END_NAMESPACE()
70