Skip to content

Commit ada3d6f

Browse files
committed
Texture Rigger 0.0.1
0 parents  commit ada3d6f

11 files changed

Lines changed: 1808 additions & 0 deletions

README

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# ENGLISH
2+
3+
# 2D Texture Rigger for Maya
4+
5+
## Installation
6+
7+
1. Drag and drop the `install.mel` file into your Maya viewport.
8+
2. A "TexRig" button will be created on your current shelf. Click it to open the tool.
9+
10+
## Usage
11+
12+
1. **Select Mesh & Position Locator:**
13+
* With the tool open, select your 3D mesh.
14+
* Click
15+
* Move the created locator to your desired texture position on the mesh.
16+
2. **Create Control System:**
17+
* Click the button in Step 2 to generate the surface-following control system.
18+
3. **Connect Texture:**
19+
* In Step 3, select your image file.
20+
* If your texture has an alpha channel, it will be automatically set up for transparency.
21+
* Click "Connect" to apply the texture.
22+
4. **Multiple Textures:**
23+
* You can run the tool again on the same mesh. Just provide a new "Object Prefix" in the tool's UI to create a separate texture rig without conflicts.
24+
25+
## Bugs and Issues
26+
27+
For any bugs or issues, please contact: civilihasan.64@gmail.com
28+
29+
# ////////////////////////////////////////////////////////////////////////////////////////////////////// #
30+
31+
# TÜRKÇE
32+
33+
# Maya için 2D Doku Rigleyici
34+
35+
## Kurulum
36+
37+
1. `install.mel` dosyasını Maya görüntüleme alanınıza sürükleyip bırakın.
38+
2. Mevcut rafınızda "TexRig" isimli bir buton oluşacaktır. Aracı açmak için bu butona tıklayın.
39+
40+
## Kullanım
41+
42+
1. **Mesh Seçimi ve Locator Konumlandırma:**
43+
* Araç açıkken, 3B meshinizi seçin.
44+
* Oluşturulan locator'ı mesh üzerinde dokunun olmasını istediğiniz konuma taşıyın.
45+
2. **Kontrol Sistemi Oluşturma:**
46+
* Yüzeyi takip eden kontrol sistemini oluşturmak için Adım 2'deki butona tıklayın.
47+
3. **Dokuyu Bağlama:**
48+
* Adım 3'te resim dosyanızı seçin.
49+
* Eğer dokunuz alfa kanalına sahipse, şeffaflık için otomatik olarak ayarlanacaktır.
50+
* Dokuyu uygulamak için "Bağla" butonuna tıklayın.
51+
4. **Birden Fazla Doku:**
52+
* Aracı aynı mesh üzerinde tekrar çalıştırabilirsiniz. Çakışma olmadan ayrı bir doku rigi oluşturmak için aracın arayüzünde yeni bir "Nesne Ön Eki" girmeniz yeterlidir.
53+
54+
## Hatalar ve Sorunlar
55+
56+
Herhangi bir hata veya sorun için lütfen iletişime geçin: civilihasan.64@gmail.com

TextureRiggerTool.py

Lines changed: 384 additions & 0 deletions
Large diffs are not rendered by default.
11.6 KB
Binary file not shown.
4.85 KB
Binary file not shown.
10.8 KB
Binary file not shown.
14.7 KB
Binary file not shown.

