How to Unwrap to a particular image....

I am writing a script to do a bunch of stuff to ease a burden and I am trying to unwrap a UV to an image. I need to load the image in to the UV image editor and make it current in all the image editors so when I do the UV unwrap it get’s linked to the image. This way when I do projection painting blender grabs pixels from this… the correct image. How do I set an image as the main current image in python.

So basically

  1. I load an image from the hard drive (done)
  2. I create a new UV Map (done)
  3. I Set the image I opened as current in blender somehow (???)
  4. I unwrap with bpy.ops.uv.project_from_view() (done)

Step 4 ties the uv to the wrong image so I can’t projection paint. Any help is GREATLY appreciated as this one has driven me batty of late.

Could you find the clues in the BProjection addon in the python editor? I can’t code, but i figure you might find something there since it enables the reference to another image

Thanks, yes I will head there next.

A lot of that is in texture_paint_layer_manager.py addon.

You’re bprojection add on tip paid off (it looks like) There’s an apply image function that assigns an image to each face, so it looks like blender isn’t assigning an image to a UV Map, but each individual face inthe uv map… so to do it in python you need to do something like this:

img = bpy.data.textures[BProjection_Texture].image #make img my image
ob = context.object #ob is now my object
face = ob.data.polygons #face us my object’s faces
uvdata = ob.data.uv_textures.active.data #uvdata is my object’s uv data

then he has a piece of code that checks if each face is selected and assigns it to the image.

    for f,d in zip(face,uvdata):
        if f.select:
            d.image = img

This looks like it might work, I was missing the image uvdata assignment of an image piece. I’m going to try this tonight (can’t right now since I’m at work).

Thanks for the help:)

Much welcome, people always help me here very quickly. I thought that it might have the necessary bits because of how the projection plane behaves

To whom it may concern… my above attempt didn’t work… still looking… I’m going to have to wait a while until I have a few hours free to reverse engineer the entire bprojection script to figure this out.

Ok, I’ve spent a few hours on this to no avail. I’m throwing in the towel. To my knowledge there is no way in python to change the active image in all uv image editors and thereby allow the script to assign an image to a UVMap to set up texture painting, it’s a real shame or I’m and idiot, one of the two.

What was the problem that you were having with that code? I tested it and it did assign the image to the active UV

My problem is I’m trying to follow the work flow of projection painting. In that workflow you’re not using textures in BI, when you unwrap the object somehow blender remembers the active image over in the image editor and ties it to the UVMap. When you enter texture paint mode there’s a clone from UVMap check box and uvmap selector. Since the UVMap does not have a corresponding image selector (like it used to I believe a while back) the tying of the image to the uv map when you unwrapped it is key to projection painting, I can’t seem to do this in python.

the above code is tying faces to a BI texture which projection painting in it’s current workflow doesn’t seem to use anymore.

Actually its not assigning it to the texture, but assigning it to the image used by the texture. This a just the way they chose to go about getting the image. You could do it by img = bpy.data.images[‘myImage’]. Works the same, no texture needed.

Are you trying to get projection cloning to work in Cycles still? I have worked with the BProjection addon, and had some success using the addon to paint image textures that are on cycles diffuse shaders with attribute nodes naming the uv layer. I did however find an impasse when trying to do clone projection painting from one uv layer to another with the default clone/stencil tools in texture paint, and found that the desired behaviour only happened in blender internal renderer. I’ve since started thinking that BI is best for the artistic painting and texture baking aspects, and that these textures can then be plugged into shaders for use in cycles.

Craig,

I gave up on cycles, it broke projection painting thoroughly. I’m not using bprojection work flow because I have an exported collada file from another piece of software that has the exact camera positions. I match the images with the camera positions exactly and then projection paint from a project from view unwrap from the camera position. I then wish to paint the photograph from that uvmap to the one I created for the object.

cmomoney,

yeah you’re right, I know it isn’t using the textures, but I need to projection paint from a specific uvmap and image to another uvmap and image. When you’re doing that blender knows you’re using one set and going to the other automagically by which image you have selected in the uvimage editor when you unwrap to create the uvmap. Assigning each face to an image doesn’t tell projection paint you want this uvmap to be tied to this image, just individual faces. You know it’s working right when you have two images in the uvimage editor and it switches to the correct image when you select the uvmap and then the uvimage editor switches over to the other image when you select the other uvmap.

It’s this kind of workflow:

I guess I’ll start looking through blender source code to figure this out…

the Material Utils addon may be relevant to you. You can transfer image assignments from mesh faces to uv editor and vice versa.

I don’t know how much you are getting to work through coding, but the most mind blowing stuff I read from Psy-Fy’s wiki pages explaining the GSOC was that stuff about the use of ray casting to determine texture painting, and how it calculated for position on face. Crazy stuff, made my head hurt.