From e3623a7ca2f9386e62b443f279c66fa3f2759210 Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Fri, 27 Feb 2026 18:49:24 -0500 Subject: [PATCH] Updated "Shift textures randomly" also work with patches --- install/scripts/commands/shift_textures_randomly.py | 11 +++++++++++ .../commands/shift_textures_upwards_randomly.py | 10 ++++++++++ plugins/script/interfaces/PatchInterface.cpp | 9 +++++++++ plugins/script/interfaces/PatchInterface.h | 3 +++ 4 files changed, 33 insertions(+) diff --git a/install/scripts/commands/shift_textures_randomly.py b/install/scripts/commands/shift_textures_randomly.py index 64b35e8e58..0b09d235d8 100644 --- a/install/scripts/commands/shift_textures_randomly.py +++ b/install/scripts/commands/shift_textures_randomly.py @@ -18,6 +18,17 @@ def visitFace(self, face): visitor = FaceVisitor() GlobalSelectionSystem.foreachSelectedFace(visitor) + class PatchVisitor(dr.SelectionVisitor) : + def visit(self, node): + patch = node.getPatch() + if not patch.isNull(): + s = random.randint(0, 100) + t = random.randint(0, 100) + patch.translateTexture(s, t) + + patchVisitor = PatchVisitor() + GlobalSelectionSystem.foreachSelected(patchVisitor) + GlobalCameraManager.getActiveView().refresh() # The variable __executeCommand__ evaluates to true diff --git a/install/scripts/commands/shift_textures_upwards_randomly.py b/install/scripts/commands/shift_textures_upwards_randomly.py index 9a33d36ecb..19c432eafc 100644 --- a/install/scripts/commands/shift_textures_upwards_randomly.py +++ b/install/scripts/commands/shift_textures_upwards_randomly.py @@ -17,6 +17,16 @@ def visitFace(self, face): visitor = FaceVisitor() GlobalSelectionSystem.foreachSelectedFace(visitor) + class PatchVisitor(dr.SelectionVisitor) : + def visit(self, node): + patch = node.getPatch() + if not patch.isNull(): + t = random.randint(0, 100) + patch.translateTexture(0, t) + + patchVisitor = PatchVisitor() + GlobalSelectionSystem.foreachSelected(patchVisitor) + GlobalCameraManager.getActiveView().refresh() # The variable __executeCommand__ evaluates to true diff --git a/plugins/script/interfaces/PatchInterface.cpp b/plugins/script/interfaces/PatchInterface.cpp index ebe5f43c2f..f7dbe89742 100644 --- a/plugins/script/interfaces/PatchInterface.cpp +++ b/plugins/script/interfaces/PatchInterface.cpp @@ -135,6 +135,14 @@ void ScriptPatchNode::controlPointsChanged() patchNode->getPatch().controlPointsChanged(); } +void ScriptPatchNode::translateTexture(float s, float t) +{ + IPatchNodePtr patchNode = std::dynamic_pointer_cast(_node.lock()); + if (patchNode == NULL) return; + + patchNode->getPatch().translateTexture(s, t); +} + const std::string& ScriptPatchNode::getShader() const { IPatchNodePtr patchNode = std::dynamic_pointer_cast(_node.lock()); @@ -265,6 +273,7 @@ void PatchInterface::registerInterface(py::module& scope, py::dict& globals) patchNode.def("getSubdivisions", &ScriptPatchNode::getSubdivisions); patchNode.def("setFixedSubdivisions", &ScriptPatchNode::setFixedSubdivisions); patchNode.def("controlPointsChanged", &ScriptPatchNode::controlPointsChanged); + patchNode.def("translateTexture", &ScriptPatchNode::translateTexture); patchNode.def("getTesselatedPatchMesh", &ScriptPatchNode::getTesselatedPatchMesh); // Define the GlobalPatchCreator interface diff --git a/plugins/script/interfaces/PatchInterface.h b/plugins/script/interfaces/PatchInterface.h index 583892e8b5..fd576defa7 100644 --- a/plugins/script/interfaces/PatchInterface.h +++ b/plugins/script/interfaces/PatchInterface.h @@ -51,6 +51,9 @@ class ScriptPatchNode : void controlPointsChanged(); + // Texture manipulation + void translateTexture(float s, float t); + // Shader handling const std::string& getShader() const; void setShader(const std::string& name);