Add new tests and functionality for image processing and geometry handling
- Introduced color_image.py for preparing standalone color images for tests. - Added hdr_image.py to create HDR textures for testing. - Implemented test_image_depth_panorama.py to evaluate panorama topology, UVs, and depth discontinuities. - Created test_shadeless.py to validate the opacity and HDR color endpoints of the Shadeless group. - Developed moge3_export.py for exporting dynamic MoGe-3 backbone and ONNX graphs. - Added material.py to inherit material slots onto generated geometry. - Built image_depth_panorama.py to construct a quad panorama with depth separation and sampling.
This commit is contained in:
52
tests/tools/nodes/test_shadeless.py
Normal file
52
tests/tools/nodes/test_shadeless.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""Render the bundled Shadeless group's opacity and HDR color endpoints."""
|
||||
|
||||
import bpy
|
||||
import numpy as np
|
||||
|
||||
from anyimage.common.node import load_node_group
|
||||
|
||||
|
||||
def test_shadeless_alpha_is_mixed_inside_the_group(tmp_path):
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
group = load_node_group("O Shadeless")
|
||||
inputs = {s.name: s for s in group.interface.items_tree if s.item_type == "SOCKET" and s.in_out == "INPUT"}
|
||||
assert list(inputs) == ["Color", "Alpha"] and inputs["Alpha"].default_value == 1
|
||||
scene = bpy.context.scene
|
||||
scene.render.engine = "CYCLES"
|
||||
scene.cycles.device = "CPU"
|
||||
scene.cycles.samples = 8
|
||||
scene.cycles.use_denoising = False
|
||||
scene.render.film_transparent = True
|
||||
scene.render.resolution_x, scene.render.resolution_y = 96, 32
|
||||
scene.render.resolution_percentage = 100
|
||||
scene.render.image_settings.file_format = "OPEN_EXR"
|
||||
scene.render.image_settings.color_mode = "RGBA"
|
||||
scene.render.image_settings.color_depth = "32"
|
||||
scene.render.filepath = str(tmp_path / "shadeless.exr")
|
||||
bpy.ops.object.camera_add(location=(0, 0, 5))
|
||||
scene.camera = bpy.context.object
|
||||
scene.camera.data.type = "ORTHO"
|
||||
scene.camera.data.ortho_scale = 3
|
||||
for index, alpha in enumerate((0, 0.5, 1)):
|
||||
bpy.ops.mesh.primitive_plane_add(size=1, location=(index - 1, 0, 0))
|
||||
material = bpy.data.materials.new(f"Alpha {alpha}")
|
||||
material.use_nodes = True
|
||||
material.node_tree.nodes.clear()
|
||||
shader = material.node_tree.nodes.new("ShaderNodeGroup")
|
||||
shader.node_tree = group
|
||||
shader.inputs["Color"].default_value = (4, 2, 0.5, 1)
|
||||
shader.inputs["Alpha"].default_value = alpha
|
||||
output = material.node_tree.nodes.new("ShaderNodeOutputMaterial")
|
||||
material.node_tree.links.new(shader.outputs[0], output.inputs["Surface"])
|
||||
bpy.context.object.data.materials.append(material)
|
||||
bpy.ops.render.render(write_still=True)
|
||||
image = bpy.data.images.load(scene.render.filepath, check_existing=False)
|
||||
try:
|
||||
pixels = np.array(image.pixels[:]).reshape(32, 96, 4)
|
||||
for index, alpha in enumerate((0, 0.5, 1)):
|
||||
patch = pixels[8:24, index * 32 + 8:index * 32 + 24]
|
||||
np.testing.assert_allclose(patch[..., 3].mean(), alpha, atol=0.035)
|
||||
np.testing.assert_allclose(pixels[16, 80, :3], (4, 2, 0.5), atol=1e-4)
|
||||
finally:
|
||||
bpy.data.images.remove(image)
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
Reference in New Issue
Block a user