install.mel

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
2D Texture Rigger Installer
3+
Drag and drop this file into the Maya viewport to install.
4+
Copyright 2021 by Hasan Civili. All Rights Reserved. (Adapted for 2D Texture Rigger)
5+
*/
6+
7+
global proc textureRiggerToolInstall() {
8+
// Get the path of this MEL script
9+
// whatIs returns "Mel procedure found in: /path/to/install.mel"
10+
string $whatIsResult = `whatIs textureRiggerToolInstall`;
11+
string $scriptPathPrefix = "Mel procedure found in: ";
12+
int $prefixLength = size($scriptPathPrefix);
13+
string $thisMelFilePath = `substring $whatIsResult ($prefixLength + 1) 999`;
14+
15+
// Derive the path to install.py (assumed to be in the same directory)
16+
string $pythonInstallScriptPath = `substitute "install.mel" $thisMelFilePath "install.py"`;
17+
$pythonInstallScriptPath = fromNativePath($pythonInstallScriptPath); // Ensure forward slashes for Python
18+
19+
// Check if the python script exists
20+
if (!`filetest -f $pythonInstallScriptPath`) {
21+
warning ("2D Texture Rigger Installer: Cannot find install.py at: " + $pythonInstallScriptPath + "\\nPlease ensure install.py is in the same directory as install.mel.");
22+
return;
23+
}
24+
25+
// Escape backslashes in the path for the Python string literal
26+
// FromNativePath should give forward slashes. A Python raw string r'D:/path/to/file.py' is good.
27+
string $pythonInstallScriptPathEscaped = "r'" + $pythonInstallScriptPath + "'"; // Construct Python command to load and execute install.py
28+
// Using a simpler approach with direct execution
29+
string $pythonCommand = "";
30+
$pythonCommand += "import sys\n";
31+
$pythonCommand += "import os\n";
32+
$pythonCommand += "import maya.cmds as cmds\n";
33+
$pythonCommand += "script_path = " + $pythonInstallScriptPathEscaped + "\n";
34+
$pythonCommand += "print(f'[2D Texture Rigger Installer MEL] Attempting to execute {script_path}')\n";
35+
$pythonCommand += "try:\n";
36+
$pythonCommand += " # Add the directory to sys.path\n";
37+
$pythonCommand += " script_dir = os.path.dirname(script_path)\n";
38+
$pythonCommand += " if script_dir not in sys.path:\n";
39+
$pythonCommand += " sys.path.append(script_dir)\n";
40+
$pythonCommand += " print(f'[2D Texture Rigger Installer MEL] Added {script_dir} to sys.path')\n";
41+
$pythonCommand += " \n";
42+
$pythonCommand += " TEXTURERIGGER_SCRIPT_PATH = script_path\n";
43+
$pythonCommand += " \n";
44+
$pythonCommand += " # Execute the Python script. \n";
45+
$pythonCommand += " # The script itself (install.py) is expected to handle shelf button creation \n";
46+
$pythonCommand += " # via its 'if __name__ == \"__main__\":' block, using TEXTURERIGGER_SCRIPT_PATH.\n";
47+
$pythonCommand += " code_to_exec = open(script_path).read()\n";
48+
$pythonCommand += " exec(code_to_exec)\n";
49+
$pythonCommand += " print(f'[2D Texture Rigger Installer MEL] Python script execution finished: {script_path}')\n";
50+
$pythonCommand += "except Exception as e:\n";
51+
$pythonCommand += " print(f'[2D Texture Rigger Installer MEL] Error during Python script execution: {e}')\n";
52+
$pythonCommand += " import traceback\n";
53+
$pythonCommand += " traceback.print_exc()\n";
54+
55+
python($pythonCommand);
56+
}
57+
58+
// Call the installation procedure
59+
textureRiggerToolInstall();

