- Implemented `cutout_depth_surface.py` for face separation and connected thickness calculations for depth surface assets. - Created `cutout_depth_surface_layout.py` to arrange nodes for staggered calculation branches in depth surface processing. - Authored `geometry_layouts.py` to define layouts for various geometry assets, including image cutouts and depth planes. - Introduced `node_layout.py` for shared presentation rules, facilitating node arrangement and validation in geometry-node layouts.
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
import unittest
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
|
SOURCE_ROOT = PROJECT_ROOT / "src" / "anyimage"
|
|
|
|
|
|
class NodeAssetsTest(unittest.TestCase):
|
|
def test_geometry_assets_have_readable_local_layouts(self):
|
|
import bpy
|
|
|
|
sys.path.insert(0, str(PROJECT_ROOT / "tools" / "node_assets"))
|
|
from node_layout import validate_node_layout
|
|
|
|
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
with bpy.data.libraries.load(
|
|
str(SOURCE_ROOT / "assets" / "O_AnyImage.blend")
|
|
) as (source, target):
|
|
target.node_groups = list(source.node_groups)
|
|
groups = [
|
|
group
|
|
for group in target.node_groups
|
|
if group.bl_idname == "GeometryNodeTree"
|
|
]
|
|
self.assertEqual(len(groups), 7)
|
|
for group in groups:
|
|
validate_node_layout(group)
|
|
|
|
def test_production_code_does_not_create_node_groups(self):
|
|
offenders = []
|
|
for path in SOURCE_ROOT.rglob("*.py"):
|
|
if "bpy.data.node_groups.new" in path.read_text(encoding="utf-8"):
|
|
offenders.append(path.relative_to(PROJECT_ROOT).as_posix())
|
|
self.assertEqual(offenders, [])
|
|
|
|
def test_runtime_node_group_entries_load_assets(self):
|
|
material_source = (SOURCE_ROOT / "common" / "material.py").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
mesh_plane_source = (
|
|
SOURCE_ROOT / "operators" / "convert_to_plane" / "mesh_plane.py"
|
|
).read_text(encoding="utf-8")
|
|
depth_plane_source = (
|
|
SOURCE_ROOT / "operators" / "convert_to_plane" / "object.py"
|
|
).read_text(encoding="utf-8")
|
|
self.assertIn("return load_node_group(group_name)", material_source)
|
|
self.assertIn(
|
|
"load_node_group(MESH_PLANE_NODE_GROUP_NAME)",
|
|
mesh_plane_source,
|
|
)
|
|
self.assertIn(
|
|
"load_node_group(DEPTH_PLANE_NODE_GROUP_NAME)",
|
|
depth_plane_source,
|
|
)
|
|
self.assertFalse(
|
|
(SOURCE_ROOT / "operators" / "convert_to_plane" / "nodes.py").exists()
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|