Skip to content

Commit 0215b88

Browse files
author
devsh
committed
cauterize more stuff, start working on the Geometry Creator
1 parent 144299d commit 0215b88

14 files changed

+194
-977
lines changed

include/nbl/asset/IAssetManager.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O.
1+
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
5-
#ifndef __NBL_ASSET_I_ASSET_MANAGER_H_INCLUDED__
6-
#define __NBL_ASSET_I_ASSET_MANAGER_H_INCLUDED__
4+
#ifndef _NBL_ASSET_I_ASSET_MANAGER_H_INCLUDED_
5+
#define _NBL_ASSET_I_ASSET_MANAGER_H_INCLUDED_
76

87
#include <array>
98
#include <ostream>
@@ -18,7 +17,7 @@
1817
#include "nbl/asset/interchange/IAssetWriter.h"
1918

2019
#include "nbl/asset/utils/CCompilerSet.h"
21-
#include "nbl/asset/utils/IGeometryCreator.h"
20+
#include "nbl/asset/utils/CGeometryCreator.h"
2221

2322

2423
#define USE_MAPS_FOR_PATH_BASED_CACHE //benchmark and choose, paths can be full system paths
@@ -115,7 +114,7 @@ class NBL_API2 IAssetManager : public core::IReferenceCounted
115114
friend class IAssetLoader::IAssetLoaderOverride; // for access to non-const findAssets
116115

117116
core::smart_refctd_ptr<IGeometryCreator> m_geometryCreator;
118-
core::smart_refctd_ptr<IMeshManipulator> m_meshManipulator;
117+
core::smart_refctd_ptr<CPolygonGeometryManipulator> m_meshManipulator;
119118
core::smart_refctd_ptr<CCompilerSet> m_compilerSet;
120119
// called as a part of constructor only
121120
void initializeMeshTools();
@@ -139,8 +138,8 @@ class NBL_API2 IAssetManager : public core::IReferenceCounted
139138

140139
inline system::ISystem* getSystem() const { return m_system.get(); }
141140

142-
const IGeometryCreator* getGeometryCreator() const;
143-
IMeshManipulator* getMeshManipulator();
141+
const CGeometryCreator* getGeometryCreator() const;
142+
CPolygonGeometryManipulator* getPolygonGeometryManipulator();
144143
CCompilerSet* getCompilerSet() const { return m_compilerSet.get(); }
145144

146145
protected:

include/nbl/asset/ICPUPolygonGeometry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class NBL_API2 ICPUPolygonGeometry final : public IAsset, public IPolygonGeometr
160160
template<typename Out>
161161
inline bool getPrimitiveIndices(Out* out, const uint32_t primitiveID) const
162162
{
163-
return getPrimitiveIndices(out,primtiveID,primtiveID+1);
163+
return getPrimitiveIndices(out,primitiveID,primitiveID+1);
164164
}
165165

166166
protected:

include/nbl/asset/IPolygonGeometry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
#include "nbl/asset/IGeometry.h"
9+
#include "nbl/asset/RasterizationStates.h"
910
#include "nbl/asset/IAccelerationStructure.h"
1011

1112
#include <span>
@@ -253,7 +254,7 @@ class NBL_API2 IPolygonGeometry : public IIndexableGeometry<BufferType>, public
253254
if (view.getElementCount()>(1u<<31))
254255
return false;
255256
}
256-
m_indexView = std::move(view);
257+
base_t::m_indexView = std::move(view);
257258
return true;
258259
}
259260

include/nbl/asset/asset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include "nbl/asset/ICPUSkeleton.h"
5252

5353
// geometry
54-
#include "nbl/asset/utils/IGeometryCreator.h"
54+
#include "nbl/asset/utils/CGeometryCreator.h"
5555
#include "nbl/asset/ICPUGeometryCollection.h"
5656
#include "nbl/asset/ICPUMorphTargets.h"
5757

