Convert Empty to an Image 2.79/2.8

Does anyone know a way to make convert an empty object that is an image into a mesh in blender 2.8?

I use this a lot for building but need to be able to export this for others to work on in other programs max, Maya etc and do not want to have to redraw them as planes and map them every time.

I don’t know a way to transfer the empty object into a mesh, but you can try to use a built-in add-on called import images as planes.

Outdated! See below: Convert Empty to an Image 2.79/2.8


Here is a little script I quickly put together. Size and offset need to be done.
The add-on Import Images as Planes has to be active.

import bpy
import os

for obj in bpy.data.objects.values():
    if obj.type == 'EMPTY':
        if obj.empty_display_type == 'IMAGE':
            
            dir, name = os.path.split(obj.data.filepath)            
            bpy.ops.import_image.to_plane(files=[{"name":name, "name":name}], directory=dir, relative=False)
            
            plane_name = name.split(".")[0]
            img_as_plane = bpy.data.objects[plane_name]
            
            img_as_plane.location = obj.location
            img_as_plane.rotation_euler = obj.rotation_euler

#    Image Plane at Image Empty - sets an image plane at every image empty
#    Copyright (C) 2019 Daniel Engler

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <https://www.gnu.org/licenses/>.

import bpy


def get_image_by_filepath(filepath):
    """find image by filepath"""
    
    for img in bpy.data.images.values():
        if img.filepath == filepath:
            return img


def image_plane_at_image_emtpy(empty):
    """set image plane at given empty"""
    
    if empty.data.filepath:    
        img = get_image_by_filepath(empty.data.filepath)
    
    if not img:
        return
    
    cursor = bpy.context.scene.cursor
    cursor.location = (0,0,0)

    bpy.ops.mesh.primitive_plane_add(size=1, enter_editmode=False, location=(0,0,0))
    plane = bpy.context.object

    x = img.size[0] / 2000
    y = img.size[1] / 2000

    if x <= y:
        plane.scale.x = x / y        
    else:
        plane.scale.y = y / x

    lx = plane.location.x
    ly = plane.location.y    
    sx = plane.scale.x
    sy = plane.scale.y
    e_offx = empty.empty_image_offset[0]
    e_offy = empty.empty_image_offset[1]    
    
    cursor.location.x = lx - sx / 2 - sx * e_offx
    cursor.location.y = ly - sy / 2 - sy * e_offy
    
    bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
    bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)

    # set loc, rot, scale
    plane.location = empty.location
    plane.rotation_euler = empty.rotation_euler    
    plane.scale.x = empty.empty_display_size * empty.scale.x
    plane.scale.y = empty.empty_display_size * empty.scale.y
    
    # material setup
    mat = bpy.data.materials.new(img.name)
    mat.use_nodes = True
    plane.data.materials.append(mat)

    mat_output = mat.node_tree.nodes['Material Output']
    img_node = mat.node_tree.nodes.new(type="ShaderNodeTexImage")
    emit_node = mat.node_tree.nodes.new(type='ShaderNodeEmission')
    mat.node_tree.links.new(img_node.outputs['Color'], emit_node.inputs['Color'])
    mat.node_tree.links.new(emit_node.outputs[0], mat_output.inputs[0])
    
    img_node.image = img
    img_node.location.x = -500
    emit_node.location.x = -200


for obj in bpy.data.objects.values():
    if obj.type == 'EMPTY':
        if obj.empty_display_type == 'IMAGE':
            image_plane_at_image_emtpy(obj)

I can make this an add-on. Any suggestion for a better name instead of “Image Plane at Image Empty”?
It’s tested in 2.80 only.

I included the license just in case someone wants to use the little code snipped.

“Empty to Image Plane”?

1 Like

Job’s done!

2 Likes

Wow daniel this is amazing!!! Thank you so much