• 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 "submesh.h"
17 
18 #include "../util.h"
19 
SCENE_BEGIN_NAMESPACE()20 SCENE_BEGIN_NAMESPACE()
21 
22 BASE_NS::string SubMesh::GetName() const
23 {
24     return Name()->GetValue();
25 }
26 
GetSubMesh() const27 CORE3D_NS::MeshComponent::Submesh SubMesh::GetSubMesh() const
28 {
29     submesh_.aabbMin = AABBMin()->GetValue();
30     submesh_.aabbMax = AABBMax()->GetValue();
31     if (auto mat = interface_cast<IEcsObjectAccess>(Material()->GetValue())) {
32         submesh_.material = mat->GetEcsObject()->GetEntity();
33     } else {
34         submesh_.material = CORE_NS::Entity {};
35     }
36     return submesh_;
37 }
SetSubMesh(IEcsContext & context,const CORE3D_NS::MeshComponent::Submesh & sm)38 bool SubMesh::SetSubMesh(IEcsContext& context, const CORE3D_NS::MeshComponent::Submesh& sm)
39 {
40     submesh_ = sm;
41     AABBMin()->SetValue(submesh_.aabbMin);
42     AABBMax()->SetValue(submesh_.aabbMax);
43     if (CORE_NS::EntityUtil::IsValid(submesh_.material)) {
44         if (auto obj = context.GetEcsObject(submesh_.material)) {
45             if (auto mat = META_NS::GetObjectRegistry().Create<IMaterial>(ClassId::Material)) {
46                 if (auto i = interface_cast<IEcsObjectAccess>(mat)) {
47                     if (!i->SetEcsObject(obj)) {
48                         return false;
49                     }
50                 }
51                 Material()->SetValue(mat);
52             }
53         }
54     }
55     return true;
56 }
57 
58 SCENE_END_NAMESPACE()
59