include/nbl/asset/interchange/IAssetLoader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace nbl::asset
1515
{
1616

17-
class IMeshManipulator;
17+
class CPolygonGeometryManipulator;
1818

1919
//! A class automating process of loading Assets from resources, eg. files
2020
/**
@@ -117,7 +117,7 @@ class NBL_API2 IAssetLoader : public virtual core::IReferenceCounted
117117
const uint8_t* decryptionKey;
118118
E_CACHING_FLAGS cacheFlags;
119119
E_LOADER_PARAMETER_FLAGS loaderFlags; //!< Flags having an impact on extraordinary tasks during loading process
120-
IMeshManipulator* meshManipulatorOverride = nullptr; //!< pointer used for specifying custom mesh manipulator to use, if nullptr - default mesh manipulator will be used
120+
CPolygonGeometryManipulator* meshManipulatorOverride = nullptr; //!< pointer used for specifying custom mesh manipulator to use, if nullptr - default mesh manipulator will be used
121121
std::filesystem::path workingDirectory = "";
122122
system::logger_opt_ptr logger;
123123
};

include/nbl/asset/utils/IGeometryCreator.h renamed to include/nbl/asset/utils/CGeometryCreator.h

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
11
// Copyright (C) 2018-2025 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
#ifndef _NBL_ASSET_I_GEOMETRY_CREATOR_H_INCLUDED_
5-
#define _NBL_ASSET_I_GEOMETRY_CREATOR_H_INCLUDED_
4+
#ifndef _NBL_ASSET_C_GEOMETRY_CREATOR_H_INCLUDED_
5+
#define _NBL_ASSET_C_GEOMETRY_CREATOR_H_INCLUDED_
66

77

88
#include "nbl/core/declarations.h"
99

10-
#include "nbl/asset/ICPUPolygonGeometry.h"
11-
#include "nbl/asset/utils/IMeshManipulator.h"
10+
#include "nbl/asset/utils/CPolygonGeometryManipulator.h"
1211

1312

1413
namespace nbl::asset
1514
{
1615

1716
//! Helper class for creating geometry on the fly.
1817
/** You can get an instance of this class through ISceneManager::getGeometryCreator() */
19-
class IGeometryCreator : public core::IReferenceCounted
18+
class CGeometryCreator final : public core::IReferenceCounted
2019
{
21-
_NBL_INTERFACE_CHILD(IGeometryCreator) {}
22-
public:
23-
struct return_type
24-
{
25-
SVertexInputParams inputParams;
26-
SPrimitiveAssemblyParams assemblyParams;
27-
SBufferBinding<ICPUBuffer> bindings[ICPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT];
28-
SBufferBinding<ICPUBuffer> indexBuffer;
29-
E_INDEX_TYPE indexType;
30-
uint32_t indexCount;
31-
core::aabbox3df bbox;
32-
};
20+
core::smart_refctd_ptr<CPolygonGeometryManipulator> m_defaultPolygonManipulator;
3321

22+
public:
3423
//! Creates a simple cube mesh.
3524
/**
3625
\param size Dimensions of the cube.
3726
\return Generated mesh.
3827
*/
39-
virtual return_type createCubeMesh(const core::vector3df& size=core::vector3df(5.f,5.f,5.f)) const =0;
28+
core::smart_refctd_ptr<ICPUPolygonGeometry> createCube(const hlsl::float32_t3 size={5.f,5.f,5.f}) const;
4029

4130

4231
//! Create an arrow mesh, composed of a cylinder and a cone.
@@ -53,11 +42,11 @@ class IGeometryCreator : public core::IReferenceCounted
5342
\param colorCone color of the cone
5443
\return Generated mesh.
5544
*/
56-
virtual return_type createArrowMesh(const uint32_t tesselationCylinder = 4,
45+
core::smart_refctd_ptr<ICPUPolygonGeometry> createArrow(const uint32_t tesselationCylinder = 4,
5746
const uint32_t tesselationCone = 8, const float height = 1.f,
5847
const float cylinderHeight = 0.6f, const float widthCylinder = 0.05f,
5948
const float widthCone = 0.3f, const video::SColor colorCylinder = 0xFFFFFFFF,
60-
const video::SColor colorCone = 0xFFFFFFFF, IMeshManipulator* const meshManipulatorOverride = nullptr) const =0;
49+
const video::SColor colorCone = 0xFFFFFFFF, IMeshManipulator* const meshManipulatorOverride = nullptr) const;
6150

6251

6352
//! Create a sphere mesh.
@@ -67,8 +56,8 @@ class IGeometryCreator : public core::IReferenceCounted
6756
\param polyCountY Number of quads used for the vertical tiling
6857
\return Generated mesh.
6958
*/
70-
virtual return_type createSphereMesh(float radius = 5.f,
71-
uint32_t polyCountX = 16, uint32_t polyCountY = 16, IMeshManipulator* const meshManipulatorOverride = nullptr) const =0;
59+
core::smart_refctd_ptr<ICPUPolygonGeometry> createSphere(float radius = 5.f,
60+
uint32_t polyCountX = 16, uint32_t polyCountY = 16, IMeshManipulator* const meshManipulatorOverride = nullptr) const;
7261

7362
//! Create a cylinder mesh.
7463
/**
@@ -80,9 +69,9 @@ class IGeometryCreator : public core::IReferenceCounted
8069
\param oblique (to be documented)
8170
\return Generated mesh.
8271
*/
83-
virtual return_type createCylinderMesh(float radius, float length,
72+
core::smart_refctd_ptr<ICPUPolygonGeometry> createCylinder(float radius, float length,
8473
uint32_t tesselation,
85-
const video::SColor& color=video::SColor(0xffffffff), IMeshManipulator* const meshManipulatorOverride = nullptr) const =0;
74+
const video::SColor& color=video::SColor(0xffffffff), IMeshManipulator* const meshManipulatorOverride = nullptr) const;
8675

8776
//! Create a cone mesh.
8877
/**
@@ -94,14 +83,14 @@ class IGeometryCreator : public core::IReferenceCounted
9483
\param oblique (to be documented)
9584
\return Generated mesh.
9685
*/
97-
virtual return_type createConeMesh(float radius, float length, uint32_t tesselation,
86+
core::smart_refctd_ptr<ICPUPolygonGeometry> createCone(float radius, float length, uint32_t tesselation,
9887
const video::SColor& colorTop=video::SColor(0xffffffff),
9988
const video::SColor& colorBottom=video::SColor(0xffffffff),
100-
float oblique=0.f, IMeshManipulator* const meshManipulatorOverride = nullptr) const =0;
89+
float oblique=0.f, IMeshManipulator* const meshManipulatorOverride = nullptr) const;
10190

102-
virtual return_type createRectangleMesh(const core::vector2df_SIMD& size = core::vector2df_SIMD(0.5f, 0.5f)) const = 0;
91+
core::smart_refctd_ptr<ICPUPolygonGeometry> createRectangle(const core::vector2df_SIMD& size = core::vector2df_SIMD(0.5f, 0.5f)) const;
10392

104-
virtual return_type createDiskMesh(float radius, uint32_t tesselation) const = 0;
93+
core::smart_refctd_ptr<ICPUPolygonGeometry> createDisk(float radius, uint32_t tesselation) const;
10594

10695
//! Create a icosphere geometry
10796
/**
@@ -110,7 +99,7 @@ class IGeometryCreator : public core::IReferenceCounted
11099
\param smooth Specifies whether vertecies should be built for smooth or flat shading.
111100
*/
112101

113-
virtual return_type createIcoSphere(float radius = 1.0f, uint32_t subdivision = 1, bool smooth = false) const = 0;
102+
core::smart_refctd_ptr<ICPUPolygonGeometry> createIcoSphere(float radius = 1.0f, uint32_t subdivision = 1, bool smooth = false) const;
114103

115104
};
116105

include/nbl/asset/utils/CPolygonGeometryManipulator.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,137 @@ class NBL_API2 CPolygonGeometryManipulator
567567
#endif
568568
};
569569

