• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 CORE_ECS_SKINNINGSYSTEM_H
17 #define CORE_ECS_SKINNINGSYSTEM_H
18 
19 #include <ComponentTools/component_query.h>
20 #include <PropertyTools/property_api_impl.h>
21 
22 #include <3d/ecs/systems/intf_skinning_system.h>
23 #include <base/math/matrix.h>
24 #include <core/namespace.h>
25 
26 CORE3D_BEGIN_NAMESPACE()
27 class INodeComponentManager;
28 class ISkinComponentManager;
29 class ISkinIbmComponentManager;
30 class ISkinJointsComponentManager;
31 class IJointMatricesComponentManager;
32 class IPreviousJointMatricesComponentManager;
33 class IWorldMatrixComponentManager;
34 class INodeSystem;
35 class ICameraComponentManager;
36 class ILightComponentManager;
37 class IMeshComponentManager;
38 class IRenderMeshComponentManager;
39 class IPicking;
40 
41 struct JointMatricesComponent;
42 
43 class SkinningSystem final : public ISkinningSystem {
44 public:
45     explicit SkinningSystem(CORE_NS::IEcs& ecs);
46     ~SkinningSystem() override = default;
47     BASE_NS::string_view GetName() const override;
48     BASE_NS::Uid GetUid() const override;
49     CORE_NS::IPropertyHandle* GetProperties() override;
50     const CORE_NS::IPropertyHandle* GetProperties() const override;
51     void SetProperties(const CORE_NS::IPropertyHandle&) override;
52 
53     bool IsActive() const override;
54     void SetActive(bool state) override;
55 
56     void Initialize() override;
57     bool Update(bool frameRenderingQueued, uint64_t time, uint64_t delta) override;
58     void Uninitialize() override;
59 
60     const CORE_NS::IEcs& GetECS() const override;
61 
62     void CreateInstance(CORE_NS::Entity const& skinIbmEntity, BASE_NS::array_view<const CORE_NS::Entity> const& joints,
63         CORE_NS::Entity const& entity, CORE_NS::Entity const& skeleton) override;
64     void DestroyInstance(CORE_NS::Entity const& entity) override;
65 
66 private:
67     void UpdateSkin(const CORE_NS::ComponentQuery::ResultRow& row);
68     void UpdateJointTransformations(bool isEnabled, const BASE_NS::array_view<CORE_NS::Entity const>& jointEntities,
69         const BASE_NS::array_view<BASE_NS::Math::Mat4X4 const>& iblMatrices, JointMatricesComponent& jointMatrices,
70         const BASE_NS::Math::Mat4X4& skinEntityWorldInverse);
71 
72     bool active_;
73     CORE_NS::IEcs& ecs_;
74 
75     IPicking& picking_;
76 
77     ISkinComponentManager& skinManager_;
78     ISkinIbmComponentManager& skinIbmManager_;
79     ISkinJointsComponentManager& skinJointsManager_;
80     IJointMatricesComponentManager& jointMatricesManager_;
81     IPreviousJointMatricesComponentManager& previousJointMatricesManager_;
82     IWorldMatrixComponentManager& worldMatrixManager_;
83     INodeComponentManager& nodeManager_;
84     IRenderMeshComponentManager& renderMeshManager_;
85     IMeshComponentManager& meshManager_;
86     INodeSystem* nodeSystem_ = nullptr;
87 
88     CORE_NS::ComponentQuery componentQuery_;
89 
90     uint32_t worldMatrixGeneration_ { 0 };
91     uint32_t jointMatricesGeneration_ { 0 };
92     CORE_NS::PropertyApiImpl<void> SKINNING_SYSTEM_PROPERTIES;
93 };
94 CORE3D_END_NAMESPACE()
95 
96 #endif // CORE_ECS_SKINNINGSYSTEM_H
97