Skip to content

Commit ced67b2

Browse files
committed
(Geometry) Fixed mesh loading under release build.
1 parent 66bb960 commit ced67b2

File tree

7 files changed

+49
-31
lines changed

7 files changed

+49
-31
lines changed

inc/Utils/FileSystem/AssimpCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace SR_UTILS_NS {
2929

3030
class AssimpCache final : public Singleton<AssimpCache> {
3131
SR_REGISTER_SINGLETON(AssimpCache);
32-
SR_MAYBE_UNUSED SR_INLINE_STATIC const uint64_t VERSION = 1014;
32+
SR_MAYBE_UNUSED SR_INLINE_STATIC const uint64_t VERSION = 1015;
3333
using NodeIndex = uint64_t;
3434
using MeshIndex = uint64_t;
3535
using NodeMap = std::pair<std::vector<aiNode*>, std::unordered_map<aiNode*, NodeIndex>>;

inc/Utils/Platform/Platform.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ namespace SR_UTILS_NS::Platform {
2525
Web
2626
);
2727

28+
SR_ENUM_NS_CLASS_T(BuildType, uint8_t,
29+
Unknown,
30+
Debug,
31+
Release
32+
)
33+
2834
static bool IsCompiledUnderMSVC() {
2935
#ifdef SR_MSVC
3036
return true;
@@ -75,6 +81,7 @@ namespace SR_UTILS_NS::Platform {
7581
SR_COMMON_DLL_API extern void InitSegmentationHandler();
7682
SR_COMMON_DLL_API extern void SetInstance(void* pInstance);
7783
SR_COMMON_DLL_API extern void* GetInstance();
84+
SR_COMMON_DLL_API extern BuildType GetBuildType();
7885
SR_COMMON_DLL_API extern PlatformType GetType();
7986
SR_COMMON_DLL_API extern WindowProtocolType GetWindowProtocolType();
8087
SR_COMMON_DLL_API extern bool IsMobilePlatform();

inc/Utils/World/ScenePrefabLogic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace SR_WORLD_NS {
1515
using Ptr = SR_HTYPES_NS::SharedPtr<ScenePrefabLogic>;
1616

1717
public:
18+
~ScenePrefabLogic() override;
19+
1820
void InitLogic() override;
1921
bool SaveLogic(ISerializer& serializer, const Path& path) override;
2022
bool LoadLogic(IDeserializer& deserializer, const Path& path) override;

src/Utils/Common/Vertices.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -355,33 +355,23 @@ namespace SR_UTILS_NS {
355355

356356
if (weights.count == 0) {
357357
// fallback — чтобы не улетело в (0,0,0)
358-
auto* pIdx = reinterpret_cast<SR_MATH_NS::UVector4*>(buffer.GetVertex(v, VertexAttribute::BlendIndices));
359-
auto* pW = reinterpret_cast<SR_MATH_NS::FVector4*>(buffer.GetVertex(v, VertexAttribute::BlendWeights));
358+
auto* pIdx = static_cast<SR_MATH_NS::UVector4*>(buffer.GetVertex(v, VertexAttribute::BlendIndices));
359+
auto* pW = static_cast<SR_MATH_NS::FVector4*>(buffer.GetVertex(v, VertexAttribute::BlendWeights));
360360

361361
(*pIdx)[0] = 0;
362362
(*pW)[0] = 1.0f;
363363
return;
364364
}
365365

366366
// 3. сортировка по убыванию веса
367-
std::sort(weights.weights, weights.weights + weights.count, [](const BoneWeight& a, const BoneWeight& b) {
367+
std::stable_sort(weights.weights, weights.weights + weights.count, [](const BoneWeight& a, const BoneWeight& b) {
368368
return a.weight > b.weight;
369369
});
370370

371-
// 4. считаем сумму всех весов
372-
float totalSum = 0.0f;
373-
for (uint8_t i = 0; i < weights.count; ++i) {
374-
totalSum += weights.weights[i].weight;
375-
}
376-
377-
if (totalSum <= 0.0f) {
378-
SRHalt("Vertex has zero total bone weight!");
379-
return;
380-
}
381-
382-
// 5. решаем: 4 или 8
383-
const uint32_t maxInfluences = weights.count > 4 ? std::min<uint32_t>(8, weights.count) : std::min<uint32_t>(4, weights.count);
371+
// 4. выбрать максимум влияний
372+
const uint32_t maxInfluences = std::min<uint32_t>(8, weights.count);
384373

374+
// 5. сумма ТОЛЬКО выбранных
385375
float selectedSum = 0.0f;
386376
for (uint32_t i = 0; i < maxInfluences; ++i)
387377
selectedSum += weights.weights[i].weight;
@@ -394,18 +384,17 @@ namespace SR_UTILS_NS {
394384
// 6. нормализация выбранных
395385
const float invSum = 1.0f / selectedSum;
396386

397-
// 7. запись
398-
auto* pIdx1 = reinterpret_cast<SR_MATH_NS::UVector4*>(buffer.GetVertex(v, VertexAttribute::BlendIndices));
399-
auto* pW1 = reinterpret_cast<SR_MATH_NS::FVector4*>(buffer.GetVertex(v, VertexAttribute::BlendWeights));
400-
401387
SR_MATH_NS::UVector4 idx1 = {0,0,0,0};
402388
SR_MATH_NS::FVector4 w1 = {0,0,0,0};
403389

404390
SR_MATH_NS::UVector4 idx2 = {0,0,0,0};
405391
SR_MATH_NS::FVector4 w2 = {0,0,0,0};
406392

407-
for (uint32_t i = 0; i < maxInfluences; ++i) {
393+
uint32_t used = std::min<uint32_t>(maxInfluences, 8);
394+
395+
for (uint32_t i = 0; i < used; ++i) {
408396
const float w = weights.weights[i].weight * invSum;
397+
409398
if (i < 4) {
410399
idx1[i] = weights.weights[i].boneId;
411400
w1[i] = w;
@@ -416,16 +405,16 @@ namespace SR_UTILS_NS {
416405
}
417406
}
418407

408+
// 7. запись
409+
auto* pIdx1 = static_cast<SR_MATH_NS::UVector4*>(buffer.GetVertex(v, VertexAttribute::BlendIndices));
410+
auto* pW1 = static_cast<SR_MATH_NS::FVector4*>(buffer.GetVertex(v, VertexAttribute::BlendWeights));
411+
auto* pIdx2 = static_cast<SR_MATH_NS::UVector4*>(buffer.GetVertex(v, VertexAttribute::BlendIndices2));
412+
auto* pW2Ptr= static_cast<SR_MATH_NS::FVector4*>(buffer.GetVertex(v, VertexAttribute::BlendWeights2));
413+
419414
*pIdx1 = idx1;
420415
*pW1 = w1;
421-
422-
if (maxInfluences > 4) {
423-
auto* pIdx2 = reinterpret_cast<SR_MATH_NS::UVector4*>(buffer.GetVertex(v, VertexAttribute::BlendIndices2));
424-
auto* pW2Ptr= reinterpret_cast<SR_MATH_NS::FVector4*>(buffer.GetVertex(v, VertexAttribute::BlendWeights2));
425-
426-
*pIdx2 = idx2;
427-
*pW2Ptr= w2;
428-
}
416+
*pIdx2 = idx2;
417+
*pW2Ptr= w2;
429418

430419
// 8. проверка
431420
float finalSum = 0.0f;

src/Utils/Math/Mathematics.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ namespace SR_MATH_NS {
99
#ifdef SR_EMSCRIPTEN
1010
return false;
1111
#elif defined(__GNUC__) || defined(__clang__)
12-
return __builtin_cpu_supports("sse4.1");
12+
#ifdef SR_COMMON_USE_CLANG_EMULATION
13+
int cpuInfo[4];
14+
__cpuid(cpuInfo, 1);
15+
return (cpuInfo[2] & (1 << 19)) != 0;
16+
#else
17+
return __builtin_cpu_supports("sse4.1");
18+
#endif
1319
#else
1420
int cpuInfo[4];
1521
__cpuid(cpuInfo, 1);

src/Utils/Platform/PlatformCommon.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ namespace SR_PLATFORM_NS {
2222
}
2323
}
2424

25+
BuildType GetBuildType() {
26+
#if defined(SR_DEBUG)
27+
return BuildType::Debug;
28+
#elif defined(SR_RELEASE)
29+
return BuildType::Release;
30+
#else
31+
return BuildType::Unknown;
32+
#endif
33+
}
34+
2535
#ifndef SR_LINUX
2636
void AccumulateMouseDelta(const SR_MATH_NS::FVector2& delta) {
2737
SRHalt("Platform::AccumulateMouseDelta() : not implemented!");

src/Utils/World/ScenePrefabLogic.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <Codegen/ScenePrefabLogic.generated.hpp>
1313

1414
namespace SR_WORLD_NS {
15+
ScenePrefabLogic::~ScenePrefabLogic() {
16+
m_pSOCustomData.reset();
17+
}
18+
1519
bool ScenePrefabLogic::SaveSOAsPrefab(ISerializer& serializer, const SR_HTYPES_NS::SharedPtr<SceneObject>& pSO) {
1620
if (!pSO) {
1721
SRHalt("ScenePrefabLogic::SaveSOAsPrefab() : pSO is nullptr!");

0 commit comments

Comments
 (0)