570+
#if 0
571+
572+
//! An interface for easy manipulation of meshes.
573+
/** Scale, set alpha value, flip surfaces, and so on. This exists for fixing
574+
problems with wrong imported or exported meshes quickly after loading. It is
575+
not intended for doing mesh modifications and/or animations during runtime.
576+
*/
577+
class CMeshManipulator : public IMeshManipulator
578+
{
579+
struct SAttrib
580+
{
581+
E_FORMAT type;
582+
E_FORMAT prevType;
583+
size_t size;
584+
uint32_t vaid;
585+
size_t offset;
586+
587+
SAttrib() : type(EF_UNKNOWN), size(0), vaid(ICPUMeshBuffer::MAX_VERTEX_ATTRIB_COUNT) {}
588+
589+
friend bool operator>(const SAttrib& _a, const SAttrib& _b) { return _a.size > _b.size; }
590+
};
591+
struct SAttribTypeChoice
592+
{
593+
E_FORMAT type;
594+
};
595+
596+
public:
597+
static core::smart_refctd_ptr<ICPUMeshBuffer> createMeshBufferFetchOptimized(const ICPUMeshBuffer* _inbuffer);
598+
599+
CQuantNormalCache* getQuantNormalCache() override { return &quantNormalCache; }
600+
CQuantQuaternionCache* getQuantQuaternionCache() override { return &quantQuaternionCache; }
601+
602+
private:
603+
friend class IMeshManipulator;
604+
605+
template<typename IdxT>
606+
static void _filterInvalidTriangles(ICPUMeshBuffer* _input);
607+
608+
//! Meant to create 32bit index buffer from subrange of index buffer containing 16bit indices. Remember to set to index buffer offset to 0 after mapping buffer resulting from this function.
609+
static inline core::smart_refctd_ptr<ICPUBuffer> create32BitFrom16BitIdxBufferSubrange(const uint16_t* _in, uint32_t _idxCount)
610+
{
611+
if (!_in)
612+
return nullptr;
613+
614+
auto out = ICPUBuffer::create({ sizeof(uint32_t) * _idxCount });
615+
616+
auto* outPtr = reinterpret_cast<uint32_t*>(out->getPointer());
617+
618+
for (uint32_t i=0u; i<_idxCount; ++i)
619+
outPtr[i] = _in[i];
620+
621+
return out;
622+
}
623+
624+
static core::vector<core::vectorSIMDf> findBetterFormatF(E_FORMAT* _outType, size_t* _outSize, E_FORMAT* _outPrevType, const ICPUMeshBuffer* _meshbuffer, uint32_t _attrId, const SErrorMetric& _errMetric, CQuantNormalCache& _cache);
625+
626+
struct SIntegerAttr
627+
{
628+
uint32_t pointer[4];
629+
};
630+
static core::vector<SIntegerAttr> findBetterFormatI(E_FORMAT* _outType, size_t* _outSize, E_FORMAT* _outPrevType, const ICPUMeshBuffer* _meshbuffer, uint32_t _attrId, const SErrorMetric& _errMetric);
631+
632+
//E_COMPONENT_TYPE getBestTypeF(bool _normalized, E_COMPONENTS_PER_ATTRIBUTE _cpa, size_t* _outSize, E_COMPONENTS_PER_ATTRIBUTE* _outCpa, const float* _min, const float* _max) const;
633+
static E_FORMAT getBestTypeI(E_FORMAT _originalType, size_t* _outSize, const uint32_t* _min, const uint32_t* _max);
634+
static core::vector<SAttribTypeChoice> findTypesOfProperRangeF(E_FORMAT _type, size_t _sizeThreshold, const float* _min, const float* _max, const SErrorMetric& _errMetric);
635+
636+
//! Calculates quantization errors and compares them with given epsilon.
637+
/** @returns false when first of calculated errors goes above epsilon or true if reached end without such. */
638+
static bool calcMaxQuantizationError(const SAttribTypeChoice& _srcType, const SAttribTypeChoice& _dstType, const core::vector<core::vectorSIMDf>& _data, const SErrorMetric& _errMetric, CQuantNormalCache& _cache);
639+
640+
template<typename InType, typename OutType>
641+
static inline core::smart_refctd_ptr<ICPUBuffer> lineStripsToLines(const void* _input, uint32_t& _idxCount)
642+
{
643+
const auto outputSize = _idxCount = (_idxCount - 1) * 2;
644+
645+
auto output = ICPUBuffer::create({ sizeof(OutType)*outputSize });
646+
const auto* iptr = reinterpret_cast<const InType*>(_input);
647+
auto* optr = reinterpret_cast<OutType*>(output->getPointer());
648+
for (uint32_t i = 0, j = 0; i < outputSize;)
649+
{
650+
optr[i++] = iptr[j++];
651+
optr[i++] = iptr[j];
652+
}
653+
return output;
654+
}
655+
656+
template<typename InType, typename OutType>
657+
static inline core::smart_refctd_ptr<ICPUBuffer> triangleStripsToTriangles(const void* _input, uint32_t& _idxCount)
658+
{
659+
const auto outputSize = _idxCount = (_idxCount - 2) * 3;
660+
661+
auto output = ICPUBuffer::create({ sizeof(OutType)*outputSize });
662+
const auto* iptr = reinterpret_cast<const InType*>(_input);
663+
auto* optr = reinterpret_cast<OutType*>(output->getPointer());
664+
for (uint32_t i = 0, j = 0; i < outputSize; j += 2)
665+
{
666+
optr[i++] = iptr[j + 0];
667+
optr[i++] = iptr[j + 1];
668+
optr[i++] = iptr[j + 2];
669+
if (i == outputSize)
670+
break;
671+
optr[i++] = iptr[j + 2];
672+
optr[i++] = iptr[j + 1];
673+
optr[i++] = iptr[j + 3];
674+
}
675+
return output;
676+
}
677+
678+
template<typename InType, typename OutType>
679+
static inline core::smart_refctd_ptr<ICPUBuffer> trianglesFanToTriangles(const void* _input, uint32_t& _idxCount)
680+
{
681+
const auto outputSize = _idxCount = (_idxCount - 2) * 3;
682+
683+
auto output = ICPUBuffer::create({ sizeof(OutType)*outputSize });
684+
const auto* iptr = reinterpret_cast<const InType*>(_input);
685+
auto* optr = reinterpret_cast<OutType*>(output->getPointer());
686+
for (uint32_t i = 0, j = 1; i < outputSize;)
687+
{
688+
optr[i++] = iptr[0];
689+
optr[i++] = iptr[j++];
690+
optr[i++] = iptr[j];
691+
}
692+
return output;
693+
}
694+
695+
private:
696+
CQuantNormalCache quantNormalCache;
697+
CQuantQuaternionCache quantQuaternionCache;
698+
};
699+
#endif
700+
570701
// TODO: Utility in another header for GeometryCollection to compute AABBs, deal with skins (joints), etc.
571702

572703
} // end namespace nbl::asset

0 commit comments

Comments
 (0)