From ccf713b7d874116fb16d3673b1b3043c7c75a8c8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 3 Apr 2024 22:21:32 +0200 Subject: [PATCH] fixed issues with material wrapping --- CMakeLists.txt | 1 + src/core/objects/geometry/VRPhysics.cpp | 2 +- src/core/objects/material/VRMaterial.cpp | 20 ++++++++++---------- src/core/objects/material/VRMaterial.h | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a337356be..c1a92ea61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -966,6 +966,7 @@ target_sources(polyvr PRIVATE src/core/math/patch.cpp) target_sources(polyvr PRIVATE src/core/math/path.cpp) target_sources(polyvr PRIVATE src/core/math/partitioning/graph.cpp) target_sources(polyvr PRIVATE src/core/math/datarow.cpp) +target_sources(polyvr PRIVATE src/core/math/PID.cpp) target_sources(polyvr PRIVATE src/core/navigation/VRNavigator.cpp) endif() diff --git a/src/core/objects/geometry/VRPhysics.cpp b/src/core/objects/geometry/VRPhysics.cpp index 3562aab65..3947ac466 100644 --- a/src/core/objects/geometry/VRPhysics.cpp +++ b/src/core/objects/geometry/VRPhysics.cpp @@ -1431,7 +1431,7 @@ void VRPhysics::updateConstraint(VRPhysics* p) { double a = c->getMin(i); double b = c->getMax(i); //if (a <= b) { - double pi = M_PI; + const double pi = 3.14159265358979323846; if (i == 3) { a = min( max(-pi, a), pi ); b = min( max(-pi, b), pi ); } // clamp to -pi/pi if (i == 4) { a = min( max(-pi*0.5, a), pi*0.5 ); b = min( max(-pi*0.5, b), pi*0.5 ); } // clamp to -0.5pi/0.5pi if (i == 5) { a = min( max(-pi, a), pi ); b = min( max(-pi, b), pi ); } // clamp to -pi/pi diff --git a/src/core/objects/material/VRMaterial.cpp b/src/core/objects/material/VRMaterial.cpp index 650019eaf..81644565e 100644 --- a/src/core/objects/material/VRMaterial.cpp +++ b/src/core/objects/material/VRMaterial.cpp @@ -231,7 +231,7 @@ struct VRMatData { } map VRMaterial::materials; -map VRMaterial::materialsByPtr; +map VRMaterial::materialsById; map VRMaterial::fieldContainerMap; VRMaterial::VRMaterial(string name) : VRObject(name) {} @@ -245,7 +245,7 @@ VRMaterialPtr VRMaterial::create(string name, bool reg) { p->init(); Material* mat = p->getMaterial()->mat.get(); if (reg) materials[p->getName()] = p; - if (reg) materialsByPtr[mat] = p; + if (reg) materialsById[mat->getId()] = p; #ifdef OSG_OGL_ES2 p->updateOGL2Shader(); // TODO: find a better place! #endif @@ -516,12 +516,12 @@ void VRMaterial::testFix() { void VRMaterial::clearAll() { materials.clear(); - materialsByPtr.clear(); + materialsById.clear(); } vector VRMaterial::getAll() { vector res; - for (auto wm : materialsByPtr) if (auto m = wm.second.lock()) res.push_back(m); + for (auto wm : materialsById) if (auto m = wm.second.lock()) res.push_back(m); return res; } @@ -600,21 +600,21 @@ void VRMaterial::prependPasses(VRMaterialPtr mat) { } VRMaterialPtr VRMaterial::get(MaterialMTRecPtr mat) { - Material* key = mat.get(); + size_t key = mat->getId(); VRMaterialPtr m; - if (materialsByPtr.count(key) == 0) { + if (materialsById.count(key) == 0) { m = VRMaterial::create("mat"); m->setMaterial(mat); - materialsByPtr[key] = m; + materialsById[key] = m; return m; - } else if (materialsByPtr[key].lock() == 0) { + } else if (materialsById[key].lock() == 0) { m = VRMaterial::create("mat"); m->setMaterial(mat); - materialsByPtr[key] = m; + materialsById[key] = m; return m; } - return materialsByPtr[key].lock(); + return materialsById[key].lock(); } VRMaterialPtr VRMaterial::get(string s) { diff --git a/src/core/objects/material/VRMaterial.h b/src/core/objects/material/VRMaterial.h index f847150a4..9bda8db90 100644 --- a/src/core/objects/material/VRMaterial.h +++ b/src/core/objects/material/VRMaterial.h @@ -32,7 +32,7 @@ Color3f toColor3f(Color4f c); class VRMaterial : public VRObject { public: static map materials; - static map materialsByPtr; + static map materialsById; static map fieldContainerMap; void setup();