@@ -13,35 +13,39 @@ namespace nbl
13
13
namespace asset
14
14
{
15
15
16
- class ICPUSkeleton : public ISkeleton <ICPUBuffer>, /* TODO: public BlobSerializable, */ public IAsset
16
+ class ICPUSkeleton final : public ISkeleton<ICPUBuffer>, /* TODO: public BlobSerializable, */ public IAsset
17
17
{
18
18
public:
19
- using Base = ISkeleton<ICPUBuffer>;
19
+ using base_t = ISkeleton<ICPUBuffer>;
20
20
21
21
template <typename NameIterator>
22
- ICPUSkeleton (SBufferBinding<BufferType >&& _parentJointIDsBinding, SBufferBinding<BufferType >&& _inverseBindPosesBinding, NameIterator begin, NameIterator end) : Base (std::move(_parentJointIDsBinding),std::move(_inverseBindPosesBinding))
22
+ inline ICPUSkeleton (SBufferBinding<ICPUBuffer >&& _parentJointIDsBinding, SBufferBinding<ICPUBuffer >&& _inverseBindPosesBinding, NameIterator begin, NameIterator end) : base_t (std::move(_parentJointIDsBinding),std::move(_inverseBindPosesBinding),std::distance(begin,end ))
23
23
{
24
- Base ::setJointNames<NameIterator>(begin,end);
24
+ base_t ::setJointNames<NameIterator>(begin,end);
25
25
}
26
+ template <typename ... Args>
27
+ inline ICPUSkeleton (Args&&... args) : base_t(std::forward<Args>(args)...) {}
26
28
27
29
//
28
- inline const core::matrix3x4SIMD& getInversePoseBindMatrix (Base ::joint_id_t jointID) const
30
+ inline const core::matrix3x4SIMD& getInversePoseBindMatrix (base_t ::joint_id_t jointID) const
29
31
{
30
- return reinterpret_cast <const core::matrix3x4SIMD*>(m_inverseBindPoses.buffer ->getPointer ()+m_inverseBindPoses.offset )[jointID];
32
+ const uint8_t * ptr = reinterpret_cast <const uint8_t *>(m_inverseBindPoses.buffer ->getPointer ());
33
+ return reinterpret_cast <const core::matrix3x4SIMD*>(ptr+m_inverseBindPoses.offset )[jointID];
31
34
}
32
- inline core::matrix3x4SIMD& getInversePoseBindMatrix (Base ::joint_id_t jointID)
35
+ inline core::matrix3x4SIMD& getInversePoseBindMatrix (base_t ::joint_id_t jointID)
33
36
{
34
37
return const_cast <core::matrix3x4SIMD&>(const_cast <const ICPUSkeleton*>(this )->getInversePoseBindMatrix (jointID));
35
38
}
36
39
37
40
//
38
- inline const Base ::joint_id_t & getParentJointID (Base ::joint_id_t jointID) const
41
+ inline const base_t ::joint_id_t & getParentJointID (base_t ::joint_id_t jointID) const
39
42
{
40
- return reinterpret_cast <const Base::joint_id_t *>(m_parentJointIDs.buffer ->getPointer ()+m_parentJointIDs.offset )[jointID];
43
+ const uint8_t * ptr = reinterpret_cast <const uint8_t *>(m_parentJointIDs.buffer ->getPointer ());
44
+ return reinterpret_cast <const base_t ::joint_id_t *>(ptr+m_parentJointIDs.offset )[jointID];
41
45
}
42
- inline Base ::joint_id_t & getParentJointID (Base ::joint_id_t jointID)
46
+ inline base_t ::joint_id_t & getParentJointID (base_t ::joint_id_t jointID)
43
47
{
44
- return const_cast <Base ::joint_id_t &>(const_cast <const ICPUSkeleton*>(this )->getParentJointID (jointID));
48
+ return const_cast <base_t ::joint_id_t &>(const_cast <const ICPUSkeleton*>(this )->getParentJointID (jointID));
45
49
}
46
50
47
51
// ! Serializes mesh to blob for *.baw file format.
@@ -55,31 +59,65 @@ class ICPUSkeleton : public ISkeleton<ICPUBuffer>, /*TODO: public BlobSerializab
55
59
}
56
60
*/
57
61
62
+ core::smart_refctd_ptr<IAsset> clone (uint32_t _depth = ~0u ) const override
63
+ {
64
+ SBufferBinding<ICPUBuffer> _parentJointIDsBinding = {m_parentJointIDs.offset ,_depth>0u &&m_parentJointIDs.buffer ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(m_parentJointIDs.buffer ->clone (_depth-1u )):m_parentJointIDs.buffer };
65
+ SBufferBinding<ICPUBuffer> _inverseBindPosesBinding = {m_inverseBindPoses.offset ,_depth>0u &&m_inverseBindPoses.buffer ? core::smart_refctd_ptr_static_cast<ICPUBuffer>(m_inverseBindPoses.buffer ->clone (_depth-1u )):m_inverseBindPoses.buffer };
66
+
67
+ auto cp = core::make_smart_refctd_ptr<ICPUSkeleton>(std::move (_parentJointIDsBinding),std::move (_inverseBindPosesBinding),m_jointCount);
68
+ clone_common (cp.get ());
69
+ assert (!cp->m_stringPool );
70
+ cp->m_stringPoolSize = m_stringPoolSize;
71
+ cp->m_stringPool = _NBL_NEW_ARRAY (char ,m_stringPoolSize);
72
+ memcpy (cp->m_stringPool ,m_stringPool,m_stringPoolSize);
73
+ for (auto stringToID : m_nameToJointID)
74
+ cp->m_nameToJointID .emplace (stringToID.first -m_stringPool+cp->m_stringPool ,stringToID.second );
75
+
76
+ return cp;
77
+ }
78
+
58
79
virtual void convertToDummyObject (uint32_t referenceLevelsBelowToConvert=0u ) override
59
80
{
60
81
convertToDummyObject_common (referenceLevelsBelowToConvert);
61
82
62
83
if (referenceLevelsBelowToConvert)
63
- for (auto i=0u ; i<getMeshBufferCount (); i++)
64
- getMeshBuffer (i)->convertToDummyObject (referenceLevelsBelowToConvert-1u );
84
+ {
85
+ m_parentJointIDs.buffer ->convertToDummyObject (referenceLevelsBelowToConvert-1u );
86
+ m_inverseBindPoses.buffer ->convertToDummyObject (referenceLevelsBelowToConvert-1u );
87
+ // TODO: do we clear out the string pool and the name to bone ID mapping?
88
+ }
65
89
}
66
90
67
91
_NBL_STATIC_INLINE_CONSTEXPR auto AssetType = ET_SKELETON;
68
92
inline E_TYPE getAssetType () const override { return AssetType; }
69
- /* TODO
93
+
70
94
virtual size_t conservativeSizeEstimate () const override
71
95
{
72
- size_t estimate = m_nameToJointID.size()*sizeof(std::pair<const char*,joint_id_t>);
96
+ size_t estimate = sizeof (SBufferBinding<ICPUBuffer>)*2ull ;
97
+ estimate += sizeof (uint16_t );
98
+ estimate += m_stringPoolSize;
99
+ estimate += m_nameToJointID.size ()*sizeof (std::pair<uint32_t ,joint_id_t >);
73
100
// do we add other things to the size estimate?
74
101
return estimate;
75
102
}
76
- */
103
+
77
104
bool canBeRestoredFrom (const IAsset* _other) const override
78
105
{
79
106
auto other = static_cast <const ICPUSkeleton*>(_other);
80
- if (getJointCount ()!=other->getJointCount ())
81
- return false ;
82
- if (!getMeshBuffer (i)->canBeRestoredFrom (other->getMeshBuffer (i)))
107
+ // if we decide to get rid of the string pool when converting to dummy, then we need to start checking stringpool and map properties here
108
+ if (m_parentJointIDs.offset != other->m_parentJointIDs .offset )
109
+ return false ;
110
+ if ((!m_parentJointIDs.buffer ) != (!other->m_parentJointIDs .buffer ))
111
+ return false ;
112
+ if (m_parentJointIDs.buffer && !m_parentJointIDs.buffer ->canBeRestoredFrom (other->m_parentJointIDs .buffer .get ()))
113
+ return false ;
114
+ if (m_inverseBindPoses.offset != other->m_inverseBindPoses .offset )
115
+ return false ;
116
+ if ((!m_inverseBindPoses.buffer ) != (!other->m_inverseBindPoses .buffer ))
117
+ return false ;
118
+ if (m_inverseBindPoses.buffer && !m_inverseBindPoses.buffer ->canBeRestoredFrom (other->m_inverseBindPoses .buffer .get ()))
119
+ return false ;
120
+ if (m_jointCount != other->m_jointCount )
83
121
return false ;
84
122
85
123
return true ;
@@ -93,15 +131,21 @@ class ICPUSkeleton : public ISkeleton<ICPUBuffer>, /*TODO: public BlobSerializab
93
131
if (_levelsBelow)
94
132
{
95
133
--_levelsBelow;
96
- // for (uint32_t i = 0u; i < getMeshBufferCount(); i++)
97
- // restoreFromDummy_impl_call(getMeshBuffer(i), other->getMeshBuffer(i), _levelsBelow);
134
+
135
+ if (m_parentJointIDs.buffer )
136
+ restoreFromDummy_impl_call (m_parentJointIDs.buffer .get (),other->m_parentJointIDs .buffer .get (),_levelsBelow);
137
+ if (m_inverseBindPoses.buffer )
138
+ restoreFromDummy_impl_call (m_inverseBindPoses.buffer .get (),other->m_inverseBindPoses .buffer .get (),_levelsBelow);
98
139
}
99
140
}
100
141
101
142
bool isAnyDependencyDummy_impl (uint32_t _levelsBelow) const override
102
143
{
103
- // TODO
104
- return false ;
144
+ --_levelsBelow;
145
+ if (m_parentJointIDs.buffer && m_parentJointIDs.buffer ->isAnyDependencyDummy (_levelsBelow))
146
+ return true ;
147
+
148
+ return m_inverseBindPoses.buffer && m_inverseBindPoses.buffer ->isAnyDependencyDummy (_levelsBelow);
105
149
}
106
150
};
107
151
0 commit comments