Skip to content

Commit 40a8df3

Browse files
author
devsh
committed
implement ICPUMorphTargets
1 parent 18adf44 commit 40a8df3

File tree

8 files changed

+123
-32
lines changed

8 files changed

+123
-32
lines changed

include/nbl/asset/ICPUMorphTargets.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (C) 2025-2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_ASSET_I_CPU_MORPH_TARGETS_H_INCLUDED_
5+
#define _NBL_ASSET_I_CPU_MORPH_TARGETS_H_INCLUDED_
6+
7+
8+
#include "nbl/asset/IAsset.h"
9+
#include "nbl/asset/IMorphTargets.h"
10+
11+
12+
namespace nbl::asset
13+
{
14+
//
15+
class NBL_API2 ICPUMorphTargets : public IAsset, public IMorphTargets<ICPUGeometryCollection>
16+
{
17+
using base_t = IMorphTargets<ICPUBuffer>;
18+
19+
public:
20+
inline ICPUMorphTargets() = default;
21+
22+
constexpr static inline auto AssetType = ET_MORPH_TARGETS;
23+
inline E_TYPE getAssetType() const override {return AssetType;}
24+
25+
//
26+
inline bool valid() const //override
27+
{
28+
for (const auto& target : m_targets)
29+
if (!target || !target.geoCollection->valid())
30+
return false;
31+
return true;
32+
}
33+
34+
inline core::smart_refctd_ptr<IAsset> clone(uint32_t _depth=~0u) const
35+
{
36+
const auto nextDepth = _depth ? (_depth-1):0;
37+
auto retval = core::smart_refctd_ptr<ICPUMorphTargets>();
38+
retval->m_targets.reserve(m_targets.size());
39+
for (const auto& in : m_targets)
40+
{
41+
auto& out = retval->m_targets.push_back();
42+
out.geoCollection = core::smart_refctd_ptr_static_cast<ICPUGeometryCollection>(in.geoCollection->clone(nextDepth));
43+
out.jointRedirectView = in.jointRedirectView.clone(nextDepth));
44+
}
45+
return retval;
46+
}
47+
48+
// TODO: remove after https://github.com/Devsh-Graphics-Programming/Nabla/pull/871 merge
49+
inline size_t getDependantCount() const override
50+
{
51+
size_t count = 0;
52+
visitDependents([&current](const IAsset* dep)->bool
53+
{
54+
count++;
55+
return true;
56+
}
57+
);
58+
return count;
59+
}
60+
61+
//
62+
inline core::vector<SGeometryReference>* getTargets()
63+
{
64+
if (isMutable())
65+
return &m_targets;
66+
return nullptr;
67+
}
68+
69+
protected:
70+
//
71+
inline void visitDependents(std::function<bool(const IAsset*)> visit) const //override
72+
{
73+
auto nonNullOnly = [&visit](const IAsset* dep)->bool
74+
{
75+
if (dep)
76+
return visit(dep);
77+
return true;
78+
};
79+
for (const auto& ref : m_targets)
80+
if (!nonNullOnly(ref.geoCollection.get())) return;
81+
}
82+
// TODO: remove after https://github.com/Devsh-Graphics-Programming/Nabla/pull/871 merge
83+
inline IAsset* getDependant_impl(const size_t ix) override
84+
{
85+
const IAsset* retval = nullptr;
86+
size_t current = 0;
87+
visitDependents([&current](const IAsset* dep)->bool
88+
{
89+
retval = dep;
90+
return ix<current++;
91+
}
92+
);
93+
return const_cast<IAsset*>(retval);
94+
}
95+
};
96+
97+
}
98+
#endif

include/nbl/asset/ICPUPolygonGeometry.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class NBL_API2 ICPUPolygonGeometry final : public IAsset, public IPolygonGeometr
6868
inline bool setPositionView(SDataView&& view)
6969
{
7070
if (isMutable() && (!view || view.composed.isFormatted()))
71-
return base_t::setPositionView(std::move(view));
71+
{
72+
m_positionView = std::move(view);
73+
return true;
74+
}
7275
return false;
7376
}
7477