install.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""
2+
Python script to create a shelf button for the 2D Texture Rigger in Maya.
3+
This script is executed by install.mel.
4+
Copyright 2025 by Hasan Çivili. All Rights Reserved. (Adapted for 2D Texture Rigger)
5+
"""
6+
import os
7+
import sys
8+
import maya.cmds as cmds
9+
import maya.mel as mel
10+
11+
def create_texture_rigger_shelf_button(install_script_path):
12+
"""Creates a shelf button for the 2D Texture Rigger."""
13+
try:
14+
if not install_script_path:
15+
cmds.warning("2D Texture Rigger Installer: Script path not provided to create_texture_rigger_shelf_button.")
16+
return
17+
18+
# script_dir is the directory where install.py (and uv_locator_tool.py) are located.
19+
script_dir = os.path.dirname(install_script_path)
20+
script_dir_norm = os.path.normpath(script_dir)
21+
22+
# The main tool script is TextureRiggerTool.py
23+
tool_module_name = "TextureRiggerTool" # Changed from "uv_locator_tool"
24+
tool_script_file = tool_module_name + ".py"
25+
tool_script_path_full = os.path.join(script_dir_norm, tool_script_file)
26+
27+
if not os.path.exists(tool_script_path_full):
28+
cmds.warning(f"2D Texture Rigger Installer: Main tool script '{tool_script_file}' not found at: {tool_script_path_full}")
29+
return
30+
31+
icon_name = "texture_rigger_icon.png" # Ensure this icon exists in the same directory
32+
icon_path = os.path.join(script_dir_norm, icon_name)
33+
icon_path_norm = os.path.normpath(icon_path)
34+
35+
if not os.path.exists(icon_path_norm):
36+
cmds.warning(f"2D Texture Rigger Installer: Icon file '{icon_name}' not found at: {icon_path_norm}. Using default Maya icon.")
37+
icon_path_for_shelf = "pythonFamily.png" # Default Maya icon
38+
else:
39+
icon_path_for_shelf = icon_path_norm
40+
41+
shelf_name = cmds.optionVar(q="currentShelf") # Get current active shelf
42+
if not shelf_name:
43+
# Fallback if no shelf is active, or create a specific one
44+
shelf_name = "Custom" # Or your preferred shelf name like "TextureTools"
45+
if not cmds.shelfLayout(shelf_name, exists=True):
46+
cmds.shelfLayout(shelf_name, parent="ShelfLayout") # Maya's main shelf area
47+
48+
# Ensure script_dir_norm uses forward slashes for the Python command string, or is a raw string
49+
escaped_tool_dir = script_dir_norm.replace("\\\\", "/").replace("\\", "/")
50+
51+
# This is the command that the shelf button will execute.
52+
# It correctly imports 'TextureRiggerTool' and calls its 'show_ui' function.
53+
shelf_command = f"""
54+
import sys
55+
import os
56+
import maya.cmds as cmds
57+
import importlib
58+
59+
tool_dir = r'{escaped_tool_dir}'
60+
tool_module_name = '{tool_module_name}'
61+
62+
if tool_dir not in sys.path:
63+
sys.path.append(tool_dir)
64+
65+
try:
66+
# Dynamically import the module
67+
module_to_run = importlib.import_module(tool_module_name)
68+
# Reload for development convenience
69+
importlib.reload(module_to_run)
70+
# Call the UI function
71+
module_to_run.show_ui()
72+
except ImportError as e_import:
73+
error_msg = f"2D Texture Rigger: IMPORT ERROR - {{e_import}}. Could not import '{{tool_module_name}}'. Ensure it is in: {{tool_dir}}."
74+
print(error_msg)
75+
cmds.warning(error_msg)
76+
except AttributeError as e_attr:
77+
error_msg = f"2D Texture Rigger: ATTRIBUTE ERROR - {{e_attr}}. Could not find 'show_ui' in '{{tool_module_name}}'."
78+
print(error_msg)
79+
cmds.warning(error_msg)
80+
except Exception as e_runtime:
81+
error_msg = f"2D Texture Rigger: RUNTIME ERROR - {{e_runtime}}."
82+
print(error_msg)
83+
cmds.warning(error_msg)
84+
"""
85+
86+
# Check if a button with this label already exists on the shelf
87+
shelf_buttons = cmds.shelfLayout(shelf_name, query=True, childArray=True) or []
88+
existing_button = None
89+
for btn in shelf_buttons:
90+
try:
91+
if cmds.shelfButton(btn, query=True, label=True) == "2D Texture Rigger": # Check for old or default label
92+
existing_button = btn
93+
break
94+
if cmds.shelfButton(btn, query=True, command=True) == shelf_command: # More robust check by command
95+
existing_button = btn
96+
break
97+
except RuntimeError: # Button might not be a shelfButton or might be deleted
98+
pass
99+
100+
button_label = "Texture Rigger" # <<< YENİ ETİKETİNİZİ BURAYA GİRİN
101+
102+
if existing_button:
103+
print(f"2D Texture Rigger Installer: Updating existing shelf button '{button_label}' on shelf '{shelf_name}'.")
104+
cmds.shelfButton(
105+
existing_button,
106+
edit=True,
107+
label=button_label,
108+
command=shelf_command,
109+
image=icon_path_for_shelf,
110+
imageOverlayLabel="TexRig", # Kısa overlay etiketi
111+
annotation="Runs the 2D Texture Rigger tool.",
112+
sourceType="python"
113+
)
114+
else:
115+
print(f"2D Texture Rigger Installer: Creating new shelf button '{button_label}' on shelf '{shelf_name}'.")
116+
cmds.shelfButton(
117+
parent=shelf_name,
118+
label=button_label,
119+
command=shelf_command,
120+
image=icon_path_for_shelf,
121+
imageOverlayLabel="TexRig", # Kısa overlay etiketi
122+
annotation="Runs the 2D Texture Rigger tool.",
123+
sourceType="python"
124+
)
125+
126+
cmds.confirmDialog(
127+
title="2D Texture Rigger Installer",
128+
message=f"2D Texture Rigger shelf button installed/updated on shelf '{shelf_name}' successfully!",
129+
button="OK"
130+
)
131+
132+
except Exception as e:
133+
error_message = f"2D Texture Rigger Installer: Failed to create shelf button. Error: {e}"
134+
print(error_message)
135+
import traceback
136+
traceback.print_exc()
137+
cmds.warning(error_message)
138+
139+
if __name__ == "__main__":
140+
# This block is executed when install.mel runs `exec(code_to_exec)`
141+
# TEXTURERIGGER_SCRIPT_PATH is globally defined by install.mel's python execution context.
142+
if 'TEXTURERIGGER_SCRIPT_PATH' in globals():
143+
create_texture_rigger_shelf_button(globals()['TEXTURERIGGER_SCRIPT_PATH'])
144+
else:
145+
# This case should ideally not happen if install.mel is used.
146+
cmds.error("2D Texture Rigger Installer: TEXTURERIGGER_SCRIPT_PATH global variable not found. Cannot determine script path for installation.")
147+

0 commit comments

Comments
 (0)