GIMP Plugin

I need to contribute in a more meaningful way here. Ingredients: GIMP Python 3D modeler or image viewer that supports importing of .obj files An image saying "Arch is the best!" Place this script somewhere where GIMP can find it. Maybe your plug-in directory, or like I do, in a user defined Python directory. Please ignore the redundant math and amatuerish Python. Put your created image (see above edit) and place it in it's own directory for your own sanity. Go into that directory from the terminal and run (replace gimp-2.5 with gimp-2.4 if that's your version). This may take a bit depending on how fast your computer is. (Replace "base_image.png" with your image file. Keep the quotes): gimp-2.5 -inbdf '(python-fu-pic-to-obj RUN-NONINTERACTIVE "base_image.png" 10 )''(gimp-quit 1)' When finished, open the resulting file "base_image.png.obj" in your 3D modeler or viewer. WARNING: This is a severely high-poly image. Every pixel was mapped!

#! /usr/bin/env python
from gimpfu import *

def pic_to_obj(file_name, depth):
    
    if depth==0:
        depth = 1
    
    depth = float(1000/depth)
    
    FILE = open(file_name + ".obj", "w")
    firstline = "g " + file_name + ".obj\n\n"
    FILE.writelines( firstline )
            
    image = pdb.gimp_file_load(file_name, file_name)
    drawable = pdb.gimp_image_get_active_layer(image)
        
    if pdb.gimp_drawable_is_gray(drawable)!= True:
        pdb.gimp_image_convert_grayscale(image)
            
    width = pdb.gimp_image_width(image)
    height = pdb.gimp_drawable_height(drawable)
        
    for j in range(height):
        for i in range(width):
            num_channels, pixel = pdb.gimp_drawable_get_pixel(drawable, i, j)
            list = "\nv " + str(float(i)/10) + " " + str(float(j)/10) + " " + str(float(pixel[0])/depth)
            FILE.writelines(list) 
            
        
    FILE.writelines( "\n" )
        
    for l in range((width)*(height-1)-1):
        if((l+1)%width)!=0:
            list = "\nf " + str(l+1) + " " + str(l+2) + " " + str(l+width+2) + " " + str(l+width+1)
            FILE.writelines(list)
            
    

register(
  "pic_to_obj", "", "", "", "", "",
  "<Toolbox>/Xtns/Languages/Python-Fu/pic_to_obj", "",
  [
  (PF_STRING, "file_name", "file_name", "file_name"),
  (PF_FLOAT, "depth", "depth", "depth")
  ],
  [],
  pic_to_obj
  )

main()

~ skottish, 2008-05-14 14:42:49

Comments

Post Comment