need help to build script (too difficult to resume !)

Hi all,

I’m using blender for a 2d cutout animation project, and I really need a script to automate some steps.
I’d like to know if it is possible before I try to build it.
Let me explain as simply as possible my problem with a few images :

So I have to set up a 2d character in blender, via transparent png’s.
The process is like this :

0: First the character is “cut” in different parts (legs, arms, torso, etc…). The result is 12 transparent png files in this example.

http://www.charlesrazack.com/3d/step0.jpg

then I manually import each part of the character in blender. I’d like the script to do those numerous steps automatically.

1: create a plane
2: uv-map the plane (simple default projection)
3: create a new material
3a: give that material the png’s name.
3b: settings: ref:1, spec:0
4: create a new texture
4a: give that texture the png’s name.
4b: settings: position:uv, canals:col + alpha
4c: type:image, path:same as the uv-map
5: resize the plane according to the png proportions

Here’s a mockup of what the script could look like, and how it would works.
–> you choose a png file…
…and than the script do the rest : create a plane, uv-map it with the png file, create the correct material and the correct texture, than apply the correct size to the plane.
The ideal would be to be able to choose an entire directory, and the script would process each file inside it… Maybe I’m asking too much.

http://www.charlesrazack.com/3d/step1a.gif

http://www.charlesrazack.com/3d/step1b.gif

So this was the process for just one part.
Now imagine your character is divided into 20+ parts. Then imagine you have 20+ characters or more, plus the backgrounds etc… Now you can figure why I need that script !
It would litterally save hours and hours of uneeded work.

That’s it for the basic explanation.
Now, my question : is it possible ?
I just want to know if I can achieve this with a python script, before I try to make it.
Well, I’m not really a kind of a programmer, but if I know it is feasible, I’m willing to learn python scripts. Because I really really need that script.
Well, I’m not asking anybody to make it for me, I suspect it could take quite some time to make.
But if anyone were willing to help me with the basis, or the tricky parts, I’d be really gratefull.

I used to work with flash for that kind of animation, basically you import a file, and that’s it, it’s ready to be animated.
I’d like to have the same behavior with blender, to avoid loosing hours just setting up the characters.
because blender is so powerfull for animation… well, you must know that.

So ANY help or advice will be greatly apreciated.
Thanks for taking the time to read that long post.

Regards,

ps : small example of the wip projet :
http://www.charlesrazack.com/3d/example1.jpg

You might want to check out ROTOBox script for the UV mapping part. It can be found at http://blenderartists.org/forum/showthread.php?t=55110 .

Try to find scripts that do parts of the requirements to get clue about how to proceed.

One alternative would be to use InkScape (it has PoTrace which can be used to convert raster image to vector one) and then import created parts as vector. You get models straight and there’s no need for UV mapping at all.

Thanks very much BeBraw.
I found a script that does almost all I was looking for. Still have to tweak the uv-mapping part (rotobox script seems also to fit, but it’s quite complicated for a beginner like me).

But there’s still one part that bothers me : I can create a mesh, a material, but impossible to assign the material to the mesh… I think there’s some basicall syntax I didn’t understood…
I found some piece of code somewhere that seems to work, but then the rest of the script doesn’t work anymore.
Here’s what I have :


nom = myImage.getName()
(...)
me = Mesh.Primitives.Plane (largeur)
(...)
mat = Material.New (nom) 
(...)
me=NMesh.GetRaw()    
mat_nom = Material.Get(nom)
me.addMaterial(mat_nom)

Why can’t I just put something like me.addMaterial(mat) ?

The code you need to add a material (assuming everything else in order) is:


me.materials += [mat_nom]

[Edit]
I spent some time writing this script for practice. If you want to use it go ahead, if not you can just disregard this. I want to add some more features to it (thats why the gigantic red portion is on the UI), but this is it for now, it does what you seemed to indicate you wanted. If anything is amiss with how the materials get assigned, let me know so I can fix it. I should really add copyright and gpl to it, but maybe later

You can download it here.

Holly sh*t !
That’s Exactly what I was looking for !
From what I could see, everything seems to work perfectly. (Have to test it a little further, though).
Thank you so much !

