blender/tests/python/ui_simulate/test_sculpt.py
Testfiya a1de44dd54 iOS: Bump version to 5.1.2
This commit bumps the `ios` branch from 5.0.0 alpha to 5.1.2 release.

I merged v5.0-release first then v5.1-release. So it was a sequential
merge.

I'm just waiting to the approval of continuing development.

The stuff that are missing (those are so close to implement):
- #145484 iOS: Keyboard Input Support: https://projects.blender.org/blender/blender/pulls/145484
- #145702 iOS: Add clipboard Image: https://projects.blender.org/blender/blender/pulls/145702
- Fix QOS threading
- Expose Downloads
- UIScene Migration

`make deps` needs to run two times. (still hacky....) OSL occurs racing
conditions.

Disclaimer: I used AI for searching in Documentation of Deps. So the
implementation is by hand. **SACRED PINKY FINGER PROMISE**

Pull Request: https://projects.blender.org/blender/blender/pulls/161073
2026-07-07 16:03:12 +02:00

314 lines
10 KiB
Python

# SPDX-FileCopyrightText: 2025 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
"""
This file does not run anything, its methods are accessed for tests by ``run_blender_setup.py``.
"""
import modules.ui_test_utils as ui
def asset_shelf_brush_selection():
e, t, window = ui.test_window()
yield e.shift.f5() # 3D Viewport.
yield e.ctrl.alt.space() # Full-screen.
yield e.ctrl.tab().s() # Sculpt via pie menu.
area = ui.get_window_area_by_type(window, 'VIEW_3D')
# We use this hardcoded area percent position because the asset shelf is very large, this centers the cursor
# in the correct position.
position = (area.x + int(area.width * 0.30), area.y + area.height // 2)
e.cursor_position_set(*position, move=True) # Move mouse
yield
yield e.shift.space() # Asset Shelf
yield e.text("Blob") # Search for "Blob"
yield e.esc()
# We repeat this again because the asset shelf is too large to fit on the screen the first time...
yield e.shift.space() # Asset Shelf
e.leftmouse.tap()
yield
import bpy
current_brush = bpy.context.tool_settings.sculpt.brush
t.assertEqual(current_brush.name, "Blob")
def _view3d_startup_area_maximized(e):
"""
Set the 3D viewport and set the area full-screen so no other regions.
"""
yield e.shift.f5() # 3D Viewport.
yield e.ctrl.alt.space() # Full-screen.
yield e.a() # Select all.
yield e.delete().ret() # Delete all.
def _reset_objects(e):
yield e.ctrl.tab().o() # Object Mode
yield e.a() # Select all.
yield e.delete().ret() # Delete all.
def _subdivide_mesh(e, times):
yield e.tab() # Enter Edit mode.
for i in range(times):
yield e.ctrl.e().d() # Subdivide.
yield e.tab() # Leave Edit mode.
def _create_test_monkey(e):
yield from ui.call_menu(e, "Add -> Mesh -> Monkey")
yield e.numpad_period() # View monkey
yield from _subdivide_mesh(e, 3)
yield e.ctrl.tab().s() # Sculpt via pie menu.
def _num_matching_face_set(face_set_id):
import bpy
import numpy as np
mesh = bpy.context.object.data
if not mesh.attributes.get('.sculpt_face_set'):
return 0
face_set_attr = mesh.attributes['.sculpt_face_set']
num_faces = mesh.attributes.domain_size('FACE')
face_set_data = np.zeros(num_faces, dtype=np.int32)
face_set_attr.data.foreach_get('value', face_set_data)
return np.count_nonzero(face_set_data == face_set_id)
def face_set_expand():
import bpy
e, t, window = ui.test_window()
yield from _view3d_startup_area_maximized(e)
yield from _create_test_monkey(e)
area = ui.get_window_area_by_type(window, 'VIEW_3D')
position = (area.x + area.width // 2, area.y + area.height // 2)
yield e.cursor_position_set(*position, move=True) # Move mouse to center
yield e.shift.w() # Expand operator
yield from _move_horizontal(e, position, 200)
e.leftmouse.tap()
yield
non_default_faces = _num_matching_face_set(2)
t.assertEqual(non_default_faces, 8682)
default_faces = _num_matching_face_set(1)
mesh = bpy.context.object.data
num_faces = mesh.attributes.domain_size('FACE')
t.assertEqual(default_faces + non_default_faces, num_faces)
def face_set_gestures():
e, t, window = ui.test_window()
yield from _view3d_startup_area_maximized(e)
# Box Face Set
yield from _create_test_monkey(e)
yield from ui.call_operator(e, "Box Face Set")
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_xy(window))
t.assertEqual(_num_matching_face_set(2), 29816)
yield from _reset_objects(e)
# Lasso Face Set
yield from _create_test_monkey(e)
t.assertEqual(_num_fully_masked_vertices(), 0)
yield from ui.call_operator(e, "Lasso Face Set")
center = ui.get_area_center_from_spacetype(window, 'VIEW_3D')
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_circle(center, 100))
t.assertEqual(_num_matching_face_set(2), 8749)
yield from _reset_objects(e)
# Line Face Set
yield from _create_test_monkey(e)
yield from ui.call_operator(e, "Line Face Set")
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_y(window))
t.assertEqual(_num_matching_face_set(2), 6795)
def _num_hidden_vertices():
import bpy
import numpy as np
mesh = bpy.context.object.data
if not mesh.attributes.get('.hide_vert'):
return 0
hide_attr = mesh.attributes['.hide_vert']
num_vertices = mesh.attributes.domain_size('POINT')
hide_data = np.zeros(num_vertices, dtype=np.bool)
hide_attr.data.foreach_get('value', hide_data)
return np.count_nonzero(hide_data)
def hide_gestures():
e, t, window = ui.test_window()
yield from _view3d_startup_area_maximized(e)
# Box Hide
yield from _create_test_monkey(e)
t.assertEqual(_num_hidden_vertices(), 0)
yield from ui.call_operator(e, "Box Hide")
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_xy(window))
t.assertEqual(_num_hidden_vertices(), 29029)
yield from _reset_objects(e)
# Lasso Hide
yield from _create_test_monkey(e)
t.assertEqual(_num_hidden_vertices(), 0)
yield from ui.call_operator(e, "Lasso Hide")
center = ui.get_area_center_from_spacetype(window, 'VIEW_3D')
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_circle(center, 100))
t.assertEqual(_num_hidden_vertices(), 8548)
yield from _reset_objects(e)
# Line Hide
yield from _create_test_monkey(e)
t.assertEqual(_num_hidden_vertices(), 0)
yield from ui.call_operator(e, "Line Hide")
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_y(window))
t.assertEqual(_num_hidden_vertices(), 6633)
def _move_horizontal(e, start_position, pixels):
for x in range(pixels // 10):
position = (start_position[0] + x * 10, start_position[1])
yield e.cursor_position_set(*position, move=True)
def _num_fully_masked_vertices():
import bpy
import numpy as np
mesh = bpy.context.object.data
if not mesh.attributes.get('.sculpt_mask'):
return 0
mask_attr = mesh.attributes['.sculpt_mask']
num_vertices = mesh.attributes.domain_size('POINT')
mask_data = np.zeros(num_vertices, dtype=np.float32)
mask_attr.data.foreach_get('value', mask_data)
return np.count_nonzero(mask_data == 1.0)
def mask_expand_and_invert():
e, t, window = ui.test_window()
yield from _view3d_startup_area_maximized(e)
yield from _create_test_monkey(e)
area = ui.get_window_area_by_type(window, 'VIEW_3D')
position = (area.x + area.width // 2, area.y + area.height // 2)
yield e.cursor_position_set(*position, move=True) # Move mouse to center
yield e.shift.a() # Expand operator
yield from _move_horizontal(e, position, 200)
e.leftmouse.tap()
yield
initial_masked_verts = _num_fully_masked_vertices()
t.assertEqual(initial_masked_verts, 8548)
yield e.a() # Mask pie menu
yield e.i() # Invert
inverted_masked_verts = _num_fully_masked_vertices()
t.assertEqual(inverted_masked_verts, 22598)
import bpy
mesh = bpy.context.object.data
total_verts = mesh.attributes.domain_size('POINT')
t.assertEqual(initial_masked_verts + inverted_masked_verts, total_verts)
def mask_gestures():
e, t, window = ui.test_window()
yield from _view3d_startup_area_maximized(e)
# Box Mask
yield from _create_test_monkey(e)
t.assertEqual(_num_fully_masked_vertices(), 0)
yield from ui.call_operator(e, "Box Mask")
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_xy(window))
t.assertEqual(_num_fully_masked_vertices(), 29029)
yield from _reset_objects(e)
# Lasso Mask
yield from _create_test_monkey(e)
t.assertEqual(_num_fully_masked_vertices(), 0)
yield from ui.call_operator(e, "Lasso Mask")
center = ui.get_area_center_from_spacetype(window, 'VIEW_3D')
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_circle(center, 100))
t.assertEqual(_num_fully_masked_vertices(), 8548)
yield from _reset_objects(e)
# Line Mask
yield from _create_test_monkey(e)
t.assertEqual(_num_fully_masked_vertices(), 0)
yield from ui.call_operator(e, "Line Mask")
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_y(window))
t.assertEqual(_num_fully_masked_vertices(), 6633)
def _create_test_cube(e):
yield from ui.call_menu(e, "Add -> Mesh -> Cube")
yield e.numpad_period() # View Cube
yield e.ctrl.tab().s() # Sculpt via pie menu.
def trim_gestures():
import bpy
e, t, window = ui.test_window()
yield from _view3d_startup_area_maximized(e)
# Box Trim
yield from _create_test_cube(e)
mesh = bpy.context.object.data
t.assertEqual(mesh.attributes.domain_size('POINT'), 8)
yield from ui.call_operator(e, "Box Trim")
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_xy(window))
t.assertEqual(mesh.attributes.domain_size('POINT'), 28)
yield from _reset_objects(e)
# Lasso Trim
yield from _create_test_cube(e)
mesh = bpy.context.object.data
t.assertEqual(mesh.attributes.domain_size('POINT'), 8)
yield from ui.call_operator(e, "Lasso Trim")
center = ui.get_area_center_from_spacetype(window, 'VIEW_3D')
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_circle(center, 100))
t.assertEqual(mesh.attributes.domain_size('POINT'), 88)
yield from _reset_objects(e)
# Line Trim
yield from _create_test_cube(e)
mesh = bpy.context.object.data
t.assertEqual(mesh.attributes.domain_size('POINT'), 8)
yield from ui.call_operator(e, "Line Trim")
yield from e.leftmouse.cursor_motion(ui.cursor_motion_data_y(window))
t.assertEqual(mesh.attributes.domain_size('POINT'), 10)