diff --git a/install/scripts/commands/shift_textures_randomly.py b/install/scripts/commands/shift_textures_randomly.py index 64b35e8e5..0b09d235d 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 9a33d36ec..19c432eaf 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 ebe5f43c2..f7dbe8974 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 583892e8b..fd576defa 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);