Tests: Add sculpt.mask_from_cavity operator test
Adds a python test for the `sculpt.mask_from_cavity` operator, checking the function against a grid with a column of lowered points to simulate a cavity. Follow up to #135130 and !135139 Pull Request: https://projects.blender.org/blender/blender/pulls/135213
This commit is contained in:
@@ -80,6 +80,39 @@ class MaskByColorTest(unittest.TestCase):
|
||||
f"Vertex {i} should not be masked ({color_data[i]}) -> {mask_data[i]}")
|
||||
|
||||
|
||||
class MaskFromCavityTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
bpy.ops.wm.open_mainfile(filepath=str(args.testdir / "plane_with_valley.blend"), load_ui=False)
|
||||
bpy.ops.ed.undo_push()
|
||||
|
||||
def test_operator_masks_low_vertices(self):
|
||||
ret_val = bpy.ops.sculpt.mask_from_cavity()
|
||||
|
||||
self.assertEqual({'FINISHED'}, ret_val)
|
||||
|
||||
mesh = bpy.context.object.data
|
||||
position_attr = mesh.attributes['position']
|
||||
mask_attr = mesh.attributes['.sculpt_mask']
|
||||
|
||||
num_vertices = mesh.attributes.domain_size('POINT')
|
||||
|
||||
position_data = np.zeros((num_vertices, 3), dtype=np.float32)
|
||||
position_attr.data.foreach_get('vector', np.ravel(position_data))
|
||||
|
||||
mask_data = np.zeros(num_vertices, dtype=np.float32)
|
||||
mask_attr.data.foreach_get('value', mask_data)
|
||||
|
||||
for i in range(num_vertices):
|
||||
if position_data[i][2] < 0.0:
|
||||
self.assertEqual(
|
||||
mask_data[i],
|
||||
1.0,
|
||||
f"Vertex {i} should be fully masked ({position_data[i]}) -> {mask_data[i]}")
|
||||
else:
|
||||
self.assertNotEqual(mask_data[i], 1.0,
|
||||
f"Vertex {i} should not be fully masked ({position_data[i]}) -> {mask_data[i]}")
|
||||
|
||||
|
||||
def main():
|
||||
global args
|
||||
import argparse
|
||||
|
||||
Reference in New Issue
Block a user