def center_stable_surface(scene, a, state):
    """
    center a objects on their assigned surfaces.
    """
    if isinstance(a, str):
        a = [a]

    score = 0
    a_trimeshes = iu.meshes_from_names(scene, [state.objs[ai].obj.name for ai in a])

    for name, mesh in zip(a, a_trimeshes):
        obj_state = state.objs[name]
        obj = obj_state.obj
        for i, relation_state in enumerate(obj_state.relations):
            relation = relation_state.relation
            parent_obj = state.objs[relation_state.target_name].obj
            obj_tags = relation.child_tags
            parent_tags = relation.parent_tags
            parent_all_planes = state.planes.get_tagged_planes(parent_obj, parent_tags)
            obj_all_planes = state.planes.get_tagged_planes(obj, obj_tags)
            parent_plane = parent_all_planes[relation_state.parent_plane_idx]
            obj_all_planes[relation_state.child_plane_idx]

            if relation_state.parent_plane_idx >= len(parent_all_planes):
                logging.warning(
                    f"{parent_obj.name=} had too few planes ({len(parent_all_planes)}) for {relation_state}"
                )
                return False
            if relation_state.child_plane_idx >= len(obj_all_planes):
                logging.warning(
                    f"{obj.name=} had too few planes ({len(obj_all_planes)}) for {relation_state}"
                )
                return False

            splitted_parent = state.planes.extract_tagged_plane(
                parent_obj, parent_tags, parent_plane
            )
            parent_trimesh = add_to_scene(
                state.trimesh_scene, splitted_parent, preprocess=True
            )
            # splitted_obj = planes.extract_tagged_plane(obj, obj_tags, obj_plane)
            # add_to_scene(state.trimesh_scene, splitted_obj, preprocess=True)
            obj_centroid = mesh.centroid
            parent_centroid = parent_trimesh.centroid
            score += np.linalg.norm(obj_centroid - parent_centroid)

            iu.delete_obj(scene, splitted_parent.name)

    return score

    center a objects on their assigned surfaces.
    
infinigen/core/constraints/evaluator/node_impl/trimesh_geometry.py