Ps : I think you should post it on a new thread once you think you’re finished with it, because it is extremely usefull from a 2d animator point of view.

Ps2 : my two little crits are
_When you import a whole directory, all the planes are atthe same location in the viewport.
_also, the transparency doesn’t show in the viewport, but I’m not sure it’s related to the script. I once got blender to show transparency from png in the viewport, but I never could reproduce this behavior (I have to open the same blend file in order to see transparency…) Well, I don’t know if I’m clear.

Hey, ForTe, may I make a last suggestion (so that your script gets close to perfection) ?

From what I understood, when a mesh is created, its longest side is equal to one blender unit. So when you import a whole directory, all the meshes have more or less the same size (resulting in a foot as big as a torso, in my case).
I found a script from Papui that uses another workaround, so that the meshes are proportionnal between them.
I’ll try to mix this with your script to see if it work. (not sure though, regarding my python skills)

Here’s a little extract :


##----indice is the reduction Index so that planes are not super big if the image is too large-----
indice = 0.1

def my_callback (filename):
    print "you chose da file:", filename
    myImage= Image.Load (filename)
    dimensiones = myImage.getSize()
    ##I define the x size of the plane "equis" as the product (Image xsize*indice)
    equis = (dimensiones [0]*indice)
    ##I define the y size of the plane "ygriega" as the product (Igame ysize*indice)
    ygriega = (dimensiones [1]*indice)
    ##I found out the proportion between X and y size ("proporcion")
    proporcion = (ygriega/equis)
    ##I create the primitive plane with dimension ("equis","equis") link it to an object, to the scene etc...
    me = Mesh.Primitives.Plane (equis)
    ob = Object. New ("Mesh")
    ob.link (me)
    sc = Scene.GetCurrent()
    sc.link (ob)
    ##---and I scale it so that it´s final size keeps the aspect Ratio of the image 
    ob.setSize (1,proporcion,1)


Alright, I got something like that going now. I use a unit called “pixels per unit” which will import an image and scale it so that if an image is 1000x1000 and pixels per unit is 500, then the plane will be 2x2 blender units.

I got most of the stuff in the script I wanted to do (though I’m not happy with the limited number of options for materials so I will probably go back and make that more flexible), if there is anything else you think could improve the script, let me know. I’m going to post it to a new thread, though, so it can be more easily found.

New Thread

Allright forTe, you did a great great job.
I think I will make a tutorial some time to show the usefulness of your script to the world !
Thanks again.

This sounds really interesting and could really be useful for doing pre-production animated storyboards using sketches… dont you think?
Could you post the final script when you get a chance? Would also love to see a preview of your animation too!
take care

Most up to date version of the script is here:

http://blenderartists.org/forum/showthread.php?p=901220#post901220

As shown in my previous post. For animation previews I guess that’d be up to tcharlss.

@DrBouvierLeduc: Thanks a lot for your initiative! Where can i see more of your work?
@forTe: Thasnks a lot for your coding!!

As Dr. says, it’s really a nice tool for the 2d animator!

Hi… I´m Looking for some way to do Depth of Field using planes with transparent PNGs… using the node editor with the Defocus Filter, but the results are like this:

http://www.ies.ufscar.br/geminis/actual_results.jpg

http://www.ies.ufscar.br/geminis/explicacao.jpg
Any help is appreciated.
Thanks!

Can you not use render layers? Render the cube, blur it, and then render the plane in a separate render layer/image (hopefully the proper alpha is preserved) and then composite the plane over the cube.

You might try posting in the Composition forum here and see if anybody has any better/different ideas as well. It may be better than posting in the Python section.

Ooops… sorry for the post on the wrong area…
I´ve posted in the Compositing area now…
http://blenderartists.org/forum/showthread.php?t=137742

anyway, separate the plane from the background is´nt the soluction, since I´m willing to work with thousants of planes…unless someone makes a script that separate each plane on a render layer and makes the compositing on the render… and so I´m on the right area! hehehe :smiley:

Thanks for your help!

HI

Can you not use render layers? Render the cube, blur it, and then render the plane in a separate render layer/image (hopefully the proper alpha is preserved) and then composite the plane over the cube and i thank u…

Staffing service

Seo masterhttp://sentersoftech.com/senter/happy.gif