project-navigation
Personal tools

Author Topic: Help may be needed from someone who knows Python  (Read 6609 times)

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Help may be needed from someone who knows Python
« on: November 24, 2009, 02:29:49 am »
Well, I've tried out the new version of Blender, the 2.5 which has many new features for modeling and is re-designed, and found out that it uses an entirely re-written Python API and uses Python 3.x instead of the older 2.5 or 2.6 versions. I also found out that Python 3 is not backwards compatible with 2.x, which means the current Blender plug-in scripts written in Python won't work and need to be updated.

How this affects UFO AI is that the new Blender program coming out has very few import and export functions (for now, at least), and looking at the list I do *not* see MD2 format or anything for MD2 tags either.

While I'm sure that some of those old scripts will be updated by Blender developers at some point, the future updates will probably be for generic importers and exporters, and probably won't be for the TAGs that we need with the MD2 files.  The MD2 format itself might or might not be updated for the new Blender, I've heard some people say that MD2 is an old format that newer graphic engines don't favor, although I haven't done a lot of research on that point and hopefully I'm wrong (I've actually only seen a few forum/blog posts out there where MD2 is being described as an old format that isn't recommended for some other 3D engines, and I admit that isn't really a lot to draw an accurate conclusion from).

Myself, I don't know Python at all, and have no idea how to read it in 2.x or 3.x, much less have any skill to update the old scripts in the SVN to work with the new Blender.

I'm therefore guessing we could use a coder who knows Python who could update the scripts, and also shed more light on this issue (and correct any of my points where I'm wrong, I don't claim to be an expert at much of this).


P.S. - Sorry if I'm unclear, it's now late where I am and I'm dead tired (stayed up playing with the new Blender Alpha that came out).   :P

Offline caelum

  • Rookie
  • ***
  • Posts: 13
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #1 on: November 24, 2009, 02:41:22 am »
I am not a Python expert, but have had a bit of a look at it from time to time.

The differences from 2.x to 3.0 are listed here.

And there is a tool that is supposed to convert 2.x code into 3.0 code, find it at http://docs.python.org/dev/3.0/library/2to3.html#to3-reference

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #2 on: November 24, 2009, 02:21:47 pm »
Thanks for the links, although everything detailed on those pages is Greek to me.  After a lot of frustrating effort for a good hour, I managed to figure out how to get the conversion tool script to run on an old 2.x script, but unfortunately it doesn't work for Blender plug-ins.

I also read on a Blender forum that conversion tools don't work for the old plug-ins, just as I experienced, and the scripts have to be re-written manually, which is something beyond my expertise and ability at this point.

Even if you're not an expert, it sounds like you know more than I do about Python and we could probably use your help to update the custom scripts for exporting models for the game.  IIRC we have two scripts, one for exporting to MD2 and another for exporting the TAGs for the MD2s.

Offline bayo

  • Professional loser
  • Project Coder
  • Captain
  • ***
  • Posts: 733
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #3 on: November 24, 2009, 07:28:37 pm »
I dont think it is hard to convert a python script from 2.x to 3.x
But if the new Blender do not support old Blender interface, it is incredibly harder.
Then you should search a Blender scripter gurru :-)

Anyway, MD2 is a really common model format no (a little old too)? Blender should maintain somewhere scripts about that?
Or we use a custom MD2 model? i hope we dont.

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #4 on: November 24, 2009, 07:41:49 pm »
Well, I know that the new python 3.x versions are not compatible with 2.x versions after being totally redesigned, but as for whether or not the new Blender interface is a lot different or not I'm really not sure.

Yes, MD2 is common, which means that there's still a good chance someone who writes stuff for Blender will write an updated export plug-in, although I'm not sure about a TAG exporter, as that does not come with the old (2.4x) version of Blender.

I've never touched Python until just now, I don't think converting scripts from 2.x to 3.1 is within my skills as I don't even know the basics of the Python language.

I'm hoping someone with at least a little experience with Python will come forward and help, even if they aren't a guru...

Edit: I suppose for now I could export it to some format that 2.49b would read, and then re-export it again to MD2.
« Last Edit: November 24, 2009, 07:44:19 pm by Destructavator »

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #5 on: November 24, 2009, 07:54:19 pm »
Not sure how related this is, but this might shed some more light on the issue:

http://wiki.blender.org/index.php/BlenderDev/Blender2.5/PythonAPI_31

