blender/tests/python/sculpt_paint/weight_paint_brushes_test.py
Sean Kim 010b904e5a Weight Paint: Update default settings and bundled assets
This PR makes a number of changes to the bundled essential brush assets
for Weight Paint, along with a number of other mode / default changes
to improve the experience for beginners.

### Brush Changes

* The default brush is now the "Add Weight" brush, which uses the "Add"
  blend mode, accumulation, and a low strength.
* The existing "Paint" brush is renamed to "Set Weight" and now has a
  Constant falloff curve. This brush also has a new icon to distinguish
  it from the "Add Weight" brush.
* The "Blur" brush has been changed to use accumulation with a low
  strength.
* For all brushes, the stroke spacing has been changed to 5% to feel
  more responsive.
* For all brushes which formerly used a Custom falloff curve that
  approximated a smoothstep function, the built-in "Smooth" curve is
  now used.

### Mode Changes
* Multi-Paint defaults to enabled
* Auto-Normalize defaults to enabled
* Mirror Vertex Groups defaults to enabled

Along with the above, the asset shelf is now shown by default in Weight
Paint mode, as there are now more brushes than tools in the toolbar.

Only the default startup files will use these new options, for existing
files, if the old "Paint" brush was active, the new "Add Weight" brush
will be active upon loading.

See #149470 for further context.

Asset PR: blender/blender-assets!67

Pull Request: https://projects.blender.org/blender/blender/pulls/158671
2026-06-05 23:34:27 +02:00

131 lines
3.8 KiB
Python

# SPDX-FileCopyrightText: 2025 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later */
"""
blender -b --factory-startup --python tests/python/sculpt_paint/weight_paint_brushes_test.py -- --testdir tests/files/mesh_paint/
"""
__all__ = (
"main",
)
import math
import numpy as np
import os
import pathlib
import sys
import unittest
import bpy
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from modules.test_helpers import set_view3d_context_override, generate_stroke
args = None
def get_weights(ob, vgroup):
group_index = vgroup.index
for i, v in enumerate(ob.data.vertices):
for g in v.groups:
if g.group == group_index:
yield (i, g.weight)
break
def get_attribute_data():
obj = bpy.context.object
mesh = bpy.context.object.data
num_elements = mesh.attributes.domain_size('POINT')
attribute_data = np.zeros(num_elements, dtype=np.float32)
if obj.vertex_groups.get('Group'):
vgroup = obj.vertex_groups[0]
for (idx, weight) in list(get_weights(obj, vgroup)):
attribute_data[idx] = weight
return attribute_data
class MeshBrushTests(unittest.TestCase):
"""
Test that none of the included brushes create NaN or inf valued vertices
"""
def setUp(self):
bpy.ops.wm.open_mainfile(filepath=str(args.testdir / "30k_monkey.blend"), load_ui=False)
bpy.ops.ed.undo_push()
bpy.ops.paint.weight_paint_toggle()
def _activate_brush(self, brush):
result = bpy.ops.brush.asset_activate(
asset_library_type='ESSENTIALS',
relative_asset_identifier='brushes/essentials_brushes-mesh_weight.blend/Brush/{}'.format(brush))
self.assertEqual({'FINISHED'}, result)
def _check_stroke(self):
initial_data = get_attribute_data()
context_override = bpy.context.copy()
set_view3d_context_override(context_override)
with bpy.context.temp_override(**context_override):
bpy.ops.paint.weight_paint(stroke=generate_stroke(context_override), override_location=True)
new_data = get_attribute_data()
# Note, depending on if the tests are run with asserts enabled or not, the test may fail before this point
# inside blender itself.
all_valid = all([not math.isinf(weight) and not math.isnan(weight) for weight in new_data])
any_different = any([orig != new for (orig, new) in zip(initial_data, new_data)])
self.assertTrue(all_valid, "All weights should be rational values")
self.assertTrue(any_different, "At least one weight should be different from its original value")
def test_add_weight_brush_creates_valid_data(self):
self._activate_brush("Add Weight")
self._check_stroke()
def test_set_weight_brush_creates_valid_data(self):
self._activate_brush("Set Weight")
self._check_stroke()
def test_average_brush_creates_valid_data(self):
self._activate_brush("Add Weight")
self._check_stroke()
self._activate_brush("Average")
self._check_stroke()
def test_blur_brush_creates_valid_data(self):
self._activate_brush("Add Weight")
self._check_stroke()
self._activate_brush("Blur")
self._check_stroke()
def test_smear_brush_creates_valid_data(self):
self._activate_brush("Add Weight")
self._check_stroke()
self._activate_brush("Smear")
self._check_stroke()
def main():
global args
import argparse
argv = [sys.argv[0]]
if '--' in sys.argv:
argv += sys.argv[sys.argv.index('--') + 1:]
parser = argparse.ArgumentParser()
parser.add_argument('--testdir', required=True, type=pathlib.Path)
args, remaining = parser.parse_known_args(argv)
unittest.main(argv=remaining)
if __name__ == "__main__":
main()