Author Topic: POF importer for Blender - WIP  (Read 5579 times)

0 Members and 1 Guest are viewing this topic.

Offline Kopachris

  • 28
  • It's Pythonic
    • Steam
    • Twitter
    • HLP QuoteDB
POF importer for Blender - WIP
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 and Blender import scripting 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 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]
« Last Edit: May 30, 2011, 08:29:30 am by Kopachris »
--
Yo momma's so fat when she sits on a binary tree she flattens it to a linked list in constant time.

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Minecraft
    • Steam
    • Twitter
    • ModDB Feature
Re: POF importer for Blender - WIP

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.
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the FSU on #SCP-FSU Talk with the SCP on #SCP
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline Rodo

  • Custom tittle
  • 212
  • stargazer
    • Minecraft
    • Steam
Re: POF importer for Blender - WIP
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:
el hombre vicio...

 

Offline esarai

  • 29
  • Steathy boi
    • Minecraft
Re: POF importer for Blender - WIP
You sir, are a hero.  I wish something like this had existed when I first started modding. 
<Nuclear>   truth: the good samaritan actually checked for proof of citizenship and health insurance
<Axem>   did anyone catch jesus' birth certificate?
<Nuclear>   and jesus didnt actually give the 5000 their fish...he gave it to the romans and let it trickle down
<Axem>and he was totally pro tax breaks
<Axem>he threw out all those tax collectors at the temple
<Nuclear>   he drove a V8 camel too
<Nuclear>   with a sword rack for his fully-automatic daggers

Esarai: hey gaiz, what's a good improvised, final attack for a ship fighting to buy others time to escape to use?
RangerKarl|AtWork: stick your penis in the warp core
DarthGeek: no don't do that
amki: don't EVER do that

 

Offline headdie

  • i don't use punctuation lol
  • 212
  • Lawful Neutral with a Chaotic outook
    • Minecraft
    • Skype
    • Twitter
    • Headdie on Deviant Art
Re: POF importer for Blender - WIP
awesome, defiantly keeping an eye on this one.
Minister of Interstellar Affairs Sol Union - Retired
quote General Battuta - "FRED is canon!"
Contact me at [email protected]
My Release Thread, Old Release Thread, Celestial Objects Thread, My rubbish attempts at art

 

Offline Kopachris

  • 28
  • It's Pythonic
    • Steam
    • Twitter
    • HLP QuoteDB
Re: POF importer for Blender - WIP
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:


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.
« Last Edit: March 23, 2011, 07:12:06 pm by Kopachris »
--
Yo momma's so fat when she sits on a binary tree she flattens it to a linked list in constant time.

 

Offline Rodo

  • Custom tittle
  • 212
  • stargazer
    • Minecraft
    • Steam
Re: POF importer for Blender - WIP
I see... well I might look into it to see if I can make it work with 2.5, just to kill some time.
el hombre vicio...

 

Offline Spicious

  • Master Chief John-158
  • 210
Re: POF importer for Blender - WIP
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?

 

Offline Kopachris

  • 28
  • It's Pythonic
    • Steam
    • Twitter
    • HLP QuoteDB
Re: POF importer for Blender - WIP
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.
--
Yo momma's so fat when she sits on a binary tree she flattens it to a linked list in constant time.

 

Offline pecenipicek

  • Roast Chicken
  • 211
  • Powered by copious amounts of coffee and nicotine
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • PeceniPicek's own deviantart page
Re: POF importer for Blender - WIP
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.
Skype: vrganjko
Ho, ho, ho, to the bottle I go
to heal my heart and drown my woe!
Rain may fall and wind may blow,
and many miles be still to go,
but under a tall tree I will lie!

The Apocalypse Project needs YOU! - recruiting info thread.

 

Offline The E

  • He's Ebeneezer Goode
  • Global Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: POF importer for Blender - WIP
Well, it is based on wxWindows, so it should, in theory, be cross-platform
Let there be light
Let there be moon
Let there be stars and let there be you
Let there be monsters and let there be pain
Let us begin to feel again
--Devin Townsend, Genesis

 

Offline Rodo

  • Custom tittle
  • 212
  • stargazer
    • Minecraft
    • Steam
Re: POF importer for Blender - WIP
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.
el hombre vicio...

 

Offline Kopachris

  • 28
  • It's Pythonic
    • Steam
    • Twitter
    • HLP QuoteDB
Re: POF importer for Blender - WIP
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.
--
Yo momma's so fat when she sits on a binary tree she flattens it to a linked list in constant time.

 

Offline Water

  • 210
Re: POF importer for Blender - WIP
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.

 

Offline Spicious

  • Master Chief John-158
  • 210
Re: POF importer for Blender - WIP
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?

 

Offline Kopachris

  • 28
  • It's Pythonic
    • Steam
    • Twitter
    • HLP QuoteDB
Re: POF importer for Blender - WIP
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.
« Last Edit: March 24, 2011, 08:15:18 pm by Kopachris »
--
Yo momma's so fat when she sits on a binary tree she flattens it to a linked list in constant time.

 

Offline Spicious

  • Master Chief John-158
  • 210
Re: POF importer for Blender - WIP
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:
  • Filter the polygons list (with base cases for 1 or 0)
  • Pick the axis with greatest bounding box length; bisect to obtain the initial split point
  • While either half is empty, bisect the non-empty half to obtain the new split point
  • While the numbers in each half aren't within a certain vicinity of even and don't add up for up to 15 tries, twiddle the split point by a shrinking geometric sequence factor of the length of the more populated half
  • Call GenerateTreeRecursion on each half

I have an alternative implementation that's still in need of testers.

 

Offline Kopachris

  • 28
  • It's Pythonic
    • Steam
    • Twitter
    • HLP QuoteDB
Re: POF importer for Blender - WIP
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.
--
Yo momma's so fat when she sits on a binary tree she flattens it to a linked list in constant time.

 

Offline Spicious

  • Master Chief John-158
  • 210
Re: POF importer for Blender - WIP
Doing it Python shouldn't be too hard, but doing it in pure Python is probably asking for painful performance.

 

Offline Kopachris

  • 28
  • It's Pythonic
    • Steam
    • Twitter
    • HLP QuoteDB
Re: POF importer for Blender - WIP
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
--
Yo momma's so fat when she sits on a binary tree she flattens it to a linked list in constant time.