Most of this I don't understand.   ???

Offline caelum

  • Rookie
  • ***
  • Posts: 13
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #6 on: November 24, 2009, 11:29:00 pm »
This seems to be talking about packaging Python with Blender, so you don't have to install it on your own, rather than converting scripts and such.

I am happy to take a look at the Python scripts if you want. I don't know how much help i'll be, but I might be able to modify them.

If it is only a matter of getting them to work with Python 3.0 then it might not be too bad. But if the Blender API has changed then it will be more difficult, since I have no experience with Blender.

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #7 on: November 25, 2009, 02:07:44 am »
That would be great if you would help out, the 2.5 Blender download just got put on the official site:

http://www.blender.org/download/get-25-alpha/

When starting it up there is a button on the initial splash for the API reference.

You can find UFO:AI's old python blender scripts here:

http://ufoai.svn.sourceforge.net/viewvc/ufoai/ufoai/trunk/src/tools/blender/

BTW, I think the new Blender uses Python 3.1, not 3.0, although I could be wrong.

Also, if you get working scripts together it would be nice if you also shared them with the Blender developers, or posted it on their forum, I'm sure many people would thank you.

Offline caelum

  • Rookie
  • ***
  • Posts: 13
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #8 on: November 25, 2009, 09:43:10 pm »
I managed to remove the syntax complaints that Python has with the scripts. But I suspect that is all that the automatic conversion tool does as well, so more will need to be done.

I will have to learn enough about Blender to actually load the scripts and see how they work.

Most of the scripts just need to change the print functions to stop syntax complaints.
So instead of:
Code: [Select]
print ""
it will be
Code: [Select]
print("")

Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #9 on: November 25, 2009, 10:33:45 pm »
You probably wouldn't need to know a whole lot about Blender just to test exporting something - Which is good because some people study the software for years and still don't know what every single button does - and in fact the default cube that comes up when starting a new file/project or starting Blender (the 3D cube in the main display) is itself a (simple) mesh that can be exported.

If you need something textured or more complex (when you get to the point where it successfully creates files without bombing out with errors), just ask and I can provide plenty of Blender files with loaded models where you can simply load the file and then export it right away without having to do anything else, it'll be set to go for export.

I'm guessing the next step would be to try re-importing the created file and see how it looks.

Thanks again for helping.

Offline caelum

  • Rookie
  • ***
  • Posts: 13
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #10 on: November 26, 2009, 03:27:19 am »
Yeah, I should just have to learn how to start it up and run a script that i've created.

From what I gather the API has changed in the new version of Blender. So, for example, any code to create a GUI will need to be redone to match the new API.

As a start I might attempt to re-create the GUI with the new API. Then I will look at porting the actual functionality. I have no idea how difficult this will be, but i'll give it a shot until someone who knows more about it comes along  :).

Offline caelum

  • Rookie
  • ***
  • Posts: 13
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #11 on: November 26, 2009, 03:34:10 am »
Actually. I am probably better off attempting to port the functionality and leave out the GUI...

Offline caelum

  • Rookie
  • ***
  • Posts: 13
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #12 on: November 26, 2009, 10:11:55 am »
I put the export_md2 script into blender and started converting it.

Once you get past the Python syntax you need to convert to the new Blender API. They have actually made a fairly large number of changes.

I have been able to work out most of them so far by looking through the API documentation. but I am still unsure that the method I am replacing does the same thing. So I will need a number of models to test.

As well as one that should definitely work I will need files that fail the validation for various reasons or need to be adjusted, not centred, not at the right scale, rotated, not made of triangles, etc, etc.

Once we have it working again we can always post it on the blender forums to see if the guys there find any mistakes.



Offline Destructavator

  • Combination Multiple Specialty Developer
  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 1908
  • Creater of Scorchcrafter, knows the zarakites...
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #13 on: November 26, 2009, 11:52:40 pm »
OK, if you can come up with a detailed list (doesn't have to be complete, it can be expanded later if needed) of test models and what characteristics they need to test things, I can put together the models in Blend files and send them your way.

Offline caelum

  • Rookie
  • ***
  • Posts: 13
    • View Profile
Re: Help may be needed from someone who knows Python
« Reply #14 on: November 27, 2009, 02:10:06 am »
For the moment just one model that will definately work, and one that fails would be good. A model that is missing a texture map should fail the process.