Skip to content

Commit c50360c

Browse files
BizaNatorclaude
andcommitted
Add Mask Colors feature - RGBA mask generation for Unreal materials
Integrates MaskColors_v1.py algorithms as a proper addon feature: - New mesh_ops/masks.py module with k-means clustering, color extraction, face-based assignment, manual color matching, and material slot mapping - Replaced stub operators (BD_OT_analyze_colors, BD_OT_auto_mask) with full implementations - Added BD_OT_manual_mask, BD_OT_clear_mask, BD_OT_mask_from_material - Expanded BD_MaskSettings with 13 new properties (input/output layers, channel ranks, tolerance, manual color picker, debug material toggle) - Full panel UI with mode-dependent sections (Auto/Manual/Material) - Creates RGBA vertex color masks for Unreal material channel customization Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 61323ec commit c50360c

File tree

7 files changed

+2178
-25
lines changed

7 files changed

+2178
-25
lines changed

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,76 @@ Mark edges for subdivision/remeshing or shading control.
206206

207207
---
208208

209+
## Mask Colors
210+
211+
Generate RGBA mask channels from existing vertex colors for Unreal Engine material customization.
212+
213+
### Channel Mapping
214+
215+
| Channel | Color | Unreal Usage |
216+
|---------|-------|--------------|
217+
| **BASE** | (0,0,0,0) | Unmasked - uses base parameter |
218+
| **PRIMARY** | R=1 | Designer-customizable primary color |
219+
| **SECONDARY** | G=1 | Designer-customizable secondary color |
220+
| **ACCENT** | B=1 | Designer-customizable accent color |
221+
| **EMISSIVE** | A=1 | Glow/emissive intensity |
222+
223+
### Modes
224+
225+
| Mode | Description |
226+
|------|-------------|
227+
| **Analyze** | Report color distribution (no changes) |
228+
| **Auto Mask** | K-means cluster colors, assign channels by cluster size rank |
229+
| **Manual** | Pick a color + tolerance, assign to a specific channel |
230+
| **Material** | Map material slots to channels by index order |
231+
232+
### Auto Mask Workflow
233+
234+
1. Ensure mesh has a "Color" vertex color layer (from VertexColors/Paint)
235+
2. Set **Clusters** (number of color groups to find)
236+
3. Enable **Face Based** for contiguous mask regions (recommended)
237+
4. Set **Channel Ranks** (0=largest cluster, 1=second largest, etc. -1=skip)
238+
5. Click **Auto Mask** - creates "Mask" color layer with R/G/B/A channels
239+
6. **Debug Material** auto-created for viewport preview
240+
241+
### Manual Mask Workflow
242+
243+
1. Switch to **Manual** mode
244+
2. Pick the **Color** to match (use eye dropper or enter values)
245+
3. Set **Tolerance** (how close colors must match, 0-1)
246+
4. Choose target **Channel** (Primary/Secondary/Accent/Emissive/Base)
247+
5. Click **Assign Color** - only matched loops are updated, existing assignments preserved
248+
6. Repeat for each color group
249+
250+
### Settings
251+
252+
| Setting | Default | Description |
253+
|---------|---------|-------------|
254+
| Input | "Color" | Source color layer name |
255+
| Output | "Mask" | Output mask layer name |
256+
| Clusters | 4 | Number of color groups for auto-mask |
257+
| Face Based | On | Contiguous face regions (recommended) |
258+
| Method | Dominant | How to pick face color (Dominant/Average/Center) |
259+
| Tolerance | 0.15 | Color match distance for manual mode |
260+
| Debug Material | On | Create emission material for preview |
261+
| Delete Source | Off | Remove source layer after mask creation |
262+
263+
### Unreal Material Setup
264+
265+
```
266+
Vertex Color (Mask layer)
267+
├── R → Lerp(BaseColor, PrimaryColor, R)
268+
├── G → Lerp(result, SecondaryColor, G)
269+
├── B → Lerp(result, AccentColor, B)
270+
└── A → Emissive multiplier
271+
```
272+
273+
---
274+
209275
## Python API
210276

211277
```python
212-
from braindead_blender.mesh_ops import colors, remesh, cleanup, decimate, normals
278+
from braindead_blender.mesh_ops import colors, remesh, cleanup, decimate, normals, masks
213279

214280
# Transfer vertex colors with solid face mode
215281
colors.transfer_vertex_colors(source_obj, target_obj, mode="FACE")
@@ -239,6 +305,20 @@ remesh.apply_sharp_remesh(obj, octree_depth=8)
239305
cleanup.fill_holes(obj, max_sides=100)
240306
cleanup.remove_internal_geometry(obj, method="RAYCAST")
241307
normals.fix_normals(obj, method="BOTH")
308+
309+
# Auto-mask with k-means clustering
310+
masks.auto_mask(obj, num_clusters=4, face_based=True, face_method="DOMINANT")
311+
312+
# Analyze color distribution
313+
colors_by_loop, colors_list = masks.extract_vertex_colors(obj, layer_name="Color")
314+
stats = masks.analyze_color_distribution(colors_list)
315+
316+
# Clear mask layer
317+
masks.clear_mask(obj, output_name="Mask")
318+
319+
# Material-based masking
320+
loop_assignments = masks.assign_by_material(obj, material_map=None)
321+
masks.create_mask_vertex_colors(obj, loop_assignments, output_name="Mask")
242322
```
243323

244324
---
@@ -258,7 +338,8 @@ BrainDeadBlender/
258338
│ ├── remesh.py # Remesh operations
259339
│ ├── cleanup.py # Cleanup/repair operations
260340
│ ├── normals.py # Normal operations
261-
│ └── decimate.py # Decimation operations
341+
│ ├── decimate.py # Decimation operations
342+
│ └── masks.py # Mask color generation (RGBA channels)
262343
263344
├── braindead_blender/ # Blender 5.0/4.2+ Extension
264345
│ ├── blender_manifest.toml # Extension manifest

0 commit comments

Comments
 (0)