Skip to content

Commit

Permalink
fixed issues with material wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Apr 3, 2024
1 parent 8dbe6a7 commit ccf713b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/core/objects/geometry/VRPhysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/core/objects/material/VRMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ struct VRMatData {
}

map<string, VRMaterialWeakPtr> VRMaterial::materials;
map<Material*, VRMaterialWeakPtr> VRMaterial::materialsByPtr;
map<size_t, VRMaterialWeakPtr> VRMaterial::materialsById;
map<size_t, size_t> VRMaterial::fieldContainerMap;

VRMaterial::VRMaterial(string name) : VRObject(name) {}
Expand All @@ -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
Expand Down Expand Up @@ -516,12 +516,12 @@ void VRMaterial::testFix() {

void VRMaterial::clearAll() {
materials.clear();
materialsByPtr.clear();
materialsById.clear();
}

vector<VRMaterialPtr> VRMaterial::getAll() {
vector<VRMaterialPtr> 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;
}

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/objects/material/VRMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Color3f toColor3f(Color4f c);
class VRMaterial : public VRObject {
public:
static map<string, VRMaterialWeakPtr> materials;
static map<Material*, VRMaterialWeakPtr> materialsByPtr;
static map<size_t, VRMaterialWeakPtr> materialsById;
static map<size_t, size_t> fieldContainerMap;

void setup();
Expand Down

0 comments on commit ccf713b

Please sign in to comment.