include/nbl/asset/IGeometry.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,6 @@ class NBL_API2 IGeometry : public IGeometryBase
338338
protected:
339339
virtual inline ~IGeometry() = default;
340340

341-
// needs to be hidden because of mutability checking
342-
inline bool setPositionView(SDataView&& view)
343-
{
344-
if (!view)
345-
return false;
346-
m_positionView = std::move(view);
347-
return true;
348-
}
349341
//
350342
inline bool setJointOBBView(SDataView&& view)
351343
{
@@ -396,7 +388,7 @@ class NBL_API2 IIndexableGeometry : public IGeometry<BufferType>
396388
// Needs to be hidden because ICPU base class shall check mutability
397389
inline bool setIndexView(SDataView&& view)
398390
{
399-
if (view.isFormattedScalarInteger())
391+
if (!view || view.isFormattedScalarInteger())
400392
{
401393
m_indexView = std::move(strm);
402394
return true;

include/nbl/asset/IGeometryCollection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace nbl::asset
1414
template<class BufferType>
1515
class NBL_API2 IGeometryCollection : public virtual core::IReferenceCounted
1616
{
17+
public:
1718
using SDataView = IGeometry<BufferType>::SDataView;
1819

19-
public:
2020
//
2121
inline const auto& getAABB() const {return m_aabb;}
2222

@@ -124,6 +124,6 @@ class NBL_API2 IGeometryCollection : public virtual core::IReferenceCounted
124124
//
125125
core::vector<SGeometryReference> m_geometries;
126126
};
127-
}
128127

128+
}
129129
#endif

include/nbl/asset/IMorphTargets.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace nbl::asset
1313
// Unlike glTF we don't require same index buffers and maintaining isomorphisms between primitives/vertices in different geometries. But most of the use cases would have such mappings.
1414
// The semantics are really up to you, these are just collections of Geometries which can be swapped out or interpolated between.
1515
// Note: A LoD set can also be viewed as a morph shape per LoD, while a Motion Blur BLAS can be viewed as representing the interval between two Morph Targets.
16-
template<class BufferType>
16+
template<class GeometryCollection>
1717
class NBL_API2 IMorphTargets : public virtual core::IReferenceCounted
1818
{
1919
public:
@@ -54,10 +54,15 @@ class NBL_API2 IMorphTargets : public virtual core::IReferenceCounted
5454

5555
struct STarget
5656
{
57-
core::smart_refctd_ptr<IGeometryCollection<BufferType>> geoCollection = {};
57+
inline operator bool() const
58+
{
59+
return geoCollection && (!jointRedirectView || jointRedirectView.composed.isFormattedScalarInteger());
60+
}
61+
62+
core::smart_refctd_ptr<GeometryCollection> geoCollection = {};
5863
// The geometry may be using a smaller set of joint/bone IDs which need to be remapped to a larger or common skeleton.
5964
// Ignored if the collection is not skinned.
60-
SDataView jointRedirectView = {};
65+
GeometryCollection::SDataView jointRedirectView = {};
6166
};
6267
inline const core::vector<STarget>& getTargets() const {return m_targets;}
6368

@@ -67,7 +72,7 @@ class NBL_API2 IMorphTargets : public virtual core::IReferenceCounted
6772
//
6873
inline core::vector<STarget>& getTargets() {return m_targets;}
6974

70-
// TODO: utility to make IBottomLevelAccelerationStructure::Triangles from two targets
75+
// TODO: utility to make motion-blur IBottomLevelAccelerationStructure::Triangles from two targets
7176

7277
//
7378
core::vector<STarget> m_targets;

include/nbl/asset/asset.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
#include "nbl/asset/format/decodePixels.h"
2020
#include "nbl/asset/format/encodePixels.h"
2121

22-
// base
22+
// buffers
2323
#include "nbl/asset/ICPUBuffer.h"
24-
#include "nbl/asset/IMesh.h" //depr
2524

2625
// images
2726
#include "nbl/asset/ICPUImage.h"
@@ -51,21 +50,19 @@
5150
#include "nbl/asset/ICPUAnimationLibrary.h"
5251
#include "nbl/asset/ICPUSkeleton.h"
5352

54-
// meshes
55-
#include "nbl/asset/ICPUMeshBuffer.h"
56-
#include "nbl/asset/ICPUMesh.h"
53+
// geometry
5754
#include "nbl/asset/utils/IGeometryCreator.h"
58-
// #include "nbl/asset/utils/IMeshPacker.h"
55+
#include "nbl/asset/utils/ICPUGeometryCollection.h"
56+
#include "nbl/asset/utils/ICPUMorphTargets.h"
5957

6058
// manipulation + reflection + introspection
61-
#include "nbl/asset/utils/IMeshManipulator.h"
59+
#include "nbl/asset/utils/CSmoothNormalGenerator.h"
6260

6361

6462
#include "nbl/asset/IAssetManager.h"
6563
// importexport
6664
#include "nbl/asset/interchange/IAssetLoader.h"
6765
#include "nbl/asset/interchange/IImageLoader.h"
68-
#include "nbl/asset/interchange/IRenderpassIndependentPipelineLoader.h"
6966
#include "nbl/asset/interchange/IAssetWriter.h"
7067
#include "nbl/asset/interchange/IImageWriter.h"
7168
#include "nbl/asset/metadata/COpenEXRMetadata.h"
@@ -74,8 +71,4 @@
7471
#include "nbl/asset/metadata/CPLYMetadata.h"
7572
#include "nbl/asset/metadata/CSTLMetadata.h"
7673

77-
//VT
78-
// #include "nbl/asset/utils/CCPUMeshPackerV1.h"
79-
// #include "nbl/asset/utils/CCPUMeshPackerV2.h"
80-
8174
#endif

src/nbl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ set(NBL_ASSET_SOURCES
178178
${NBL_ROOT_PATH}/src/nbl/asset/utils/CForsythVertexCacheOptimizer.cpp
179179
${NBL_ROOT_PATH}/src/nbl/asset/utils/CSmoothNormalGenerator.cpp
180180
${NBL_ROOT_PATH}/src/nbl/asset/utils/CGeometryCreator.cpp
181-
${NBL_ROOT_PATH}/src/nbl/asset/utils/CMeshManipulator.cpp
181+
${NBL_ROOT_PATH}/src/nbl/asset/utils/CPolygonGeometryManipulator.cpp
182182
${NBL_ROOT_PATH}/src/nbl/asset/utils/COverdrawMeshOptimizer.cpp
183183
${NBL_ROOT_PATH}/src/nbl/asset/utils/CSmoothNormalGenerator.cpp
184184

src/nbl/asset/utils/CSmoothNormalGenerator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ namespace nbl::asset
1616
class CSmoothNormalGenerator
1717
{
1818
public:
19-
static core::smart_refctd_ptr<ICPUMeshBuffer> calculateNormals(ICPUMeshBuffer* buffer, float epsilon, uint32_t normalAttrID, IMeshManipulator::VxCmpFunction function);
20-
2119
CSmoothNormalGenerator() = delete;
2220
~CSmoothNormalGenerator() = delete;
21+
#if 0
22+
static core::smart_refctd_ptr<ICPUMeshBuffer> calculateNormals(ICPUMeshBuffer* buffer, float epsilon, uint32_t normalAttrID, IMeshManipulator::VxCmpFunction function);
2323

2424
private:
2525
class VertexHashMap
@@ -66,7 +66,7 @@ class CSmoothNormalGenerator
6666
private:
6767
static VertexHashMap setupData(const ICPUMeshBuffer* buffer, float epsilon);
6868
static void processConnectedVertices(ICPUMeshBuffer* buffer, VertexHashMap& vertices, float epsilon, uint32_t normalAttrID, IMeshManipulator::VxCmpFunction vxcmp);
69-
69+
#endif
7070
};
7171

7272
}

0 commit comments

Comments
 (0)