Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Tools => Topic started by: Kopachris on March 21, 2011, 10:04:20 pm

Title: POF importer for Blender - WIP
Post by: Kopachris on March 21, 2011, 10:04:20 pm
Now, why hasn't anyone made a POF import/export script for Blender yet?  It's Python--it can't be that hard to write, especially with so much documentation on the file format.
Write it then.
Maybe I will! :P

After studying POF data structure (http://www.hard-light.net/wiki/index.php/POF_-_Formal_specification) and Blender import scripting (http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Advanced_Tutorials/Python_Scripting/Import_scripts) very carefully (read: after skimming through pages of documentation and hacking together some code), I think I have a small proof-of-concept for a POF import script for Blender.  It's obviously incomplete; all it really imports right now is the shield mesh.  As I go along with coding the rest of it, I'll try to follow the Blender to POF guide (http://www.hard-light.net/wiki/index.php/Blender_to_POF_Conversions) on the wiki as closely as possible.  I'll try to get the import fully-functional (except for texturing) by the end of this week.  An export script might have to wait until this summer.

Anyway, please download it and drop it in your Blender scripts folder and let me know if it works.  I've tested it on my computer, running Linux with Blender 2.49 and Python 2.6.5, but it should theoretically work on Windows or Mac with any Blender 2.4x release.  I've tested it with Fighter2T-02.pof and Bomber04.pof, and the shield mesh came up just fine both times.  This proof-of-concept is based on an earlier proof-of-concept that simply ran through all the POF chunks (except BSP data) and printed it to the command line.  I've attached both, if you want to take a look.  I'll be keeping the latest version here until I make an actual release.

The archive contains four Python scripts: bsp.py and pof.py simply read BSP and POF information from a .pof file and outputs the info to the command-line.  bsp_import.py and pof_import.py go into Blender's scripts folder, and import .pof files into Blender.  pof_import.py currently imports object and subobject geometry, shield geometry, a few helper empties (muzzleflashes and center of mass), and texture/uv mapping.  bsp_import.py imports BSP sortnorms from the first detail level of a .pof file as bounding boxes, and isn't really of much use, except as a curiosity.

A note on texturing and UV-mapping:
It doesn't seem to import correctly for all files.  For one, it should be noted that on Unix-based systems, the texture filenames are case-sensitive.  The script looks for (in this order) DDS, TGA, PNG, and JPG textures in "../maps," "./," "./maps," and "./data/maps."  I'll try to add something to let it ask for the texture locations and/or remove its case-sensitivity in the future.  Also, it seems that some models don't map correctly.  On those models, some detail levels, all subobjects, and all debris seem to texture just fine.  For example, detail-0 and detail-2 of Fighter2T-02.pof (Herc II) have trouble.  The UV map itself has faces in all the right places, it's just that they're not the right faces.  interesting note: Capital01.pof (Orion) seems to texture just fine.  Lastly, the importer doesn't create materials for the textures, only UV layers.  To get the models to render with the textures, you need to assign a material to them with "TexFace" (in the materials buttons, material tab) enabled.  You can use the same material for all models, and they'll use their own textures.

[attachment deleted by ninja]
Title: Re: POF importer for Blender - WIP
Post by: Zacam on March 21, 2011, 11:52:13 pm

YAY! This will be awesome, since one of the -biggest- Upgrade issues we have is the conversion from POF into something usable.

Granted, PCS2 now mitigates that to a great degree by letting one open the POF and save to DAE, but not everything imports DAE as nicely as it should (or occasionally export).

As Blender is one of the most popular (followed I think by Wings3D, Max then TrueSpace) having a single step process can only serve to speed things along.
Title: Re: POF importer for Blender - WIP
Post by: Rodo on March 21, 2011, 11:56:15 pm
Oh, great timing! I had Blender 2.49 deleted two months back and replaced it with 2.5 beta but it lacks dae importing capabilities so I was stuck, with this I might have an opportunity! :yes:
Title: Re: POF importer for Blender - WIP
Post by: esarai on March 22, 2011, 12:25:05 am
You sir, are a hero.  I wish something like this had existed when I first started modding. 
Title: Re: POF importer for Blender - WIP
Post by: headdie on March 22, 2011, 03:49:18 am
awesome, defiantly keeping an eye on this one.
Title: Re: POF importer for Blender - WIP
Post by: Kopachris on March 22, 2011, 04:57:30 pm
Oh, great timing! I had Blender 2.49 deleted two months back and replaced it with 2.5 beta but it lacks dae importing capabilities so I was stuck, with this I might have an opportunity! :yes:
Sorry, I'm currently using Blender 2.49, so a 2.5-compatible script won't be coming for a while.  That said, I'm making progress on the import script (a new version is attached).  I've never worked with BSP data (or much binary data at all) before, so this is a huge step for me.  Behold Fighter2T-02.pof:
(http://img535.imageshack.us/img535/3840/screenshot1zlr.png) (http://img535.imageshack.us/i/screenshot1zlr.png/)

I still need to get Blender to import subobjects hierarchically and import extra data (gun points, viewpoint, etc.) as empty meshes.  After that, I'll try to figure out texturing.
Title: Re: POF importer for Blender - WIP
Post by: Rodo on March 22, 2011, 11:44:55 pm
I see... well I might look into it to see if I can make it work with 2.5, just to kill some time.
Title: Re: POF importer for Blender - WIP
Post by: Spicious on March 23, 2011, 03:24:42 am
Have you considered working with PMF instead? (Or even contributing to PCS2?)

Oh, great timing! I had Blender 2.49 deleted two months back and replaced it with 2.5 beta but it lacks dae importing capabilities so I was stuck, with this I might have an opportunity! :yes:
Are there any specifics on what the problem is with 2.5?
Title: Re: POF importer for Blender - WIP
Post by: Kopachris on March 23, 2011, 11:39:43 am
Do you have a guide to running PCS2 on Linux?  If you do, that would help.  My main goal with writing an importer for Blender was to get around having to use Collada or Truespace as an intermediate format; it isn't to get around PCS2 entirely, unless there is no way to satisfactorily run PCS2 on Linux.  As it is, I might write the export script for PMF instead of POF to avoid having to figure out how to make a BSP tree.  In that case, some documentation on the format that would let me avoid looking through the PCS2 source code would help.
Title: Re: POF importer for Blender - WIP
Post by: pecenipicek on March 23, 2011, 11:41:02 am
Do you have a guide to running PCS2 on Linux?  If you do, that would help.  My main goal with writing an importer for Blender was to get around having to use Collada or Truespace as an intermediate format; it isn't to get around PCS2 entirely, unless there is no way to satisfactorily run PCS2 on Linux.  As it is, I might write the export script for PMF instead of POF to avoid having to figure out how to make a BSP tree.  In that case, some documentation on the format that would let me avoid looking through the PCS2 source code would help.
try and run it with wine, if that doesnt work, unfortunately windows is yer only choice.
Title: Re: POF importer for Blender - WIP
Post by: The E on March 23, 2011, 11:41:57 am
Well, it is based on wxWindows, so it should, in theory, be cross-platform
Title: Re: POF importer for Blender - WIP
Post by: Rodo on March 23, 2011, 11:54:25 am
Are there any specifics on what the problem is with 2.5?

Problem is caused by blender, dae support is not available yet on the beta version.
But the program itself presents with a more friendly interface and a better rendering engine, it's at least 1/3 faster than the older version, well...that's what I calculate from a few comparisons I made a while back.

Anyway I cannot be bothered to install python again when the beta version comes with that already included.
Title: Re: POF importer for Blender - WIP
Post by: Kopachris on March 23, 2011, 07:11:46 pm
PCS2 doesn't work very well in WINE, and I can't get it to build with scons.  Eh, it doesn't really matter, though.  I've got the script to the point where subobjects are parented and positioned correctly in Blender, and I'm working on importing other data as helper empties.  After that, texturing!  If there are any suggestions or requests (e.g. model scale and orientation on import--POF Z axis (bow to stern) = Blender Z axis right now), I'd be happy to listen.

I'll be keeping the latest version of the script in the OP until I make an actual release.
Title: Re: POF importer for Blender - WIP
Post by: Water on March 24, 2011, 12:59:39 am
If there are any suggestions or requests (e.g. model scale and orientation on import--POF Z axis (bow to stern) = Blender Z axis right now), I'd be happy to listen.

If you are doing just an importer, then having the ship point right (in side view) would keep it compatible with the dae exporter. If it will end up as an importer and exporter, then having the ship point left, in side view would be cool. (eg numpad 1 = front view)

For textures. PCS2 doesn't store the texture type, so having it check for both dds, and tga would make things a lot easier.
Title: Re: POF importer for Blender - WIP
Post by: Spicious on March 24, 2011, 06:12:24 am
PCS2 doesn't work very well in WINE, and I can't get it to build with scons.
Do you have all the dependencies installed?
Title: Re: POF importer for Blender - WIP
Post by: Kopachris on March 24, 2011, 05:55:31 pm
I just checked, and I definitely don't have the Collada library installed.  I tried building it, but it was missing something and I didn't feel like going to the trouble to make it work.  If you have some documentation about how PCS2 generates BSP trees, I'd greatly appreciate it if I could take a look at it.  In particular, I'd like to know how PCS2 decides where to bisect the model.  For example, the SF Mara's model is first split right down the middle, bow to stern, while the GTD Orion's model is split about 2/3 of the way from the stern.  After I get helpers and textures working on this import script, I want to work on putting all this in a Python module so that I can make a cleaner and more flexible import/export script.  As I've never worked with BSP trees before, some help in that area would be nice.
Title: Re: POF importer for Blender - WIP
Post by: Spicious on March 25, 2011, 07:09:23 pm
I just checked, and I definitely don't have the Collada library installed.  I tried building it, but it was missing something and I didn't feel like going to the trouble to make it work.
Make sure you run make from the dom directory; otherwise it'll try to build some ps3 thing.

Quote
If you have some documentation about how PCS2 generates BSP trees, I'd greatly appreciate it if I could take a look at it.
Does not exist. Try finding Kazan if you want definitive answers.
This is the other reason for PMF being a lot easier.

The current method is fairly horrible though, and loses/duplicates polygons. It's done in pcs_pof_bspfuncs.cpp:GenerateTreeRecursion.
At each recursion:

I have an alternative implementation (http://www.hard-light.net/forums/index.php?topic=73133.msg1479084#msg1479084) that's still in need of testers.
Title: Re: POF importer for Blender - WIP
Post by: Kopachris on March 25, 2011, 09:42:56 pm
Okay, thanks.  For an exporter proof-of-concept, I'll probably use PMF until I can write a BSP tree generator in Python (if I can write a BSP tree generator in Python).

I've updated the importer in the OP.
Title: Re: POF importer for Blender - WIP
Post by: Spicious on March 25, 2011, 10:30:34 pm
Doing it Python shouldn't be too hard, but doing it in pure Python is probably asking for painful performance.
Title: Re: POF importer for Blender - WIP
Post by: Kopachris on March 26, 2011, 10:52:20 pm
Just to try the importer out a little, I made a simple animation.  Just some Maras flying past an Orion.  The Orion isn't glow-mapped, but the Maras are.
http://www.youtube.com/watch?v=3Mvbk5FALKE
Title: Re: POF importer for Blender - WIP
Post by: bigchunk1 on April 07, 2011, 07:48:44 pm
 :yes: in support of this effort. If a completed version of it comes out, I most certainly will use it. Best of luck.
Title: Re: POF importer for Blender - WIP
Post by: rhettro on June 14, 2011, 02:26:53 pm
Given that Blender is free, modern and full featured, I have wondered why this hasn't happened sooner.  Thank you.
Title: Re: POF importer for Blender - WIP
Post by: chief1983 on June 15, 2011, 05:36:13 pm
You can already export to DAE in PCS2, which Blender can open.  What else do you need?
Title: Re: POF importer for Blender - WIP
Post by: Angelus on June 16, 2011, 03:30:58 pm
You can already export to DAE in PCS2, which Blender can open.  What else do you need?

A good pof to Max importer/ exporter.  :nervous:
---------------------------------------------------------------

Despite not being a Blender user, i support this and hope it'll work out.
Title: Re: POF importer for Blender - WIP
Post by: chief1983 on June 16, 2011, 04:34:00 pm
Wow, when I read this thread I totally missed the first page.  I didn't realized there was already work done at some point, although the attachment's been deleted.