Previous Thread  Next Thread

chat icon Script to assign images to uvmaps

theuns

Posted: Fri Jan 25, 2013 4:49 pm
Joined: 04 Mar 2010
Posts: 4
I would like to loop through my objects and assign an image to each object uvmap automatically based on the image file name.

If I had 100 objects (same shape and same uvmap shape in my case) then the script should assign the images numbered 1.jpg, 2.jpg, 3.jpg etc. to the objects via a loop in the script.

I've tried recording this with the developer-macro recorder, but the part where I open the image file does not record at all, only the selection of the object and the tab-key to go to edit mode is recorded.

Does anyone have an idea where to find the python code to load an image to the uvmap?

Regards,
Reply with quote


CoDEmanX

Posted: Fri Jan 25, 2013 7:18 pm
Joined: 05 Apr 2009
Posts: 894
do the objects have independent materials / textures assigned already?
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Reply with quote


theuns

Posted: Fri Jan 25, 2013 9:01 pm
Joined: 04 Mar 2010
Posts: 4
CoDEmanX wrote:
do the objects have independent materials / textures assigned already?


I could assign materials/textures if required but I'm using the objects in game mode eventually, so not rendering them for animation.

Maybe some background of what I want to do will clarify Wink Basically something better than prezi, where I may use 3D blender models as part of my presentations.

I can already use the game engine to advance through a 3D "slideshow" presentation, where real 3d objects may be included in my presentation. My slides are 40 images that that are numbered from 0 to say 39, and in the blender file I have 40 objects (planes in my case, that were copied so that all are the same size). These planes must then be UVunwrapped giving a rectangular map, and each map gets the image with the same number assigned to it.

When I have a new presentation to give, I want to to replace the image files with new images(with the same names), run the script that will replace or reload the images?) and the slideshow game is ready to export?

I control the camera as the viewpoint for my slides, using the mouse, arrow keys and such together with a motion actuator.

I'm a lecturer and have been messing around with blender but never realy got into the programming side, so I basically need some example code of how to assign the image to a specific object. I know or could figure out the loop, I should think.

Thanks,
Reply with quote


CoDEmanX

Posted: Sun Jan 27, 2013 12:25 am
Joined: 05 Apr 2009
Posts: 894
you may be interested into browser-based presentation tools like impress.js:

http://bartaz.github.com/impress.js

Especially:
http://introtonode.herokuapp.com/

it's CSS3-based, so no real chance for 3d models in it, but still interesting project. There is actually a way for more complex 3d stuff with CSS shaders, but appears to be supported by Chrome Canary only: http://blattchat.com/2012/09/26/reveal-js-with-css-custom-filters/

However, there are also WebGL-based tools, mostly WIP, but you may take a look:

http://fhtr.blogspot.de/2010/10/webgl-presentation-editor-prototype.html

https://github.com/davertron/webgl-presentation


Back to Blender:

I assume you want to assign an image to all faces of an object, but not via materials / textures, but only uv_textures.

Code:
# Use the active object for this example
ob = bpy.context.object
me = ob.data

# Load image from file
img = bpy.data.images.load("the\\file\\path.ext")

for uv_tex_face in me.uv_textures.active.data:
    uv_tex_face.image = img


A really minimalistic example, you should actually check whether the image loading was successful and test if uv_textures is even available. But i hope you see how the basic image assignment works.
_________________
I'm sitting, waiting, wishing, building Blender in superstition...
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group