feat(node_assets): add image plane geometry nodes and validation scripts
- Implemented `image_plane.py` to build the Image Plane Geometry Nodes group with customizable parameters for geometry, subdivide, and thickness. - Created `image_plane_validation.py` to validate the functionality of the image plane, ensuring correct geometry generation and material assignment. - Developed `material_layers.py` to construct shader node groups for image materials, including depth and normal handling. - Authored `plane_layouts.py` to define node arrangements for image geometry assets. - Introduced `shadeless.py` to create a shadeless shader node group that displays color without scene lighting while preserving shadows and reflections.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Mesh Plane and Depth Plane conversion operators."""
|
||||
"""Rectangular Plane and Depth Plane conversion operators."""
|
||||
|
||||
from .conversion import (
|
||||
ConvertToDepthPlane,
|
||||
|
||||
@@ -46,7 +46,7 @@ class GenerateDepthPlane(JobOperatorBase, bpy.types.Operator):
|
||||
bl_idname = "anyimage.generate_depth_plane"
|
||||
bl_label = "Generate Depth Plane"
|
||||
job_type = "generate-depth-plane-geometry"
|
||||
starting_message = "Preparing Depth Plane"
|
||||
starting_message = "Preparing depth conversion"
|
||||
|
||||
input_path: bpy.props.StringProperty(options=_HIDDEN)
|
||||
source_object_name: bpy.props.StringProperty(options=_HIDDEN)
|
||||
@@ -94,7 +94,7 @@ class GenerateDepthPlane(JobOperatorBase, bpy.types.Operator):
|
||||
def start_depth_plane_job(operator, context):
|
||||
source_object = context.object
|
||||
if video_total_frames(source_object.data) != 1:
|
||||
operator.report({"ERROR"}, "Depth Plane currently supports still images")
|
||||
operator.report({"ERROR"}, "Depth conversion currently supports still images")
|
||||
return {"CANCELLED"}
|
||||
setup_result = invoke_ai_setup_if_needed()
|
||||
if setup_result is not None:
|
||||
@@ -157,7 +157,7 @@ class ConvertToPlane(bpy.types.Operator):
|
||||
class ConvertToDepthPlane(bpy.types.Operator):
|
||||
bl_idname = "anyimage.convert_to_depth_plane"
|
||||
bl_label = "Convert to Depth Plane"
|
||||
bl_description = "Convert the complete Image Empty into a front-projected relief"
|
||||
bl_description = "Convert the complete Image Empty into a Relief or Camera depth plane"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
mesh_detail: bpy.props.IntProperty(name="Subdivide", default=6, min=0, max=10)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Create Mesh Plane objects used by conversion and clipboard paste."""
|
||||
"""Create Image Plane objects used by conversion and clipboard paste."""
|
||||
|
||||
import bpy
|
||||
|
||||
@@ -6,10 +6,10 @@ from ...common.object import modifier_input_identifier, set_modifier_input
|
||||
from ...common.node import load_node_group
|
||||
|
||||
|
||||
MESH_PLANE_NODE_GROUP_NAME = "O Mesh Plane"
|
||||
IMAGE_PLANE_NODE_GROUP_NAME = "O Image Plane"
|
||||
|
||||
|
||||
def build_mesh_plane_matrix(matrix_world, bounds):
|
||||
def build_image_plane_matrix(matrix_world, bounds):
|
||||
from mathutils import Matrix
|
||||
|
||||
x_min, x_max, y_min, y_max = bounds
|
||||
@@ -17,7 +17,7 @@ def build_mesh_plane_matrix(matrix_world, bounds):
|
||||
return matrix_world @ Matrix.Translation(center)
|
||||
|
||||
|
||||
def create_mesh_plane_mesh(name, bounds):
|
||||
def create_image_plane_mesh(name, bounds):
|
||||
x_min, x_max, y_min, y_max = bounds
|
||||
if x_max <= x_min or y_max <= y_min:
|
||||
raise ValueError("The plane has invalid dimensions")
|
||||
@@ -46,14 +46,14 @@ def create_mesh_plane_mesh(name, bounds):
|
||||
return mesh
|
||||
|
||||
|
||||
def add_mesh_plane_processing(
|
||||
def add_image_plane_processing(
|
||||
plane_object,
|
||||
subdivisions=0,
|
||||
thickness=0.0,
|
||||
):
|
||||
node_group = load_node_group(MESH_PLANE_NODE_GROUP_NAME)
|
||||
node_group = load_node_group(IMAGE_PLANE_NODE_GROUP_NAME)
|
||||
modifier = plane_object.modifiers.new(
|
||||
name=MESH_PLANE_NODE_GROUP_NAME,
|
||||
name=IMAGE_PLANE_NODE_GROUP_NAME,
|
||||
type="NODES",
|
||||
)
|
||||
modifier.node_group = node_group
|
||||
@@ -68,7 +68,7 @@ def add_mesh_plane_processing(
|
||||
return modifier
|
||||
|
||||
|
||||
def create_mesh_plane_object(
|
||||
def create_image_plane_object(
|
||||
context,
|
||||
name,
|
||||
bounds,
|
||||
@@ -77,7 +77,7 @@ def create_mesh_plane_object(
|
||||
subdivisions=0,
|
||||
thickness=0.0,
|
||||
):
|
||||
mesh = create_mesh_plane_mesh(name, bounds)
|
||||
mesh = create_image_plane_mesh(name, bounds)
|
||||
mesh.materials.append(material)
|
||||
plane = bpy.data.objects.new(name, mesh)
|
||||
context.collection.objects.link(plane)
|
||||
@@ -85,8 +85,8 @@ def create_mesh_plane_object(
|
||||
from mathutils import Matrix
|
||||
|
||||
matrix_world = Matrix.Identity(4)
|
||||
plane.matrix_world = build_mesh_plane_matrix(matrix_world, bounds)
|
||||
add_mesh_plane_processing(
|
||||
plane.matrix_world = build_image_plane_matrix(matrix_world, bounds)
|
||||
add_image_plane_processing(
|
||||
plane,
|
||||
subdivisions=subdivisions,
|
||||
thickness=thickness,
|
||||
@@ -23,16 +23,13 @@ from ...common.object import (
|
||||
set_modifier_input,
|
||||
)
|
||||
from ...common.node import load_node_group
|
||||
from .mesh_plane import (
|
||||
build_mesh_plane_matrix,
|
||||
create_mesh_plane_mesh,
|
||||
create_mesh_plane_object,
|
||||
from .image_plane import (
|
||||
build_image_plane_matrix,
|
||||
create_image_plane_mesh,
|
||||
create_image_plane_object,
|
||||
)
|
||||
|
||||
|
||||
DEPTH_PLANE_NODE_GROUP_NAME = "O Image Depth Plane"
|
||||
|
||||
|
||||
def create_color_image(source_object):
|
||||
source = source_object.data
|
||||
image = source.copy()
|
||||
@@ -49,7 +46,7 @@ def create_color_image(source_object):
|
||||
|
||||
def create_plane_object(context, source_object, subdivisions, material):
|
||||
source_name = source_object.name
|
||||
plane = create_mesh_plane_object(
|
||||
plane = create_image_plane_object(
|
||||
context,
|
||||
source_name,
|
||||
image_empty_bounds(source_object),
|
||||
@@ -71,35 +68,42 @@ def create_depth_plane_object(
|
||||
depth_image,
|
||||
depth_metadata,
|
||||
):
|
||||
node_group = load_node_group("O Image Depth Plane")
|
||||
source_name = source_object.name
|
||||
bounds = image_empty_bounds(source_object)
|
||||
mesh = create_mesh_plane_mesh(source_name, bounds)
|
||||
for polygon in mesh.polygons:
|
||||
polygon.use_smooth = True
|
||||
mesh.materials.append(material)
|
||||
plane = bpy.data.objects.new(source_name, mesh)
|
||||
context.collection.objects.link(plane)
|
||||
plane.matrix_world = build_mesh_plane_matrix(source_object.matrix_world, bounds)
|
||||
plane["anyimage_mesh_shape"] = "DEPTH_PLANE"
|
||||
mesh = create_image_plane_mesh(source_name, bounds)
|
||||
plane = None
|
||||
try:
|
||||
for polygon in mesh.polygons:
|
||||
polygon.use_smooth = True
|
||||
mesh.materials.append(material)
|
||||
plane = bpy.data.objects.new(source_name, mesh)
|
||||
context.collection.objects.link(plane)
|
||||
plane.matrix_world = build_image_plane_matrix(source_object.matrix_world, bounds)
|
||||
plane["anyimage_mesh_shape"] = "DEPTH_PLANE"
|
||||
|
||||
node_group = load_node_group(DEPTH_PLANE_NODE_GROUP_NAME)
|
||||
modifier = plane.modifiers.new(name=node_group.name, type="NODES")
|
||||
modifier.node_group = node_group
|
||||
modifier.show_group_selector = False
|
||||
uniform_scale = depth_uniform_scale(source_object, depth_metadata)
|
||||
for name, value in (
|
||||
("Subdivide", max(0, min(10, int(subdivisions)))),
|
||||
("Thickness", 0.1),
|
||||
("Depth Scale", 1.0),
|
||||
("Reference Depth", depth_metadata["reference_depth"] * uniform_scale),
|
||||
("Uniform Scale", uniform_scale),
|
||||
("Depth Image", depth_image),
|
||||
):
|
||||
set_modifier_input(
|
||||
modifier,
|
||||
modifier_input_identifier(node_group, name),
|
||||
value,
|
||||
)
|
||||
modifier = plane.modifiers.new(name=node_group.name, type="NODES")
|
||||
modifier.node_group = node_group
|
||||
modifier.show_group_selector = False
|
||||
uniform_scale = depth_uniform_scale(source_object, depth_metadata)
|
||||
for name, value in (
|
||||
("Subdivide", max(0, min(10, int(subdivisions)))),
|
||||
("Depth Scale", 1.0),
|
||||
("Reference Depth", depth_metadata["reference_depth"] * uniform_scale),
|
||||
("Uniform Scale", uniform_scale),
|
||||
("Depth Image", depth_image),
|
||||
):
|
||||
set_modifier_input(
|
||||
modifier,
|
||||
modifier_input_identifier(node_group, name),
|
||||
value,
|
||||
)
|
||||
except Exception:
|
||||
if plane is not None:
|
||||
bpy.data.objects.remove(plane, do_unlink=True)
|
||||
if mesh.users == 0:
|
||||
bpy.data.meshes.remove(mesh)
|
||||
raise
|
||||
return finalize_object_result(context, source_object, plane)
|
||||
|
||||
|
||||
@@ -113,7 +117,7 @@ def create_depth_plane_from_result(context, result, operator):
|
||||
try:
|
||||
depth_metadata = load_depth_metadata(result.file("depth_metadata"))
|
||||
depth_image = load_depth_result_image(
|
||||
result.file("z_depth"),
|
||||
result.file("depth"),
|
||||
source_object,
|
||||
depth_metadata,
|
||||
)
|
||||
@@ -141,9 +145,10 @@ def create_depth_plane_from_result(context, result, operator):
|
||||
except Exception:
|
||||
if material is not None and material.users == 0:
|
||||
bpy.data.materials.remove(material, do_unlink=True)
|
||||
for image in (depth_image, normal_image):
|
||||
for image in (color_image, depth_image, normal_image):
|
||||
if image is not None and image.users == 0:
|
||||
bpy.data.images.remove(image, do_unlink=True)
|
||||
raise
|
||||
if "FINISHED" not in bpy.ops.ed.undo_push(message="Convert to Depth Plane"):
|
||||
raise RuntimeError("Unable to create the Convert to Depth Plane Undo step")
|
||||
label = "Convert to Depth Plane"
|
||||
if "FINISHED" not in bpy.ops.ed.undo_push(message=label):
|
||||
raise RuntimeError(f"Unable to create the {label} Undo step")
|
||||
|
||||
Reference in New Issue
Block a user