Dynaverse.net

Taldrenites => Starfleet Command Models => Topic started by: Kreeargh on February 12, 2010, 09:16:06 pm

Title: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 12, 2010, 09:16:06 pm
Blender to .mod scripts are there any working? Im thinking about blender since gmax is worthless for converting to any thing else but .mod . I do alot of other games work and milkshape wont open 1/3 of my work in .mod for convert.
Title: Re: Blender to .mod scripts are there any working?
Post by: yochenhsieh on February 13, 2010, 08:18:47 pm
There is nif tools with which you can export and import .nif format for Bridge commander in gmax.
http://niftools.sourceforge.net

Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 13, 2010, 11:10:02 pm
Someone was working on a blender mod script but that was a while back, i dont know how far they got with the project, since its not out yet im guessing its dead.
Its a read damn shame Gmax of all the free programs wont export to 3ds < a Max format while All other FRee 3d modeling programs can export to 3ds and Many other formats LOL.
 Thanks for the info guys  :thumbsup:
Title: Re: Blender to .mod scripts are there any working?
Post by: atheorhaven on February 17, 2010, 08:11:25 pm
I guess the big question these days is, what all does Blender currently export to?  Maybe there's something it'll export to that gmax will open natively for export to .MOD..
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on February 18, 2010, 01:07:41 am
I guess the big question these days is, what all does Blender currently export to?  Maybe there's something it'll export to that gmax will open natively for export to .MOD..


My thoughts when pursuing the .mod plugin for gmax were 1. It should be easy as it's basically just a recompile of the 3DS plugin. You just needed the gmax SDK. and 2, everything exports to .3ds which gmax can import, thus allowing for models to be made for SFC on free software.

I never cared about people being able to export .mod to other formats, which is where gmax falls short. I'll be honest. I'm still not concerned with people being able to get SFC models into other games. You can get Milkshape for really cheap to do that. Honestly, if Milkshape was capable of fully exporting to .mod I wouldn't have worried about a plugin for gmax. The Milkshape plugin is a bit of an abortion though. It's better than nothing, but not very good. There's also "Ultimate Unwrap 3D" (www.unwrap3d.com (http://www.unwrap3d.com)) which will open .mod files and save in tons of formats. It's also one of the best and easiest to use UV mapping tools around. It's not expensive either, $50-$60 USD, depending on version. Brad Bolthouse, the developer, is a pretty awesome guy too, IMHO.

Anyhow, has anyone approached someone who can do Blender plugins to see if they will/can do it? We have the 3DS source, if that would be of any help. My advice is if you really want it pop on over to the Blender forums and see.

Edit: Sorry, got a bit offtrack. Atheorhaven, the reason people want a .mod plugin for Blender is for importing .mod and then exporting to another format.
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 18, 2010, 02:44:43 am
I guess the big question these days is, what all does Blender currently export to?  Maybe there's something it'll export to that gmax will open natively for export to .MOD..


My thoughts when pursuing the .mod plugin for gmax were 1. It should be easy as it's basically just a recompile of the 3DS plugin. You just needed the gmax SDK. and 2, everything exports to .3ds which gmax can import, thus allowing for models to be made for SFC on free software.

I never cared about people being able to export .mod to other formats, which is where gmax falls short. I'll be honest. I'm still not concerned with people being able to get SFC models into other games. You can get Milkshape for really cheap to do that. Honestly, if Milkshape was capable of fully exporting to .mod I wouldn't have worried about a plugin for gmax. The Milkshape plugin is a bit of an abortion though. It's better than nothing, but not very good. There's also "Ultimate Unwrap 3D" ([url=http://www.unwrap3d.com]www.unwrap3d.com[/url] ([url]http://www.unwrap3d.com[/url])) which will open .mod files and save in tons of formats. It's also one of the best and easiest to use UV mapping tools around. It's not expensive either, $50-$60 USD, depending on version. Brad Bolthouse, the developer, is a pretty awesome guy too, IMHO.

Anyhow, has anyone approached someone who can do Blender plugins to see if they will/can do it? We have the 3DS source, if that would be of any help. My advice is if you really want it pop on over to the Blender forums and see.

Edit: Sorry, got a bit offtrack. Atheorhaven, the reason people want a .mod plugin for Blender is for importing .mod and then exporting to another format.


Yes i do wish to export some of MY OWN models that i mistakenly did not save a 3ds file of. But for the community read further.

IF there was a export plugin only many wouldnt mind at all it would allow many more options to create with . THe options are getting fewer these days , it wont be long before gmax is NOT avalable and then one will have to choose from Illegal or milkshape. Thats why a blender and or Wings3d and other plugins need to be created.
Not for the hacks,for the creators . BUt if the game is about dead then why bother huh  :-\.
Title: Re: Blender to .mod scripts are there any working?
Post by: intermech on February 18, 2010, 08:02:06 am
Does Gmax allow you to do break models? Milkshape does not.
Title: Re: Blender to .mod scripts are there any working?
Post by: GotAFarmYet? on February 18, 2010, 11:10:25 am
Does Gmax allow you to do break models? Milkshape does not.

Yes
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 18, 2010, 11:43:21 pm
I guess the big question these days is, what all does Blender currently export to?  Maybe there's something it'll export to that gmax will open natively for export to .MOD..


My thoughts when pursuing the .mod plugin for gmax were 1. It should be easy as it's basically just a recompile of the 3DS plugin. You just needed the gmax SDK. and 2, everything exports to .3ds which gmax can import, thus allowing for models to be made for SFC on free software.

I never cared about people being able to export .mod to other formats, which is where gmax falls short. I'll be honest. I'm still not concerned with people being able to get SFC models into other games. You can get Milkshape for really cheap to do that. Honestly, if Milkshape was capable of fully exporting to .mod I wouldn't have worried about a plugin for gmax. The Milkshape plugin is a bit of an abortion though. It's better than nothing, but not very good. There's also "Ultimate Unwrap 3D" ([url=http://www.unwrap3d.com]www.unwrap3d.com[/url] ([url]http://www.unwrap3d.com[/url])) which will open .mod files and save in tons of formats. It's also one of the best and easiest to use UV mapping tools around. It's not expensive either, $50-$60 USD, depending on version. Brad Bolthouse, the developer, is a pretty awesome guy too, IMHO.

Anyhow, has anyone approached someone who can do Blender plugins to see if they will/can do it? We have the 3DS source, if that would be of any help. My advice is if you really want it pop on over to the Blender forums and see.

Edit: Sorry, got a bit offtrack. Atheorhaven, the reason people want a .mod plugin for Blender is for importing .mod and then exporting to another format.


I have emaild 4 persons that claim to create blender stuff, All have offers of $. No responce yet.   Sorry Rod Not all of us are theivs ,if thats the thought { no offence intended}  i dont export any others work unless asked by the author in person or have total premissions for.
I post because i have been  asked by many what can model in to sfc and many have been put off by the options avalable. Most moders i know use wings 3d or Blender these days. Gmax download isnt even a option, either they dont really want to mod sfc or its to much of a pain in the ass to deal with the issues of vista, w7 and gmax crashes. Foas kill this topic i guess there is no support for it . If i get a blender plugin for sfc i will post it ,I hope others will do the same.
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on February 19, 2010, 03:05:54 am
Oh, come on Kreeargh. I'm not accusing you of anything. Those people who model in wings or blender can do so. I model in C4D. I export to .3DS and use gmax to convert to .MOD. I used to use Milkshape, but getting models in and out of it required too much touching up of the smoothing on import and I could never get the export smoothing good. Break mods of course are no goes.

Legit copies of Max 3-5 don't exist anymore and in theory would require you to buy a new license from Autodesk. Old versions of Max won't pass Windows Vista security either. Gmax runs on Vista, and I've only seen one person post about problems with Windows 7.

The problem I've heard of with Gmax is it doesn't export to a commercial format that other programs can use. (Actually, there is a work around to export the mesh to .obj, but it's a bit of a pain and it doesn't export a .mat file) People want to be able to move SFC models to other formats to, I presume, use in other games. All I was stating is that wasn't a concern for me when I got the gmax plugin done and it still isn't. I'm sure people would help you out and convert some of your models for you to .3DS if you wanted. I'd gladly do some for you.

 No need to have a Mod to close the thread. Nobody's breaking any forum rules
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 19, 2010, 03:21:41 am
I only have about a dozen iron in the fire, so I will what I can figure out for blender.  I know it uses Python for its plug-ins and I have the .mod plug-in code.  It will be a nice aside, but will have a lot of reading to be done first. 
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on February 19, 2010, 04:36:10 am
That's be nice of you, Marstone. Want to do a C4D one for me? (just kidding) ;)

Do you use Blender, Kreeargh? I can't make heads or tales of the bloody thing.
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 19, 2010, 01:37:24 pm
That's be nice of you, Marstone. Want to do a C4D one for me? (just kidding) ;)

Do you use Blender, Kreeargh? I can't make heads or tales of the bloody thing.

Yep i use it and alot more modeling tools, xsi mod tool< sucks more now thanks to autodesk takeover, just got wings 3d to try it out. Im not good with any of them yet. I made 1 model so far in blender it sucked yea but its a start.  I am used to the older format  this 2.5 interface is all new to me.  Going to be alot more learning it looks like .
There are a bunch of blender tutorials  here.  http://blenderunderground.com/ (http://blenderunderground.com/)
 
Title: Re: Blender to .mod scripts are there any working?
Post by: KBF-Kurok on February 19, 2010, 01:43:04 pm
an exporter for .mod in blender would be great. i think i would start messing around with it again since every thing i have  heard and read about it says it is faster and easier to use once you figure out  how it works. The tuts you can get  to help you learn it are excellent for the most part. Blender is a great free app.
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on February 19, 2010, 03:34:02 pm
Yeah, Blenderheads for years have touted the UI is so awesome once you learn it. Nice to hear they're doing a major overhaul of it in 2.5. :laugh: Love the concept of Blender. An open source professional quality 3D animation pkg for free. 8) Really sick and tired of $1000 and up to get good modeling software.

What has Autodesk done to Modtool? I really liked it when I tried it. Thought it had a great interface. Not as good as the C4D interface, but more powerful as a modeling tool, being XSI Sofimage based.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on February 19, 2010, 04:01:30 pm
I have also made attempts at it, but it is a daunting task. I think I can handle the basics (mesh) of translating the c++ gmax/3ds plugin to a python blender import/export script pair, but when it comes to the LODs, textures and illuminations I get lost... that is what I recall from when I looked at it last.

I also have about (two)dozen irons in the fire (too many, I'm not enough getting done, too much ddo). But perhaps I'll take another look at it this weekend and dig up the thread for marstone and I. There was a request for SFC3 scripts too, I have that setup and ready to accept simple custom script requests I gotta dig that thread up too, and the OSS project and the proprietary projects and completing the turn-based campaign interface (tbci) - oh wait, my improved SQL skills may accelerate the tbci somewhat from where I left off...

OK. Digging up my blender stuff where I left off... issue is upgrading the version and keeping python compatible across multiple products depending on it. Hmm. Yes, at it before I lose the motivation. Hopefully I'll get farther this time. I have a thread or two... I'll search and post the hits...

EDIT: here's some of the previous discussions ans links:
http://www.dynaverse.net/forum/index.php/topic,163386574.0.html
http://www.dynaverse.net/forum/index.php/topic,163387732.0.html
hmmm looks like that's it (and this one) I thought there was more.... off to update blender/python...
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 19, 2010, 07:29:51 pm
Bonk, I find it alittle humorous that the threads that are working on it, has both of us also doing alittle diddling there also.  I think the real task would be to find a thread that we are not helping out on it, in some form or another when it comes to moding the game.
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 19, 2010, 09:21:48 pm
Yeah, Blenderheads for years have touted the UI is so awesome once you learn it. Nice to hear they're doing a major overhaul of it in 2.5. :laugh: Love the concept of Blender. An open source professional quality 3D animation pkg for free. 8) Really sick and tired of $1000 and up to get good modeling software.

What has Autodesk done to Modtool? I really liked it when I tried it. Thought it had a great interface. Not as good as the C4D interface, but more powerful as a modeling tool, being XSI Sofimage based.

They removed the obj export the name shows up obj but its grey like its not active and without an obj file some have issues maping. Adding something is cool but removeing the only standard format ppl use to export to is rediculas i think.  Though this might be my fault for not installing something correct but another moder that uses xsi mod tool , That mods sins only said the same thing about the new autodesk version of xsimod tool.   Call me insain or what you will but i belive autodesk is in a 3d take over of all software they can get their hands on to end the Free modeling tools all together.  Buts neither here or there we cant stop that even bitching wont stop the billion$ greed. Moders and pro modelers generaly dont get along cause we can possably take away their profits cause we work for free I bet you that is also thought about on these takeovers.
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on February 19, 2010, 09:25:17 pm
http://pyffi.sourceforge.net/ (http://pyffi.sourceforge.net/)

Would this be of any help?

Quote
The Python File Format Interface, briefly PyFFI, is an open source Python library for processing block structured binary files:

    * Simple: Reading, writing, and manipulating complex binary files in a Python environment is easy! Currently, PyFFI supports the NetImmerse/Gamebryo NIF and KFM formats, CryTek’s CGF format, the FaceGen EGM format, the DDS format, and the TGA format.
    * Batteries included: Many tools for files used by 3D games, such as a stripifier, tangent space calculator, 2d/3d hull algorithms, inertia calculator, as well as a general purpose file editor QSkope (using PyQt4), are included.
    * Modular: Its highly modular design makes it easy to add support for new formats, and also to extend existing functionality.


This has been used for other game files from Max to Blender.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 19, 2010, 09:32:53 pm
Yeah, Blenderheads for years have touted the UI is so awesome once you learn it. Nice to hear they're doing a major overhaul of it in 2.5. :laugh: Love the concept of Blender. An open source professional quality 3D animation pkg for free. 8) Really sick and tired of $1000 and up to get good modeling software.

What has Autodesk done to Modtool? I really liked it when I tried it. Thought it had a great interface. Not as good as the C4D interface, but more powerful as a modeling tool, being XSI Sofimage based.

They removed the obj export the name shows up obj but its grey like its not active and without an obj file some have issues maping. Adding something is cool but removeing the only standard format ppl use to export to is rediculas i think.  Though this might be my fault for not installing something correct but another moder that uses xsi mod tool , That mods sins only said the same thing about the new autodesk version of xsimod tool.   Call me insain or what you will but i belive autodesk is in a 3d take over of all software they can get their hands on to end the Free modeling tools all together.  Buts neither here or there we cant stop that even bitching wont stop the billion$ greed. Moders and pro modelers generaly dont get along cause we can possably take away their profits cause we work for free I bet you that is also thought about on these takeovers.

thankfully, Blender is open source, it is already out there so it can't be taken away.  Someone will always have the code for it.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 19, 2010, 09:36:06 pm
[url]http://pyffi.sourceforge.net/[/url] ([url]http://pyffi.sourceforge.net/[/url])

Would this be of any help?

Quote
The Python File Format Interface, briefly PyFFI, is an open source Python library for processing block structured binary files:

    * Simple: Reading, writing, and manipulating complex binary files in a Python environment is easy! Currently, PyFFI supports the NetImmerse/Gamebryo NIF and KFM formats, CryTek’s CGF format, the FaceGen EGM format, the DDS format, and the TGA format.
    * Batteries included: Many tools for files used by 3D games, such as a stripifier, tangent space calculator, 2d/3d hull algorithms, inertia calculator, as well as a general purpose file editor QSkope (using PyQt4), are included.
    * Modular: Its highly modular design makes it easy to add support for new formats, and also to extend existing functionality.


This has been used for other game files from Max to Blender.


I'll check it out, thanks.  Got a few docs printed out so time to read (yes, Bonk I still print dang near everything, saves my eyes).
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on February 19, 2010, 09:45:32 pm
I hadn't noticed the omission of .obj export. Still does direct X, FBX, and Collada though (.xsi as well which a lot of aps. can import too). Which is really strange because it doesn't stop people from getting stuff out of Modtool and into another 3D ap. I wonder why they dropped it? 
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 20, 2010, 12:02:20 am
I hadn't noticed the omission of .obj export. Still does direct X, FBX, and Collada though (.xsi as well which a lot of aps. can import too). Which is really strange because it doesn't stop people from getting stuff out of Modtool and into another 3D ap. I wonder why they dropped it?
Problay a $ issue i noticed the obj format had a new tag name gw::objfile in the max 9 design demo vrs the max9 demo. A new plugin/format im guessing made by autodesk??, wasnt the obj format made by wavefront? Just a guess on my part though.

ANy how i have a $100 bill for anyone who can release a export to sfc directly from Blender plugin to keep the modeling community alive for good! Im willing to pay more $ for a import sfc to Blender plugin but the first goal is Export to .mod.  $ keeps going up more free 3d programs plugins are made for, Wings 3d is the next verision. No game moder should have to pay 1 $ to mod a game for free!   
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 20, 2010, 03:48:09 pm
okay got blender installed, but for some reason it doesn't want to load up the python I also installed.  Could be that blender was compiled with an earlier version of python.

Printing out the 3DS import script.  Will then compare with the .mod import and export files.  Will what I can gleen from that.
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 20, 2010, 03:59:15 pm
okay got blender installed, but for some reason it doesn't want to load up the python I also installed.  Could be that blender was compiled with an earlier version of python.

Printing out the 3DS import script.  Will then compare with the .mod import and export files.  Will what I can gleen from that.
Blender 2.5 need python 311 i belive the 2.49 version works with the 2??? python. Just FYI  ;D
Title: Re: Blender to .mod scripts are there any working?
Post by: sierracharlie on February 20, 2010, 09:40:49 pm
Blender 2.49 is the latest stable version. It uses Python 2.6
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 20, 2010, 10:10:41 pm
oddly it says no installed python found.  Even tho I did install it.  Oh, well, I am still reading through and correlating the parts of the MOD file to the Blender internals.
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 20, 2010, 10:23:42 pm
oddly it says no installed python found.  Even tho I did install it.  Oh, well, I am still reading through and correlating the parts of the MOD file to the Blender internals.

2.5 did the same to me but i installed 2.6 before i read further and noticed it said something about needing 3.11.
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on February 21, 2010, 12:40:27 am
oddly it says no installed python found.  Even tho I did install it.  Oh, well, I am still reading through and correlating the parts of the MOD file to the Blender internals.

Sorry for the basic question, but do you have python installed in the drive directory? Like  C:\python. It won't work installed in a folder like C:\program files\python.  Again, sorry if I just insulted you, but that would cause the problem you're describing.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on February 21, 2010, 09:36:17 am
Yeah, it takes some futzing with blender and python versions to get it going. But It can even be done portably. (I can dig up instructions if needed)


A point I just thought of: for me, more than anything, getting blender scripts working (import and export) has more to do with porting old community content (with approval) to open formats like collada for use in our planned OSS project! :D

We can even bring the content under GPL protections? To preserve the long term efforts of the SFC art community? (beyond the length of readme permissions email address vaildity - we're into the decades here...)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 21, 2010, 10:59:01 am
Well, for the OSS project.  I would say open up the formats that are supported so that we don't have to modify the .MOD format (if needed) to add features people are looking for.  It really wouldn't be that hard to make the import functions for the game to just load a new format into the game.  Instead of trying to make import and export functions for a bunch of graphic programs.

As for my python install, well I used the installer that it came with and let it put it where it wanted.  Which is C:\Python26.

Wife distracted me from the studying last night so not much new was learned for me on the importing of .MOD.  ;D

*edit*
oooOo just looked in the blender folder and seen sdl.dll, it's an SDL program.  will have to check the source alittle in there too.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 22, 2010, 12:33:30 am
Had a dah moment a minute ago. Was looking through and working out how the texture information is stored in MOD. First it saves material data, then the texture info. I was getting confused as many of the materials didn't link with a texture. It took abit of me sitting and thinking what the heck. Then it came back to me. Every texture needs a material but not all materials have a texture. Yeah, I'm not a graphics guy.
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on February 22, 2010, 03:29:54 am
What model were you looking at? While it is as you say AFAIK it's not right to have materials without textures.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 22, 2010, 03:58:08 am
A stock fed ca
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 25, 2010, 04:51:56 pm
FoaS or one of you other guys who are modelers.  Think it might be possible for someone to hack togeather a small MOD image and a 3DS image of the same thing.  Basicly I am looking for a very small unit, dumped in both 3DS and MOD so I can do compares of them for translating.  Thanks.  You can dump it to my email addy under my name here, I should get it.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on February 25, 2010, 05:39:32 pm
Will do. I will create a single cube with a texture map as well as an illumination map. One hard point as well.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 25, 2010, 10:00:31 pm
awesome.  It is just alittle daunting using the fed CA I have right now.  it is huge and mulitiple lod's also.

That is a question, I am not sure how lod's are loaded on blender (if it even does it) so should I just have it strip the first lod out of the file and forget the rest for now???
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on February 25, 2010, 10:17:44 pm
Well, tell you what: tell me what you want as you want it. I'll start with one material ID, then add more, start with minimal verts, then add more, etc.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 25, 2010, 11:44:00 pm
Sounds good, as basicly everything is looping the same loading code. Once I can load a set of vert, a face, surface, texture it just repeat for more. I'll let you know as I get to each new thing.  So thanks again.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 27, 2010, 08:12:57 pm
meh, learning new languages.  Odd format for loading data as python (I believe) is string based and to read numbers you have to have a binary format to translate with for each part.  Learning.  can open the file and start to read a .MOD in pure python (not in blender yet).  Will work on building the reader stuff now.

Off to get my lotto ticket and wish my dad a happy b-day so taking a break.  ;D
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 28, 2010, 11:43:57 am
Well, I feel like an idiot so far.  I don't seem to be able to figure out how to get blender to find my script I am working on.  So I will do more in just straight python first.  Then add the stuff that is needed to make it a blender script. 

If anyone has the patience to explain how to get blender to find my script (and where to access it from blender) I would appreciate it.  Explain it like you are talking to a five year old, I'm feeling stupid in my old age.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on February 28, 2010, 12:47:28 pm
Put your script here:
C:\blender\.blender\scripts
Or depending on how you installed blender the .blender folder may be in a user dir.

make sure it starts like so:
Code: [Select]
#!BPY

"""
Name: 'StarFleet Command (.mod)...'
Blender: 249
Group: 'Export'
Tooltip: 'Export to SFC file format (.mod).'
"""

It should then be accessible through the file...export menu. (Similarly for import scripts)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 28, 2010, 01:08:25 pm
yep,yep,yep.  I remember that part now.  The sample I was working with as a base didn't have the header on it. (but yeah, I did read about it a few days ago, grrr).
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on February 28, 2010, 02:34:08 pm
ya know, its nice having two resident code geniuses here ;)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 01, 2010, 01:58:22 am
Alright, it finds the script.  It can open a file and start to read it. 

First version I am shooting to just read in the verts and faces.  No textures or bones(hardpoints)

speaking of the hardpoints, what does blender hold them as?
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on March 01, 2010, 04:42:06 am
hardpoints should be dummy objects, in 3ds max they are dummy cubes... from what i can tell blender has something similar.   From my understanding (and what i surmise) is that the dummy objects are simply placeholders for the hardpoints, so that when the ship is exported, the export programs know what to name the hardpoints and where to position them.  So I would imagine any dummy object in blender would do.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 01, 2010, 04:54:39 am
I thought that hardpoints were stored as joints since the model is not animated. (?) (could be mistaken)

THere's a thread on the subject with an appropriate title in the models forum. joints, hardpoints and something... ah here it is:
http://www.dynaverse.net/forum/index.php/topic,163372956.0.html
in the context of milkshape... might be relevant to blender too?

Where's that pdf from Heaven's Eagle?
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on March 01, 2010, 04:58:12 am
For 3ds Max, the HP and DP are all stored as dummy objects.  what the equivalent in blender is, i don't know (empty object maybe?)

edit:  from my quick playing with blender it seems that empty objects (add empty) are similary to what a dummy object is.   for all i know though i could be adding a vertex lol

edit2:  From some quick checking of the wiki, I'm like.. 80 % sure that empy objects are what we are looking for (either the empty or empty mesh) either one of those could be used to represent the hard points
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on March 01, 2010, 04:59:01 am
I thought that hardpoints were stored as joints since the model is not animated. (?) (could be mistaken)

THere's a thread on the subject with an appropriate title in the models forum. joints, hardpoints and something... ah here it is:
[url]http://www.dynaverse.net/forum/index.php/topic,163372956.0.html[/url]
in the context of milkshape... might be relevant to blender too?


yes, that is because MS does not support dummy objects, thus another method had to be developed to get the same effect
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 01, 2010, 05:19:04 am
alright, sounds good so far for the hardpoints.  In the MOD format they are stored as a name reference and a 3d point.  When I get to worrying about adding them, then we can figure out what is best to hold the spot on the ship.  I should have the vertices worked out when I get home from work today, and the faces hopefully shortly after that.  (faces have alot of information on them that I have to sort through to just get the three verts that make up the face)


Well, finish work, and see what I can do.

*edit*
Okay, going alittle slower then I wanted.  I am now ready to start to read in the verts.   Was hoping to have this part done before heading off to the second job (in ten minutes)

*edit*
just heading off to work (again), but have it reading all the verts in (not doing anything with them yet, but they are in an array now).  I figure since the converter for 3DS was written in C++ the references to the array of verts for the faces will start with number zero.  I will get those read in when I get back from work, and see if I can get a wire frame up in Blender.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on March 01, 2010, 06:14:31 pm
I would think that it doesn't matter what type of object you make the hardpoint/damage point, so long as the exporter script that objects A through G are hardpoints, and then places their XYZ coordinates into the MOD format in the right place. (the easiest way of designating hardpoint coordinates is to use a "for x in objects where classof x == dummy do..." type dealy.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 01, 2010, 09:46:56 pm
I would think that it doesn't matter what type of object you make the hardpoint/damage point, so long as the exporter script that objects A through G are hardpoints, and then places their XYZ coordinates into the MOD format in the right place. (the easiest way of designating hardpoint coordinates is to use a "for x in objects where classof x == dummy do..." type dealy.
yeah, something like that.  :crazy2:  Feeling alittle sick right now so got some sleep.  Example code had two ways of doing the verts, and neither stuck out to me.  So will diddle tonight at work.  Python is interesting language, abit weird for me, but interesting.

*edit*
okay found a function that will add the verts and faces in easily.  Now to reading in faces.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 02, 2010, 12:18:13 am
okay, question.  why is that stupid square in the middle of my blender screen?  It gets in the way of seeing the fighter model I just loaded.

MOD_Import.py (http://www.filefront.com/15719799/MOD_import.py)

Next is to work on the textures. Then the hardpoints.
Also will start to work on the export version.

*edit*
Oh, if you get an earge to look at the code, it has been programmed in an Italian dinner style. 
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on March 02, 2010, 01:56:26 am
Great going, Marstone!
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 02, 2010, 02:26:32 am
Thx, It's coming along.  Although I am feeling like Charlie Brown trying to kick the football, working on this material/texture stuff.  As a graphicly challenged individual, this is not the most fun reading (tho it is interesting, I vaguely remember this stuff from way earlier).  Now am I reading it right, that for SFC I have a normal texture (diffuse) and an illumination  texture (not sure of the spcific name).  I can just forget about all the rest right?

You know if I had a clue, and maybe some talent, I could be dangerous.
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on March 02, 2010, 04:56:06 am
SFC supports only Diffuse and Illumination maps, though I think the .mod file does store more information than just that - its just the game doesn't read it.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 02, 2010, 10:31:56 am
coughing up a lung.  Will be a day or so before I am back on this.

*edit*
A peek behind the curtain of how I work on decoding this stuff (and the Q3).
(http://i433.photobucket.com/albums/qq59/marstone2/working.jpg)
Note the mountain dew throwback, a much needed tool.
Other side note, note the lack of a computer in the area.  ;)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 04, 2010, 02:23:33 am
Question for those that know.  When putting an illum map on a ship what material/texture settings are used?  Is the texture an Opacity?  The standard material seems to be a Diffuse texture. 
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on March 04, 2010, 10:50:06 am
normal material = Diffuse (aka: color)
the illum map should be called something like Lighting, Self-Illumination. Blender might use the term ambient (even if it is inaccurate for such things).
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 04, 2010, 12:31:57 pm
Okay, thanks.  Will look and see what I can find as the type for the illum map.  I should have a version out that does the basic texture in a day or two. (then have to look into the break models also, grrr)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 09, 2010, 05:03:07 am
Okay, not alot to report right now.  I spent my weekend taking my spagetti code and making it nice, then working out the glitches from the conversion to a nicer layout.  So, not much farther along, but in a good place to add the materials (need to add a new structure yet for holding the meshes), and it will be set to load LOD's tho not sure how you display that.  Also for working with break models (I hope).

This week working on the textures yet.  Hope to have that done soon. ;D
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 09, 2010, 05:30:10 am
Awesome marstone! This will help a lot. (and open up the blender game engine for experimentation with sfc models...)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 09, 2010, 06:36:31 am
You know it almost took me as long to organize the code, as it did to write it in the first place.  Guess this is a good lesson not to spaghetti code to start with, as you are just doubling your time if you want to make it nice later.  But it is just to much fun to program that way to start with.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 09, 2010, 03:11:09 pm
I know exactly what you mean.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 10, 2010, 10:37:45 pm
Question. How many pieces can you use in a break mod?
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on March 10, 2010, 11:54:18 pm
I don't know of any limit, but generally I limit it to 5 to 7. More than that and it can cause excessive lag if a lot of sh*te gets blowed up at once.
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on March 11, 2010, 12:31:05 am
Question. How many pieces can you use in a break mod?

Look at some stock model brks in gmax ? I wish i could help on this but i get more crashes of my vista pc the more i mess with the .mod format. I am so sick of this crashing issue  with the mod format i am about to quit all together.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 11, 2010, 05:06:25 am
Don't have the textures added yet, but reworked it so it will load in what I would assume is the LOD's, maybe the break models pieces, have to check  on how that is done yet.

Python doesn't use c++ style pointers so took awhile to learn how to use the python references  :crazy2:
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 11, 2010, 05:21:00 am
I wish i could help on this but i get more crashes of my vista pc the more i mess with the .mod format. I am so sick of this crashing issue  with the mod format i am about to quit all together.

What application is crashing? The Taldren mod viewer? Gmax? Milkshape? Max?

I have found that Vista has destabilised with recent updates. I have had three unrelatable blue screens of death in the last three months. XP might have done it to me once a year.
Title: Re: Blender to .mod scripts are there any working?
Post by: atheorhaven on March 12, 2010, 11:56:20 am
I think I remember hearing way back when about 10-15 being a practical limit.. but that may have been a hardware limit due to older SFC1 era hardware.  I usually will do a maximum of 10 parts in a _brk.mod
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on March 12, 2010, 04:52:25 pm
afaik there is no limit in the 3ds max script, that is not to say there isn't a limit in sfc in which the game crashes...
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on March 12, 2010, 07:12:26 pm
I wish i could help on this but i get more crashes of my vista pc the more i mess with the .mod format. I am so sick of this crashing issue  with the mod format i am about to quit all together.

What application is crashing? The Taldren mod viewer? Gmax? Milkshape? Max?

I have found that Vista has destabilised with recent updates. I have had three unrelatable blue screens of death in the last three months. XP might have done it to me once a year.


Its explorer itself and the Taldren viewer, when i export to desktop from gmax some , not all mod files instantly crash windows. If i export to a folder it wont crash untill i open that folder to view the mod file. The pirate crashed the pc when i exported it to a folder this time, but it wont auto crash it through 2 folders. But the version with lower poly warps is just fine it dont crash the pc. Its wierd. Not just my files either, some stock sfc models crash the pc,it crashes when i view the models folder in stock sfc2 and other user created models do it also. I posted a pic of the crashes in the Pdn pirate thread.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 12, 2010, 07:37:58 pm
Try disabling McAfee and see what happens.

I have a story about MCAfee for you. A roughly $20,000 4 business day loss to McAfee. The communications software with the gas chromatograph - mass spectrometer system I was using was experiencing random communications errors resulting in an inability to run any samples reliably. (It was Win98 on a Dell Optiplex G1 or something - I still dread the machine), Tech flown in power monitors installed the works. It was McAfee interfering with serial communications!!!! ARG! Un-effing-believable. I have been extremely wary of McAfee ever since.

Give it a whirl, if you're worried, just shutdown, disconnect your internet cable from the computer, then startup, disable McAfee, reboot, and see if the undesirable behaviour persists. It shouldn't take long to test. However, be careful in disabling McAfee, it often says it is disabled but is not. (at least I have observed that behaviour) - temporarily disable any services run in its name in addition to it's internal "disable" features (prior to stopping the services). A little extra info there to help make for a valid test.

Mind you, my Vista install just bluescreened while watching youtube not twenty minutes ago. I'm running Microsoft Security Essentials only for AV type stuff currently.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 13, 2010, 08:58:49 pm
okay, seeing a problem that Blender might have doing SFC models (actually importing MOD's).  From what I have read is that a mesh can only reference 16 materials, as each texture is on one material.  Blender would not be able to load a stock FCA as it has 32 textures, thus would use 32 materials (of which a mesh can only hold 16), checking to see if I can link two textures to one material (say the illum map to the normal texure) that way a FCA could be loaded.   Any hints from Blender users.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on March 13, 2010, 10:00:46 pm
i have never heard of a program limiting the number of material IDs... this is new
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 13, 2010, 10:30:37 pm
from the docs.

Quote
materials
The mesh's materials. Each mesh can reference up to 16 materials. Empty slots in the mesh's list are represented by None. Note: Object.colbits needs to be set correctly for each object in order for these materials to be used instead of the object's materials.

I have seen some code that is set to copy just 16 materials to the mesh material list. 
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on March 14, 2010, 12:28:42 am
Try disabling McAfee and see what happens.

I have a story about MCAfee for you. A roughly $20,000 4 business day loss to McAfee. The communications software with the gas chromatograph - mass spectrometer system I was using was experiencing random communications errors resulting in an inability to run any samples reliably. (It was Win98 on a Dell Optiplex G1 or something - I still dread the machine), Tech flown in power monitors installed the works. It was McAfee interfering with serial communications!!!! ARG! Un-effing-believable. I have been extremely wary of McAfee ever since.

Give it a whirl, if you're worried, just shutdown, disconnect your internet cable from the computer, then startup, disable McAfee, reboot, and see if the undesirable behaviour persists. It shouldn't take long to test. However, be careful in disabling McAfee, it often says it is disabled but is not. (at least I have observed that behaviour) - temporarily disable any services run in its name in addition to it's internal "disable" features (prior to stopping the services). A little extra info there to help make for a valid test.

Mind you, my Vista install just bluescreened while watching youtube not twenty minutes ago. I'm running Microsoft Security Essentials only for AV type stuff currently.

Hmm  I just noticed some things that makes me think retirement is best for me .  I am years behind in the pc world.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 14, 2010, 08:03:32 am
The road to hell... when will I ever learn.  :(

/me shakes head

Reading up on mats in blender there now marstone.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 14, 2010, 08:49:12 am
Um yeah, it appears blender only supports 16 materials per mesh.  :skeptic:  How did we not catch that?

However, my stock fca has 12 textures. (+12 illumination maps). I don't know if I've ever seen a model with more than 16. (a random sampling of models in my SFC installs (EAW and OP) does not show any with more than 13)

That limitiation is not good though.

I think material nodes may be the solution. I just added 18 materials to a mesh with nodes and have added 18 textures to one of those materials... I just haven't figured out how to assign bitmaps to them yet! I recall figuring out texturing in blender before, I totally forget now.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 14, 2010, 09:13:15 am
Muddling through it again now. Materials and textures are two different things. As far as I can tell a material can have unlimited textures associated with it and by using nodes one can have unlimited materials. At least that is currently how I think it works. More than sufficient complexity to plaster any surface with myriads of information. I just need to demonstrate it / work it out - to see if I'm right.
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on March 14, 2010, 01:48:12 pm
actually bonk, thats just a limit on the UI i think.   to prove this just add cubes to your scene and for each one link a material to it. by doing so, it appears it applies a unique material name to each one (material.024 for example).

Of course i could be completely off, but i think this is right.
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on March 14, 2010, 01:51:24 pm
btw, your screenie shows 18 mats in scene
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on March 14, 2010, 02:49:57 pm
as i understand it its not a matter of limiting how many materials you can have in scene, but rather how many materials a single object can have.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 14, 2010, 02:56:30 pm
yes its mats per obj.

Lol, I'm watching blender tutorials on youtube - being schooled by kids! They all sound like 12 man!  :-[

I'm working on a test model, I've got 24 textures on it, and no materials. Now I'm going to add on materials in various ways and see what I get.

I'm a little confused between uv wrapped images and material texture images at this point. Which renders when? Do UV wrapped images render at all?  :huh:

I have a little ways to go to contribute productively here I guess.

edit: this guy is not a kid and has some good tuts: http://www.youtube.com/user/irakrakow#p/u

http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 14, 2010, 03:16:54 pm
now you got me confused, I thought in order to put a texture on an object you had to have the texture on a material.  How are you putting textures on but no materials?

This is where not being a graphics guy, and having just alittle knowledge seems to hurt.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 14, 2010, 03:19:44 pm
Opps, Sorry! Hopefully one of the modellers will set us straight, if not, I'll let you know what I make of it all once I work my way through this Ira fellow's tutorials.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 14, 2010, 03:55:43 pm
Ya, it seems to get it to render the textures I've assigned to each face I need to add a material and set some properties.

This video was instructive (though i've not really implemented it yet): http://www.youtube.com/watch?v=I_8OV92HLPY

So this is a single material with 24 textures (attached). I shall try assigning a material to each face now.

All of this is a very inefficient way to texture a cube of course, but it is a learning tool for me.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 14, 2010, 04:29:51 pm
16 traditional materials assigned manually to 16 faces, the remaining 8 faces default to the first material index.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 14, 2010, 05:07:34 pm
Ah, Blender 2.5 Alpha 2 does not seem to have exactly the same limitation, it seems to be much easier to add and assign multiple materials beyond 16 without using nodes. One assigned to each face in this case. (four faces per side of cube for a total of 24)

Textures not assigned to materials but uv wrapped 1:1 on each face.... There will be several ways to do this.

Edit: I'm getting handier with blender 2.5. I like the changes. Time to move to a ship model soon.
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on March 15, 2010, 01:08:05 am
basically the material controlls what properties are applied to mesh, whether that be mutliple textures with different ids, or effects and blending.  For me, it is easier to assign each material a set of textures (aka diffuse, light, spec maps) for one particular area - i find it less confusing.  However it is possible to use one mat, and then add multple textures to it each with a different id and then 'assign' them to certain parts of a mesh via selection.  This has the advantage of having one mat to deal with for say one part of a scene versus haveing 24 for just one model.
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on March 15, 2010, 11:11:59 pm
The road to hell... when will I ever learn.  :(

/me shakes head

Reading up on mats in blender there now marstone.

You did me some good , got me thinking how stupid i can be  :thumbsup:  Take a hammer to the vista machine and revert back to what i know somewhat. Hell i dont even know how to shut off antivurus in vista crap.
Title: Re: Blender to .mod scripts are there any working?
Post by: Rod ONeal on March 16, 2010, 02:08:26 am
If they didn't refuse to keep Dx up to date in XP nobody would change over. LOL
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 17, 2010, 01:55:37 am
 :crazy2: was starting to work through some tutorials to learn alittle more about blender, was working on the textures (of course), and for some reason my version doesn't seem to have the UV stuff shown in the video. 

So, going to ask if someone (FoaS) could put up a link to a image (cube or whatever) that has one texture on it.  Maybe saved in .mod .3ds  so I can compare them.  Thanks in advance.
maybe one that also has a illum map on it also.

Figure after i can get it to show at least one texture, then I will worry about getting the loads of them ready (however they need to be done so I can show as many textures as are on a model)

I know this is going to end up being easy peasy but at the moment i can't wrap my brain around how to load it.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 17, 2010, 05:32:40 am
If you've got blender you've got the UV editing stuff. One of blender's main strong points. Split the window by right clicking at near the lower margin and then set the right window the UV/image editor view by clicking the icon at the lower left corner of the window. I'll post screenshots when I get home (for 2.49 right?)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on March 17, 2010, 06:43:35 am
I got that far, but then the video was showing to change my object mode to a UV something, and that isn't in the list that comes up when I click on the menu.  going to run through more of the training videos now that I am back home and have my two screens to work with (one for the training video, the other for Blender).  I love dual monitors.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on March 17, 2010, 03:25:28 pm
I believe what you want is "edit mode" instead of "object mode" this will change the menus. Once in edit mode Press "a" a few times to select the whole mesh, then on the "mesh" menu select "UV unwrap" (maps whole mesh to single texture). One could also select parts of the mesh and UV unwrap them separately to put particular textures on particular faces or regions. At least I think that is how it works.

Anybody know what UV stands for in this context? Would be nice to know...

Ah, U and V are arbitrary labels for the ordinate and abscissa of the 2D mapping of the 3D surface.

http://en.wikipedia.org/wiki/UV_mapping

Projections... takes me back to grade school!
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on March 17, 2010, 09:16:01 pm
Actually the full term is UVW, because the texture coordinates can exist in three dimensions, even if most systems only use two of them. 3D textures use all three, but those are in-program things usually, not anything that a game engine can use as of yet.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 06, 2010, 04:47:25 pm
I'm going to take another stab at this right now. Downloading blender 2.5. The motivation is to get the dang mod format worked out in me head and then move on to rendering it on the canvas or writing conversion/display/manipulation scripts in python/php/js.

Step one (I think - will be the import script... though it may be easier to do the export first...)

edit: ... wow... 2.5 is different...

some good blender docs here: http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro (http://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro)

OK... I'm past "hello world" and object browsing in blender 2.5 again, now to prompt for a filename, load .mod binary data and sort it out. Easy right?  ;D

making progress, basing it on the 2.5 LWO import script. have the filename aand import menu hooks all set, now to chunking up the binary data and see if I can get it into blender objects.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 06, 2010, 05:55:50 pm
Import is easier then export. Is there a copy of the script I was working on in this thread?   When I get back from hunting I'll upload the file (if I can find it) for you to play with.  The .mod is not very complicated.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 06, 2010, 06:00:26 pm
I figured, so working on import. Ya, the format looks pretty simple. How far along were you? (dont wanna re-invent here...)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 06, 2010, 06:18:51 pm
Got it to import the polies and show them. Read what textures to use, but couldn't apply them. Never got the demo files I asked about so I could compare to learn how to do the illum. It should read all LOD's.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 06, 2010, 06:49:51 pm
Oh right, its coming back to me... that's what all those blender texturiong screenshots I have are about... :smackhead: I was wondering what I was up to with that. Perhaps I should review this and other threads.

Definitely upload your script if it is not here already. That's like half-way there. I figure it makes the most sense to start this on Blender 2.5 now that it is in beta.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 06, 2010, 07:22:55 pm
I will be back to a computer on monday and look for it then.

Yeah. I have been rereading the thread again also.

Thanks for smart phones in the woods.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 06, 2010, 08:21:48 pm
well, I did post it here but I haven't been on filefront for so long my account went inactive and can't seem to get it active by just logging on.  So will have to send it again.  Bright side is that file will be the neat code and not the funky stuff.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 08, 2010, 09:17:17 am
I'm building a .mod file template in my hex editor to assist me in this today. You're probably already past this, but it will help me a lot to get it into blender. Once I get this done, I think the rest of it will fall into place in blender 2.5. If you locate your 2.4 work we can compare/combine what we have.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 08, 2010, 01:48:20 pm
here is the file.

get it here:
https://docs.google.com/leaf?id=0B_1Q5dMWZoYkOTg5MDIxNzktM2UwNC00ZTIyLTg0YWEtZmY5ZGZkMWUwZDg3&sort=name&layout=list&num=50

or here:
https://docs.google.com/leaf?id=0B4rh3h4bW8tvMGQyZTAzZmQtMGQyZi00MDQ1LTg1OGUtNzg4NjA3OTliYTU1&hl=en
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 08, 2010, 01:59:51 pm
I'm building a .mod file template in my hex editor to assist me in this today. You're probably already past this, but it will help me a lot to get it into blender. Once I get this done, I think the rest of it will fall into place in blender 2.5. If you locate your 2.4 work we can compare/combine what we have.

I like your hex editor.  :smitten:  But alas, as a poor boy I can't pony the bucks and will stay with my no thrills editor.  :'(

So yeah, I have the formats written down on paper.  ::)
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 08, 2010, 02:51:49 pm
frak! I forgot about this thread.

Bonk and marstone, I can still make that simple cube MOD file if you need it. With precisely known XYZ coordinates, UVW coordinates, and material properties it will probably help you out quite a bit.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 08, 2010, 03:11:54 pm
A "model" model would be handy. One with one of everything possible defined. (5 LODs, all hardpoints, sample of every material type...)

noting the material structure (from the Max3 mod importer):
Code: [Select]
struct tMaterial
{
enum
{
kTexMapped      = 0x0001, // set if texture mapping
kGouraud        = 0x0002, // set if gouraud (smooth) shading
kFlat = 0x0004, // set if flat shading
kWire           = 0x0008, // set if polygon should be wire frame
kAdditive = 0x0010, // set if polygon should be blended
kLuminance = 0x0020, // set if we have luminance texture maps
};
unsigned int fFlags;
COLORREF fColor;
float fAmbient;
float fDiffuse;
float fEmittance;
struct tTextureInfo
{
int fTexID;
int fTexNameOffset;
};
tTextureInfo fDiffuseTexture;
tTextureInfo fLuminanceTexture;
};

I'm working with the stock fca, but at some point a regular object for testing and debugging would be good.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 08, 2010, 03:27:00 pm
here is the file.

get it here:
https://docs.google.com/leaf?id=0B_1Q5dMWZoYkOTg5MDIxNzktM2UwNC00ZTIyLTg0YWEtZmY5ZGZkMWUwZDg3&sort=name&layout=list&num=50

or here:
https://docs.google.com/leaf?id=0B4rh3h4bW8tvMGQyZTAzZmQtMGQyZi00MDQ1LTg1OGUtNzg4NjA3OTliYTU1&hl=en

Awesome, thanks marstone!
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 08, 2010, 04:45:09 pm
something I had wondered is how did the LOD's get done.  Was it done by the exporter? or did you have to make all of them in one file and export?  It would make a difference on how to import.  Only thing I could find along time ago was info on modding a file was to use the extractor program that dumped the file out into LWO.  You delete the LOD's except for the first one and work from there.  I always wondered if when you export it would make the LOD's again or if it just didn't have any from then on.
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on November 08, 2010, 05:54:39 pm
LoDs are made before exporting.  the exporter determins which lod is which based upon name if i'm not mistaken (haven't used it much)
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 09, 2010, 05:00:52 am
Yeah, automatically generating LODs on export would take a rather sophisticated algorithm, though I suppose one could borrow or import existing poly reduction scripts and use a set of standard transition distances. I expect that would be a feature that many would like. But we get ahead of ourselves... (edit: nope not gonna happen... auto-texturing of LODs would be insane)

I'm out of coffee!  :o This will not do.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 09, 2010, 07:41:02 am
I wouldn't want auto-LODing anyways: it would be a loss of control over how many polies the ship had and how it was built.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 09, 2010, 08:48:30 am
Oh if I was ever masochistic enough to attempt it, it would of course be a selectable option. (but like I said, automating texturing would be a bitch... come to think of it though, if it worked out well... think of the carryover tech that might be possible)

I'm trying to decide on how to handle the strings right now, and whether to continue working on my hex editor template or move right on to python and just print a smackload of debug output to the console... that is probably what I will do today after looking at how(if) marstone handled the strings.

I'm taking a "Little Train That Could" attitude today. This is totally doable. We just have to stick to it.

Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 09, 2010, 10:11:32 am
working on your template might be good.  Open up the code I sent you and see if some of the structures will help ya with that.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 09, 2010, 12:27:11 pm
I got hung up on bugs in the 010 editor scripting system (ceil does not return ceil) so abandoned it and moved right back to my python script.

I took a peek at your code but not too deep yet.

I'm approaching this exactly as I did the flatfile webmap using the unpack function stepwise through the file as necessary bits of info are collected. I like the way python's unpack fucntion works better than php's though. Much more efficient. :thumbsup:

This is what I have so far.... (still behind yours by a bit, but taking a different approach - once I get to the same stage yours is at, then a merge of some kind may be in order, but you know how it is with code... )

Code: [Select]
bl_addon_info= {
    "name": "Import StarFleet Command Models",
    "author": "Bonk",
    "version": (0, 1),
    "blender": (2, 5, 5),
    "api": 31847,
    "location": "File > Import > StarFleet Command Model (.mod)",
    "description": "Imports a StarFleet Command model file.",
    "warning": "",
    "wiki_url": "http://www.dynaverse.net/wiki/index.php?title=Blender:SFC_Models",
    "category": "Import/Export"}

import os
import io
import time
import struct
import chunk
import array

import bpy
import mathutils

# print (dir(bpy))
# print (list(bpy.data.objects))


def import_mod(filename,
               context):
                   
    print (filename)
   
    name, ext= os.path.splitext(os.path.basename(filename))
    file= open(filename, 'rb')

    # Header
    try:
        modHdrTag, \
        modHdrFileSize, \
        modHdrVersion, \
        modHdrRadius, \
        modHdrTotalLODs, \
        modHdrLODHyst \
        = struct.unpack("<4siIfif", file.read(24))
        print ("modHdrTag: " + modHdrTag.decode("ascii"))
        print ("modHdrFileSize: %d" % modHdrFileSize)
        print ("modHdrVersion: %d" % modHdrVersion)
        print ("modHdrRadius: %f" % modHdrRadius)
        print ("modHdrTotalLODs: %d" % modHdrTotalLODs)
        print ("modHdrLODHyst: %f " % modHdrLODHyst)
        modHdrLODTrans \
        = struct.unpack("<%df" % modHdrLODHyst, file.read(int(modHdrLODHyst)*4))
        print ("modHdrLODTrans:")
        print (modHdrLODTrans)     
    except:
        print("Error parsing file header. Boo!")
        file.close()
        return
   
    # Strings
    modStrTag, \
    modStrSize \
    = struct.unpack("<4si", file.read(8))
    print ("modStrTag: " + modStrTag.decode("ascii"))
    print ("modStrSize: %d" % modStrSize)
    modStrPool \
    = struct.unpack("<%ds" % modStrSize, file.read(modStrSize))
    print (modStrPool)

from bpy.props import *

class IMPORT_OT_mod(bpy.types.Operator):
    '''Import MOD Operator.'''
    bl_idname= "import.mod"
    bl_label= "Import MOD"
    bl_description= "Import a StarFleet Command model."
    bl_options= {'REGISTER', 'UNDO'}

    filepath= StringProperty(name="File Path", description="Filepath used for importing the model file", maxlen=1024, default="")

    def execute(self, context):
        import_mod(self.filepath,
                 context)
        return {'FINISHED'}

    def invoke(self, context, event):
        wm= context.window_manager
        wm.add_fileselect(self)
        return {'RUNNING_MODAL'}


def menu_func(self, context):
    self.layout.operator(IMPORT_OT_mod.bl_idname, text="StarFleet Command Model (.mod)")

def register():
    bpy.types.INFO_MT_file_import.append(menu_func)

def unregister():
    bpy.types.INFO_MT_file_import.remove(menu_func)

if __name__ == "__main__":
    register()

Hmmm should we go for a SyntaxHighligter (http://alexgorbatchev.com/SyntaxHighlighter/) install here?  (<- I just used the url button marstone! ;)  ;D)

... anyway, I'm doing like I said, just printing it all to the console - I'm up to the same decision point as with my t hex editor template - how to handle the strings exactly... might just leave them as a byte blob for now and move on then make the decision when I need to use the strings. That makes sense.

Once I have parsed the file reliably into variables and data.. then I'll build a model with it (looking at the lwo scene importer as a starting seed).

Only thing that worries me about my current approach is I'm not sure that the chunk order is consistent in the mod files and I may have to separate each into its own procedure and iterate through them. Again, I find that out once I get there. (unless you know already).
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 09, 2010, 12:41:11 pm
I did about three formats of the code, then set it up like the import code for 3DS Max so it is easier to follow along.

I'll take a peek at yours but off to a movie with my son, then work on some C# code for the ship UI editor. (always something to learn)
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 09, 2010, 01:04:52 pm
Have fun at the movie!

ceil works muuuuch better in Python... (allowing me to pad the stringpool block to a dword multiple, allowing my unpack strategy to continue...)  :)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 09, 2010, 03:34:27 pm
Yeah, I didn't like Python that much.  The pointers are a bugger to get down.  Structures don't work the way they do in C++ so took awhile for me to get it down (have forgotten it now again tho)
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 09, 2010, 03:38:38 pm
Right now the arrays (lists) are pissing me off. Why is it that every language has to have their own queer implementation of arrays? Drives me nuts.  :banghead:
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 09, 2010, 03:46:38 pm
Right now the arrays (lists) are pissing me off. Why is it that every language has to have their own queer implementation of arrays? Drives me nuts.  :banghead:

Makes the writers of the language feel manly redoing everything for no good reason. :crazy2:
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 09, 2010, 05:01:01 pm
What's killing me now is the meta-syntax of the python documentation. I just can't see how it translates in most cases to actual usable python code.

I'm trying to break up the bytearray of null terminated strings more efficiently than unpacking character by character as you have, but it is starting to look like that is the only way.

At least Python has authoritative online documentation. The lack of that for Javascript is maddening. I think I'm going to have to spend some time decoding the Python documentation. Perhaps they explain their meta-syntax in its introduction...

Starting to burn out for today...
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 09, 2010, 05:13:41 pm
remember that Python is named after Monty Python.  So logic and simplicity may not always apply.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 09, 2010, 08:38:46 pm
Got past a few blocks, hit a few more. I should have the whole file parsed by the end of tomorrow. (hit an issue with vertices, and then need to finish polys and looping throgh the LOD count.) Then it is just a matter of building the model. Simple right? ;)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 09, 2010, 08:50:37 pm
polys are fun.  They store normals in there also. Maybe, the normals might be on the verts, can't remember.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 09, 2010, 08:57:40 pm
Ya, face normals are stored:
Code: [Select]
struct tFaceDef
{
int vtxCount;
int materialNdx;
tPoint3 normal;
struct tFlatPolyVertex
{
unsigned short vtxNdx;
unsigned short flags;
tPoint3 normal;
float u;
float v;
float light;
}*vertices;
tFaceDef() : vertices(NULL) {}
~tFaceDef() { if ( vertices ) { delete [] vertices; } }
};

So I conclude the vertex normals displayed in the model viewer are calculated. edit: no wait ... i see both normals are stored in the face structs.

I begin to fear the math of the export...  :o
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 09, 2010, 09:20:08 pm
Typically, IIRC, vertex's and faces each have their own normals.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 10, 2010, 05:19:02 am
Yeah, they are both stored in the face struct. I find it odd that normals should be stored when they can be calculated... perhaps too much to calc them on the fly? Why does the game engine need them anyway? (naieve question?) Perhaps they are just there strictly as a modeling tool? (really easy to see misalignments with them displayed)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 10, 2010, 07:01:12 am
I believe the game engine would need it for shading. Also, was probably saved as the target machines for the game were low end and didn't need a 3D card. So would help not bog down the cpu.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 10, 2010, 08:34:54 am
Normals can be altered from their usual vectors, but rarely ever are.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 10, 2010, 08:43:15 am
But.. then... it wouldn't be a normal would it?  ;D
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 10, 2010, 12:58:35 pm
this model is suffering from abnormal normals?
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 04:49:31 am
Not even groan worthy...  ;)

Actually though, I've gotten stuck on the vertices, they just aren't adding up on the stock fca for me. The first and last values don't "add up". Might be time for that "model model". Though I'll have to be able to handle this regardless.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 06:29:40 am
What isn't "adding up" about the verts for yeah?
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 07:29:40 am
I'm probably missing something dumb... but the first value makes no sense and I have one spare one at the end that also makes no sense... perhaps some screenshots and my current unpacking code will illustrate...
Code: [Select]
bl_addon_info= {
    "name": "Import StarFleet Command Models",
    "author": "Bonk",
    "version": (0, 1),
    "blender": (2, 5, 5),
    "api": 31847,
    "location": "File > Import > StarFleet Command Model (.mod)",
    "description": "Imports a StarFleet Command model file.",
    "warning": "The universe may implode at any moment.",
    "wiki_url": "http://www.dynaverse.net/wiki/index.php?title=Blender:SFC_Models",
    "category": "Import/Export"}

import os
import io
import time
import struct
import chunk
# import array

import bpy
import math
import mathutils

def decodeAsc(byteStr):
    print (byteStr.decode("ascii"))

def import_mod(filename,context):
                   
    print (filename)
   
    name, ext= os.path.splitext(os.path.basename(filename))
    file= open(filename, 'rb')

    # Header
    try:
        modHdrTag, \
        modHdrFileSize, \
        modHdrVersion, \
        modHdrRadius, \
        modHdrTotalLODs, \
        modHdrLODHyst \
        = struct.unpack("<4siIfif", file.read(24))
        print ("modHdrTag: " + modHdrTag.decode("ascii"))
        print ("modHdrFileSize: %d" % modHdrFileSize)
        print ("modHdrVersion: %d" % modHdrVersion)
        print ("modHdrRadius: %f" % modHdrRadius)
        print ("modHdrTotalLODs: %d" % modHdrTotalLODs)
        print ("modHdrLODHyst: %f " % modHdrLODHyst)
        modHdrLODTrans \
        = struct.unpack("<%df" % modHdrLODHyst, file.read(int(modHdrLODHyst)*4))
        print ("modHdrLODTrans:")
        print (modHdrLODTrans)     
    except:
        print("Error parsing file header. Boo!")
        file.close()
        return
   
    # Strings
    modStrTag, \
    modStrSize \
    = struct.unpack("<4si", file.read(8))
    modStrSizePadded = 4*(math.ceil(modStrSize/4))
    print ("modStrTag: " + modStrTag.decode("ascii"))
    print ("modStrSize: %d" % modStrSize)
    print ("modStrSizePadded: %d" % modStrSizePadded)
    modStrPool \
    = struct.unpack("<%ds" % modStrSizePadded, file.read(modStrSizePadded))
    modStrStrings = modStrPool[0].split(b'\x00')
    modStrList = [x.decode("ascii") for x in modStrStrings]
    print ("modStrList: ")
    print (modStrList)
   
    # Named Points
    modPtsTag, \
    modPtsSize \
    = struct.unpack("<4si", file.read(8))
    modPtsStart = file.tell()
    print ("modPtsTag: " + modPtsTag.decode("ascii"))
    print ("modPtsSize: %d" % modPtsSize)
    modPtsNum = modPtsSize / 16
    print ("modPtsNum: %d" % modPtsNum)
    modPts = list()
    while (file.tell() - modPtsStart < modPtsSize):
        modPts.append(struct.unpack("<fffi", file.read(16)))
    print ("modPts:")
    print (modPts)
   
    # Materials (aieee!)
    modMtsTag, \
    modMtsSize \
    = struct.unpack("<4si", file.read(8))
    modMtsStart = file.tell()   
    print ("modMtsTag: " + modMtsTag.decode("ascii"))
    print ("modMtsSize: %d" % modMtsSize)
    modMtsFlags = list()
    modMts = list()     
    while (file.tell() - modMtsStart < modMtsSize):
        modMtsFlags.append(struct.unpack("<i", file.read(4)))
        if modMtsFlags[-1][0] > 20:
            modMts.append(struct.unpack("<Ifffiiii", file.read(32)))
        else:
            modMts.append(struct.unpack("<Ifffii", file.read(24)))
    print ("modMtsFlags:")
    print (modMtsFlags)
    print ("modMts:")
    print (modMts) 

    # Geometries
    modModTag, \
    modModSize, \
    modModVerticesNum, \
    modModFacesNum \
    = struct.unpack("<4siii", file.read(16))
    print ("modModTag: " + modModTag.decode("ascii"))
    print ("modModSize: %d" % modModSize)   
    print ("modModVerticesNum: %d" % modModVerticesNum)   
    print ("modModFacesNum: %d" % modModFacesNum) 
   
    modVtxTag \
    = struct.unpack("<4s", file.read(4))
    modVtxStart = file.tell() 
    print ("modVtxTag: " + modVtxTag[0].decode("ascii"))
    # print (modVtxTag)
   
    modVtx = list()
    while (file.tell() - modVtxStart < modModVerticesNum*12):
        modVtx.append(struct.unpack("<fff", file.read(12)))
    print ("modVtx: ")
    print (modVtx)
   
    modPlyTag, \
    modPlySize, \
    modPlyVtxCount, \
    modPlyMtlIdx, \
    = struct.unpack("<4siii", file.read(16))
    print ("modPlyTag :")
    print (modPlyTag)
    print ("modPlySize :")
    print (modPlySize)
    print ("modPlyVtxCount :")
    print (modPlyVtxCount)
    print ("modPlyMtlIdx :")
    print (modPlyMtlIdx)


from bpy.props import *

class IMPORT_OT_mod(bpy.types.Operator):
    '''Import MOD Operator.'''
    bl_idname= "import.mod"
    bl_label= "Import MOD"
    bl_description= "Import a StarFleet Command model."
    bl_options= {'REGISTER', 'UNDO'}

    filepath= StringProperty(name="File Path", description="Filepath used for importing the model file", maxlen=1024, default="")

    def execute(self, context):
        import_mod(self.filepath,
                 context)
        return {'FINISHED'}

    def invoke(self, context, event):
        wm= context.window_manager
        wm.add_fileselect(self)
        return {'RUNNING_MODAL'}


def menu_func(self, context):
    self.layout.operator(IMPORT_OT_mod.bl_idname, text="StarFleet Command Model (.mod)")

def register():
    bpy.types.INFO_MT_file_import.append(menu_func)

def unregister():
    bpy.types.INFO_MT_file_import.remove(menu_func)

if __name__ == "__main__":
    register()

I'm missing something... as far as I can tell the vertex block is just a set of tPoint3s (fff)...
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 08:56:36 am
I'm a little out of my depth here, but I think that first value is a near zero. We get that sometimes in 3D programs where the program doesn't return a perfect zero but returns an extremely small float that might as well be zero. Not sure if that helps, though.

When I get home from work today (which, im actually late for now >.<) I will create a particular box object for you with known dimensions and stuff.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 09:11:49 am
I found the dumb error, I skipped the VTXS block size int. (reading it as the first float of the coords) :smackhead: I probably did so because it is totally redundant, knowing the number of vertices and the size of their struct.

The last value still leaves me wondering (-1.9390653040624603e-15), but I suspected it may have meaning... probably is just a point near zero on that axis.

On to the polies.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 09:19:22 am
hmm, first how much of a header on the vertex are you pulling?  It only has the name VTX0 and a size. IIRC.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 09:21:29 am
I don't remember an extra bit of data at the end of verts, it was just the sets of verts.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 09:23:36 am
Check my edits above. I think I have it sorted.

"VTX header" (actually, whole block):
Code: [Select]
    modVtxTag, \
    modVtxSize \
    = struct.unpack("<4si", file.read(8))
    modVtxStart = file.tell() 
    print ("modVtxTag: " + modVtxTag.decode("ascii"))
    print ("modVtxSize: %d" % modVtxSize)
   
    modVtx = list()
    while (file.tell() - modVtxStart < modModVerticesNum*12):
        modVtx.append(struct.unpack("<fff", file.read(12)))
    print ("modVtx: ")
    print (modVtx)
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 09:27:56 am
Lol, see, I still have the vertices*12 in there when it can just be the size read from the same VTXS block instead of the number of verts stored in the parent geometry block. Lots of redundancy in this file format.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 09:32:21 am
'tis looks right to me.  does this seem to read it all or missing some still?
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 09:42:08 am
Lol, see, I still have the vertices*12 in there when it can just be the size read from the same VTXS block instead of the number of verts stored in the parent geometry block. Lots of redundancy in this file format.

it has redundancies but it also allows the skipping of any part you want because it store the size of each block.  Thus you can just skip over if you don't want that information now.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 09:44:55 am
now myself, instead of checking where in the file I am to see if I read anough, I might have gone with a counter and counted the number of verts read in instead.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 09:59:17 am
Have fun Bonk, I'm off to work (2nd job).  Looking forward to seeing how you have done.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 10:02:19 am
I'm more of a "start at the beginning and when you come to the end, stop" kind of guy... (very procedural and not so o.o)

I have the all the blocks sorted out, now just to loop through each LOD properly and I'll have all the data to build the model.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 10:05:12 am
now myself, instead of checking where in the file I am to see if I read anough, I might have gone with a counter and counted the number of verts read in instead.

I went with this option oddly only to avoid the inadequacies of the for control structure in python (or until I grasp what they call.. umm "List Comprehensions"... yeah that's it... possibly where I will end up for a control structure)

Oh right I suppose I  can count manually in each loop, I suppose that would be more efficient than calling back the file position? (maybe not though, as the var is already there, why create another to store the same info...? - as I expect the file.tell function just returns the position value, nothing more...)
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 12:21:58 pm
Almost got all the data in... I am having to count manually in places as I loop through because of variable object sizes. ;)  Just the LOD loop left.

Though after the trouble I went to to parse the strings out, they're probably best left as a bytestring blob since the named points and polies reference them by hex offset. Easy enough.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 12:50:59 pm
would agree with the byteblob thingie.  Would probably be easier to reference that way.

Now also, add in a check to make sure that each block is actually there.  Since you can't be sure if each block will be used (that way you don't just eat the head of the block and assume it is the one you want, never want to assume)
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 01:58:35 pm
Alrighty Bonk + Marstone,

Here is a basic no-nonsense MOD file. It has a single object in it - a cube. I have listed up the XYZ, UVW, and Material data that is involved in it.

Code: [Select]
XYZ coordinates
------------------
[-50,-50,0]
[50,-50,0]
[-50,50,0]
[50,50,0]
[-50,-50,100]
[50,-50,100]
[-50,50,100]
[50,50,100]

UVW coordinates
-----------------
[33.9291,66.0709,0]
[66.0709,66.0709,0]
[33.9291,33.9291,0]
[66.0709,33.9291,0]
[1,66.8582,0]
[33.1418,66.8582,0]
[1,99,0]
[33.1418,99,0]
[33.9291,1,0]
[66.0709,1,0]
[33.9291,33.1418,0]
[66.0709,33.1418,0]
[66.8582,1,0]
[99,1,0]
[66.8582,33.1418,0]
[99,33.1418,0]
[33.1418,33.9291,0]
[1,33.9291,0]
[33.1418,66.0709,0]
[1,66.0709,0]
[33.1418,1,0]
[1,1,0]
[33.1418,33.1418,0]
[1,33.1418,0]

Face 1, 2, and 3 use MatID 1
Face 4, 5, and 6 use MatID 2

Material = Super_Mat
 - Submaterial 1 = Material_Able
 - - Diffuse Map = Map_Yankee
 - Submaterial 2 = Material_Baker
 - - Diffuse Map = Map_Zulu
 - - Self-Illumination Map = Map_Whiskey

Let me know if there is more information you need or if you want a specific criteria in another MOD file.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 02:12:53 pm
could you save it in a 3DS format also for a comparing how to import it?
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 02:14:44 pm
You're going to have to fix the texture name, but here it is :)
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 02:15:41 pm
Now also, add in a check to make sure that each block is actually there.  Since you can't be sure if each block will be used (that way you don't just eat the head of the block and assume it is the one you want, never want to assume)

Right. I think the only block that could be missing from a model is the named points block? Or how about a model with no textures? A few samples of those kind of variations would be good.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 02:16:51 pm
Forgive the ignorance, but what is a Named Points block?
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 02:21:34 pm
Thanks FoaS! :thumbsup:

5 LOD transitions but only one mesh? (are those 3ds max exporter defaults perhaps) LOD count is right though

My decoding choked on the materials flags... (not sure why, the file is probably fine) I think because I'm not adding the flags up right...
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 02:22:01 pm
No LODs in that model.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 02:22:56 pm
the named points are the hardpoints and hit locations on the ship. IIRC
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 02:23:57 pm
k, rgr that. That MOD also does not have hardpoints or hit locations - Tried to keep it as simple as possible. I can add or remove stuff as you'd like. Want a no-texture version?
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 02:25:44 pm
the named points are the hardpoints and hit locations on the ship. IIRC

Yes.

k, rgr that. That MOD also does not have hardpoints or hit locations - Tried to keep it as simple as possible. I can add or remove stuff as you'd like. Want a no-texture version?

A whole buncha variations would be awesome if it is not too much trouble. With this... without that...
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 02:26:56 pm
could be why you choked on the materials with some of the blocks missing.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 02:27:42 pm
xactly my suspicion too! :)

Gonna take a little break and watch some TV. Pretty good progress today (for me).
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 02:29:36 pm
Alright - assume that the model above is the Control. I'll make as few changes from that at a time - give me five minutes and I'll have a Non-Texture version and a version with Hardpoints/DamagePoints. I've NEVER used LODs before, so I feel a little bit of trepidation, but I'll post the LOD settings when I make it.

EDIT: if you are hung on the materials and want to tackle the Hardpoints/Damagepoints without the material, I'll make the double-change version, too.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 02:32:35 pm
No hurry, take your time and get it right (working out the LODs, and the other variations) As we have stock models with LODs to work from. I'm gonna take a bit of a break right now anyway as I've been at it all day.

Your initial model may be too simple (too few faces?) to be reduced to 4 additional LODs? (not really sure, did not look close enough to see...)
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 11, 2010, 02:34:28 pm
 ;D ;D my script reads in the cube, but have to work on textures yet.  That is where I got stopped before.  With the 3DS one, should be able to work on that some.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 02:44:35 pm
Version 2 Includes the following

 - Control.mod (basic features)
 - NoTex.mod (stripped of material)
 - hardpoint.mod (has basic Hardpoints and damagepoints)
 - NoTexHardpoint.mod (has basic hardpoints and damagepoints; no material)
 - Information.txt (has an outline of what I've guessed as being relevant information about the file)
 - UVChecker.bmp (The bitmap file used)
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 02:47:19 pm
Not sure what you mean about the reduction to LODs, Bonk. There is only 1 LOD included in the model - can the script handle less than 3 LODs?
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 11, 2010, 04:07:47 pm
Pretty sure the maximum # of LODs in the mod file are 5. Ideally one of the sample models would have 5 meshes in it of decreasing complexity (LODs). The script, when complete will be able to handle from 1-5. (thanks again...)

(in case anyone is wondering LOD = Level Of Detail)
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on November 11, 2010, 05:41:45 pm
modelname_1, modelname_2, modelname_3, etc. for LODs.  there doesn't actually have to be anything different really between the models, the exporter from what i can surmise doesn't care only that things are properly named

edit: well you have to select that option.  the exporter has the option to check level of detail... but i wouldn't go that route ever.  Also i went ahead and modified FoaS base model and added 5 LOD (base model + 4 other levels).  Each level is exactly the same as the base model.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 11, 2010, 07:46:52 pm
Thanks Tus,

Did you happen to document the numbers you used on the LODs?, distances, etc?
Title: Re: Blender to .mod scripts are there any working?
Post by: Tus-XC on November 11, 2010, 08:44:36 pm
i used the default settings, which are

5LOD_1: 0
5LOD_2: 100
5LOD_3: 200
5LOD_4: 300
5LOD_5: 400
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on November 11, 2010, 09:46:03 pm
Damn its not dead yet JIM   ;D  :thumbsup:
I wish i could help but i am worthless. Modeling is just a hobby to me. Here is some way to late and out of date most likey not true info that im sure you already know by now but i will share anyway. LODs {Level of detail models}  The max/ gmax exporter can do 5 or more but the game engine uses 3.  I am not sure thats true but from what the stock models show its 3. The models are seperate meshes that use 1 set of hardpoints for all 3meshes. So for the cube test use 3 cubes each cube a higher poly than the next.
 I belive for the lod system to work each model must be a single object either attached seperate parts or a welded hollow mesh i think a groupe lock would work also but i never botherd to try that. I wish all my models to open in m6/sfced editor so my ways are not normal. :crazy2: I have exported a model i forgot to weld the mesh after maping. That model showed atleast 5 mesh parts in m6sfced but in the game engine only 3 showed up from the LOD system. I think the 0 :100 200 300 400 500 thingy is for the scale system frigets might use the closer setings larger ships span the distance more ie for a frig use 0 100 and 300 for the 3 meshes but thats my guess i have always exported the default for the 5 designs i have botherd to make lods for cause i didnt care at the time. The model should be maped by a seperate lower rez texture set fit for the lower poly model or the game engine may show lag in multiplayer play.   Im sure this is a WOP waist of post but i try to help  :angel:
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 12, 2010, 07:00:26 am
I know... look what you (re)started Kreeargh!  ;D  and your input is still useful. Got me thinking... this script wil handle five (or 500...) but if all we ever use normally (and if that is all the game uses) is 3 then that is fine... I can add those restrictions and settings as we firmly establish them.

That will do Tus, thanks for the effort! :thumbsup:  (though ideally, each LOD should have fewer polys for a "standard" sample model)
... aha the 5 tansitions were the max3 exporter defaults... thought so.

... a little shopping then I'm back at this. All these test models will definitely help the process. I suspect marstone may be updating his 2.49 importer while I work out the start of my 2.5 importer. Either way, one way or another we will have a working import soon. I'm not far off and neither is marstone.

I'm starting to think the export may not be so difficult since we have worked out so much already.

It occurs to me that we'll have to watch what happens to the rather large library of SFC models when this importer is complete. Would we want to add some kind of model "watermarker" or "brander" as I've previously discussed with DarkDrone? Or just stick to our mostly working honour system?   ... bah - scratch the watermarking idea... fraught with issues and complications... pretty much have to leave it up to the individual modeler...
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 13, 2010, 07:31:58 pm
Thanks again for the test models guys, helped bunches. I've got all the data in correctly for all the test cases. Or as Jim would say... "Is everybody in? The ceremony is about to begin..."

I might get serious on this tonight and try and get the models built. That should be the fun part. Another look at marstone's blender 2.4 version should help. (and the stock lwo and 3ds imports...)

the data import (may need tidying up as I build the model... its simple enough not to need its own classes and object oriented design... I think I can get away with a one, two procedural punch for this task):
Code: [Select]
bl_addon_info= {
    "name": "Import StarFleet Command Models",
    "author": "Bonk",
    "version": (0, 1),
    "blender": (2, 5, 5),
    "api": 31847,
    "location": "File > Import > StarFleet Command Model (.mod)",
    "description": "Imports a StarFleet Command model file.",
    "warning": "The universe may implode at any moment.",
    "wiki_url": "http://www.dynaverse.net/wiki/index.php?title=Blender:SFC_Models",
    "category": "Import/Export"}

import os
import io
import time
import struct
import chunk
# import array

import bpy
import math
import mathutils

def decodeAsc(byteStr):
    print (byteStr.decode("ascii"))

def import_mod(filename,context):
                   
    print (filename)
   
    name, ext= os.path.splitext(os.path.basename(filename))
    file= open(filename, 'rb')

    # Header
    try:
        modHdrTag, \
        modHdrFileSize, \
        modHdrVersion, \
        modHdrRadius, \
        modHdrTotalLODs, \
        modHdrLODHyst \
        = struct.unpack("<4siIfif", file.read(24))
        print ("modHdrTag: " + modHdrTag.decode("ascii"))
        print ("modHdrFileSize: %d" % modHdrFileSize)
        print ("modHdrVersion: %d" % modHdrVersion)
        print ("modHdrRadius: %f" % modHdrRadius)
        print ("modHdrTotalLODs: %d" % modHdrTotalLODs)
        print ("modHdrLODHyst: %f " % modHdrLODHyst)
        modHdrLODTrans \
        = struct.unpack("<%df" % modHdrLODHyst, file.read(int(modHdrLODHyst)*4))
        print ("modHdrLODTrans:")
        print (modHdrLODTrans)     
    except:
        print("Error parsing file header. Boo!")
        file.close()
        return
   
    if modHdrTag != b'MDLS':
        print("Error parsing file header. Boo!")
        file.close()
        return   
   
    modMeshesParsed = 0
    modMeshes = list()
   
    while modMeshesParsed < modHdrTotalLODs:
       
        modChnkTag, \
        modChnkSize \
        = struct.unpack("<4si", file.read(8))
       
        # Strings
        if modChnkTag == b'STRS':
            modStrSizePadded = 4*(math.ceil(modChnkSize/4))
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            print ("modStrSizePadded: %d" % modStrSizePadded)
            modStrPool \
            = struct.unpack("<%ds" % modStrSizePadded, file.read(modStrSizePadded))
            modStrStrings = modStrPool[0].split(b'\x00')
            modStrList = [x.decode("ascii") for x in modStrStrings]
            print ("modStrList: ")
            print (modStrList)
       
        # Named Points
        elif modChnkTag == b'PNTS':
            modPtsStart = file.tell()
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            modPtsNum = modChnkSize / 16
            print ("modPtsNum: %d" % modPtsNum)
            modPts = list()
            while (file.tell() - modPtsStart < modChnkSize):
                modPts.append(struct.unpack("<fffi", file.read(16)))
            print ("(last)modPts:")
            print (modPts[-1])
       
        # Materials (aieee!)
        elif modChnkTag == b'MATS':
            modMtsStart = file.tell()   
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            modMtsFlags = list()
            modMts = list()     
            while (file.tell() - modMtsStart < modChnkSize):
                modMtsFlags.append(struct.unpack("<i", file.read(4)))
                if modMtsFlags[-1][0] > 20:
                    modMts.append(struct.unpack("<Ifffiiii", file.read(32)))
                else:
                    modMts.append(struct.unpack("<Ifffii", file.read(24)))
            print ("modMtsFlags:")
            print (modMtsFlags)
            print ("(last)modMts:")
            print (modMts[-1]) 

        # Geometries
        elif modChnkTag == b'MOD0':
            modModVerticesNum, \
            modModFacesNum \
            = struct.unpack("<ii", file.read(8))
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            print ("modModVerticesNum: %d" % modModVerticesNum)   
            print ("modModFacesNum: %d" % modModFacesNum) 
           
            modVtxTag, \
            modVtxSize \
            = struct.unpack("<4si", file.read(8))
            modVtxStart = file.tell() 
            print ("modVtxTag: " + modVtxTag.decode("ascii"))
            print ("modVtxSize: %d" % modVtxSize)
           
            modVtx = list()
            while (file.tell() - modVtxStart < modVtxSize):
                modVtx.append(struct.unpack("<fff", file.read(12)))
            print ("(last)modVtx: ")
            print (modVtx[-1])
           
            modPlysStart = file.tell()
            modPlys = list()
            modPlysCount = 0
            while (modPlysCount < modModFacesNum):
                modPly = list()
                modPlyTag, \
                modPlySize, \
                modPlyVtxCount, \
                modPlyMtlIdx \
                = struct.unpack("<4siii", file.read(16))
                # print ("modPlyTag: " + modPlyTag.decode("ascii"))
                # print ("modPlySize: %d" % modPlySize)
                # print ("modPlyVtxCount: %d" % modPlyVtxCount)
                # print ("modPlyMtlIdx: %d" % modPlyMtlIdx)
                modPlyNorm \
                = struct.unpack("<fff", file.read(12))
                # print ("modPlyNorm:")
                # print (modPlyNorm)
                modPlyVtxsStart = file.tell()
                modPlyVtxs = list()
                while (file.tell() - modPlyVtxsStart < modPlyVtxCount*28):
                    modPlyVtxs.append(struct.unpack("<HHffffff", file.read(28)))
                # print ("modPlyVtxs:")
                # print (modPlyVtxs)
                modPly.append(modPlyTag)
                modPly.append(modPlySize)
                modPly.append(modPlyVtxCount)
                modPly.append(modPlyMtlIdx)
                modPly.append(modPlyNorm)
                modPly.append(modPlyVtxs)
                modPlys.append(modPly)
                modPlysCount += 1
           
            modMeshes.append(modModVerticesNum)
            modMeshes.append(modModFacesNum)
            modMeshes.append(modVtx)
            modMeshes.append(modPlys)
           
            print ("(last)modPlys:")
            print (modMeshes[-1][3][-1])
            print (file.tell())
           
            modMeshesParsed += 1
       
    file.close()
       
       
from bpy.props import *

class IMPORT_OT_mod(bpy.types.Operator):
    '''Import MOD Operator.'''
    bl_idname= "import.mod"
    bl_label= "Import MOD"
    bl_description= "Import a StarFleet Command model."
    bl_options= {'REGISTER', 'UNDO'}

    filepath= StringProperty(name="File Path", description="Filepath used for importing the model file", maxlen=1024, default="")

    def execute(self, context):
        import_mod(self.filepath,
                 context)
        return {'FINISHED'}

    def invoke(self, context, event):
        wm= context.window_manager
        wm.add_fileselect(self)
        return {'RUNNING_MODAL'}


def menu_func(self, context):
    self.layout.operator(IMPORT_OT_mod.bl_idname, text="StarFleet Command Model (.mod)")

def register():
    bpy.types.INFO_MT_file_import.append(menu_func)

def unregister():
    bpy.types.INFO_MT_file_import.remove(menu_func)

if __name__ == "__main__":
    register()
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on November 13, 2010, 09:40:57 pm
I know... look what you (re)started Kreeargh!  ;D  and your input is still useful. Got me thinking... this script wil handle five (or 500...) but if all we ever use normally (and if that is all the game uses) is 3 then that is fine... I can add those restrictions and settings as we firmly establish them.

That will do Tus, thanks for the effort! :thumbsup:  (though ideally, each LOD should have fewer polys for a "standard" sample model)
... aha the 5 tansitions were the max3 exporter defaults... thought so.

... a little shopping then I'm back at this. All these test models will definitely help the process. I suspect marstone may be updating his 2.49 importer while I work out the start of my 2.5 importer. Either way, one way or another we will have a working import soon. I'm not far off and neither is marstone.

I'm starting to think the export may not be so difficult since we have worked out so much already.

It occurs to me that we'll have to watch what happens to the rather large library of SFC models when this importer is complete. Would we want to add some kind of model "watermarker" or "brander" as I've previously discussed with DarkDrone? Or just stick to our mostly working honour system?   ... bah - scratch the watermarking idea... fraught with issues and complications... pretty much have to leave it up to the individual modeler...

Sorry about that :P but gmax kinda blows even though i use it mainly. Lack of renderer and good uvw stuff make the program 1/2 arse usefull. Blender is supported and used by alot so i figured what the hell ask  :-X.   A import .mod to blender plugin isnt needed near as much as a export to mod plugin. Work on that first and take a poll or something from the sfc modelers about the import version. That is true more can be riped if that option is avalable. I myself dont care my work has been riped for many stuff i cant stop that or want to waist my time trying. { my thoughs if one dont want ones work riped dont release it to public}   
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 12:44:54 am
Making progress... seems the y and z coordinates are flipped. Typical... flying sideways at 2:30 am!  ;D

The unreal psk importer has been most helpful. I'm as far as getting the first LOD mesh in. Looks like the UV mappings are up next... ? Then apply the mats... I expect to get hung up there a bit as I have not quite sorted the materials flags in my head, flag values that store multiple settings in one int that add in binary always make my head hurt a bit...

And the question is shoud I correct the axes before or after applying the materials? Hmmm maybe the named points... but what blender object to use for those? I seem to recall blender had a better suited object for .mod hardpoints than the milkshape solution...  :-\

Code: [Select]
bl_addon_info= {
    "name": "Import StarFleet Command Models",
    "author": "Bonk",
    "version": (0, 1),
    "blender": (2, 5, 5),
    "api": 31847,
    "location": "File > Import > StarFleet Command Model (.mod)",
    "description": "Imports a StarFleet Command model file.",
    "warning": "The universe may implode at any moment.",
    "wiki_url": "http://www.dynaverse.net/wiki/index.php?title=Blender:SFC_Models",
    "category": "Import/Export"}

import os
import io
import time
import struct
import chunk
# import array

import bpy
import math
import mathutils

def decodeAsc(byteStr):
    print (byteStr.decode("ascii"))

def import_mod(filename,context):
                   
    print (filename)
   
    name, ext= os.path.splitext(os.path.basename(filename))
    file= open(filename, 'rb')

    # Header
    try:
        modHdrTag, \
        modHdrFileSize, \
        modHdrVersion, \
        modHdrRadius, \
        modHdrTotalLODs, \
        modHdrLODHyst \
        = struct.unpack("<4siIfif", file.read(24))
        print ("modHdrTag: " + modHdrTag.decode("ascii"))
        print ("modHdrFileSize: %d" % modHdrFileSize)
        print ("modHdrVersion: %d" % modHdrVersion)
        print ("modHdrRadius: %f" % modHdrRadius)
        print ("modHdrTotalLODs: %d" % modHdrTotalLODs)
        print ("modHdrLODHyst: %f " % modHdrLODHyst)
        modHdrLODTrans \
        = struct.unpack("<%df" % modHdrLODHyst, file.read(int(modHdrLODHyst)*4))
        print ("modHdrLODTrans:")
        print (modHdrLODTrans)     
    except:
        print("Error parsing file header. Boo!")
        file.close()
        return
   
    if modHdrTag != b'MDLS':
        print("Error parsing file header. Boo!")
        file.close()
        return   
   
    modMeshesParsed = 0
    modMeshes = list()
   
    while modMeshesParsed < modHdrTotalLODs:
       
        modChnkTag, \
        modChnkSize \
        = struct.unpack("<4si", file.read(8))
       
        # Strings
        if modChnkTag == b'STRS':
            modStrSizePadded = 4*(math.ceil(modChnkSize/4))
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            print ("modStrSizePadded: %d" % modStrSizePadded)
            modStrPool \
            = struct.unpack("<%ds" % modStrSizePadded, file.read(modStrSizePadded))
            modStrStrings = modStrPool[0].split(b'\x00')
            modStrList = [x.decode("ascii") for x in modStrStrings]
            print ("modStrList: ")
            print (modStrList)
       
        # Named Points
        elif modChnkTag == b'PNTS':
            modPtsStart = file.tell()
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            modPtsNum = modChnkSize / 16
            print ("modPtsNum: %d" % modPtsNum)
            modPts = list()
            while (file.tell() - modPtsStart < modChnkSize):
                modPts.append(struct.unpack("<fffi", file.read(16)))
            print ("(last)modPts:")
            print (modPts[-1])
       
        # Materials (aieee!)
        elif modChnkTag == b'MATS':
            modMtsStart = file.tell()   
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            modMtsFlags = list()
            modMts = list()     
            while (file.tell() - modMtsStart < modChnkSize):
                modMtsFlags.append(struct.unpack("<i", file.read(4)))
                if modMtsFlags[-1][0] > 20:
                    modMts.append(struct.unpack("<Ifffiiii", file.read(32)))
                else:
                    modMts.append(struct.unpack("<Ifffii", file.read(24)))
            print ("modMtsFlags:")
            print (modMtsFlags)
            print ("(last)modMts:")
            print (modMts[-1]) 

        # Geometries
        elif modChnkTag == b'MOD0':
            modMesh = list()
            modFaces = list()
            modModVerticesNum, \
            modModFacesNum \
            = struct.unpack("<ii", file.read(8))
            print ("modChnkTag: " + modChnkTag.decode("ascii"))
            print ("modChnkSize: %d" % modChnkSize)
            print ("modModVerticesNum: %d" % modModVerticesNum)   
            print ("modModFacesNum: %d" % modModFacesNum) 
           
            modVtxTag, \
            modVtxSize \
            = struct.unpack("<4si", file.read(8))
            modVtxStart = file.tell() 
            print ("modVtxTag: " + modVtxTag.decode("ascii"))
            print ("modVtxSize: %d" % modVtxSize)
           
            modVtx = list()
            modVt = list()
            while (file.tell() - modVtxStart < modVtxSize):
                modVt = struct.unpack("<fff", file.read(12))
                modVtx.extend(modVt)
            # print ("(last)modVtx: ")
            # print (modVtx[-1])
           
            modPlysStart = file.tell()
            modPlys = list()
            modPlysCount = 0
            while (modPlysCount < modModFacesNum):
                modPly = list()
                modPlyTag, \
                modPlySize, \
                modPlyVtxCount, \
                modPlyMtlIdx \
                = struct.unpack("<4siii", file.read(16))
                # print ("modPlyTag: " + modPlyTag.decode("ascii"))
                # print ("modPlySize: %d" % modPlySize)
                # print ("modPlyVtxCount: %d" % modPlyVtxCount)
                # print ("modPlyMtlIdx: %d" % modPlyMtlIdx)
                modPlyNorm \
                = struct.unpack("<fff", file.read(12))
                # print ("modPlyNorm:")
                # print (modPlyNorm)
                modPlyVtxsStart = file.tell()
                modPlyVtxs = list()
                modPlyFace = list()
                while (file.tell() - modPlyVtxsStart < modPlyVtxCount*28):
                    modPlyVtxs.append(struct.unpack("<HHffffff", file.read(28)))
                    modPlyFace.append(modPlyVtxs[-1][0])
                    # print (modPlyVtxs[-1][0])
                modPlyFace.append(0)
                # print ("modPlyVtxs:")
                # print (modPlyVtxs)
                modPly.append(modPlyTag)
                modPly.append(modPlySize)
                modPly.append(modPlyVtxCount)
                modPly.append(modPlyMtlIdx)
                modPly.append(modPlyNorm)
                modPly.append(modPlyVtxs)
                # modPly.append(modPlyFace)
                modFaces.extend(modPlyFace)
                modPlys.append(modPly)
                modPlysCount += 1
           
            modMesh.append(modModVerticesNum)
            modMesh.append(modModFacesNum)
            modMesh.append(modVtx)
            modMesh.append(modPlys)
            modMesh.append(modFaces)
           
            modMeshes.append(modMesh)
           
            print ("(last)modPlys:")
            print (modMesh[-1][3])
            # print (modMeshes[0])
            print (file.tell())
           
            modMeshesParsed += 1
       
    file.close()
   
    mod_obj = bpy.data.meshes.new(name)
    mod_obj.vertices.add(modMeshes[0][0])
    print (modMeshes[0][0])
    mod_obj.vertices.foreach_set("co", modMeshes[0][2])
    print (modMeshes[0][2])
    mod_obj.faces.add(modMeshes[0][1])
    print (modMeshes[0][1])
    mod_obj.faces.foreach_set("vertices_raw", modMeshes[0][4])
    mod_obj.update()
    modmesh = bpy.data.objects.new(name,mod_obj)
    bpy.context.scene.objects.link(modmesh)
    bpy.context.scene.update()
 
    # print (modFaces)
   
    # print (modMeshes[0][0])
    # print (modMeshes[0][2])
   
    return

       
       
from bpy.props import *

class IMPORT_OT_mod(bpy.types.Operator):
    '''Import MOD Operator.'''
    bl_idname= "import.mod"
    bl_label= "Import MOD"
    bl_description= "Import a StarFleet Command model."
    bl_options= {'REGISTER', 'UNDO'}

    filepath= StringProperty(name="File Path", description="Filepath used for importing the model file", maxlen=1024, default="")

    def execute(self, context):
        import_mod(self.filepath,
                 context)
        return {'FINISHED'}

    def invoke(self, context, event):
        wm= context.window_manager
        wm.add_fileselect(self)
        return {'RUNNING_MODAL'}


def menu_func(self, context):
    self.layout.operator(IMPORT_OT_mod.bl_idname, text="StarFleet Command Model (.mod)")

def register():
    bpy.types.INFO_MT_file_import.append(menu_func)

def unregister():
    bpy.types.INFO_MT_file_import.remove(menu_func)

if __name__ == "__main__":
    register()


Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 01:18:41 am
Sorry about that :P but gmax kinda blows even though i use it mainly. Lack of renderer and good uvw stuff make the program 1/2 arse usefull. Blender is supported and used by alot so i figured what the hell ask  :-X.   A import .mod to blender plugin isnt needed near as much as a export to mod plugin. Work on that first and take a poll or something from the sfc modelers about the import version. That is true more can be riped if that option is avalable. I myself dont care my work has been riped for many stuff i cant stop that or want to waist my time trying. { my thoughs if one dont want ones work riped dont release it to public}

Yeah, about releases... Ozzy has a song about it. Basically I am with you.  (actually, Sabbath, Technical Ecstasy, It's Alright)

Definitely getting SFC material into blender will help its future. (watch people start playing with SFC models in the blender game engine... see your models in the movies! ;))

Of course the goal is to get an exporter made so we have a nice new modern open source modelling program to use with existing SFC products. At this point it is a question of when, not if. We're not far off finishing the importer. Once that is done I'll need to figure out how to grab the normals in  the blender environment for storage in the exported .mod file.  (as I see no need (or mechanism) to import them and I expect blender can generate them on the fly, I should be able to jsut grab them inthe exposrt script... but I get ahead...)

Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 11:05:22 am
Was the test cube meant to be this huge? (That's a little orange fca mesh back there... I have yet to apply the stored model radius value... ack!)

edit: actually looking at the stored radius vaules they look about right (fca radius ~= 8.5, Control radius ~= 122.5) looks like the radius is just calculated and stored for the engine, as for the normals.

I wonder if one could optimise the file format by normalising the data and using a center and scale value. ? (scale all x,y,z data to 0-1) That would make the most sense to me. I expect other 3d file formats may do so. You'd have to have apretty high poly mesh to lose precision, and moving to 64 bit ints would probably cover even that for some time... hmmm... It would also facilitate mesh manipulation and analysis.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 11:24:19 am
It was 100 maxunits tall - of course I dont know how big an FCA model is in max >.<
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 11:30:55 am
*giggle* you said "maxunits"  hehe hehe hehe ...  :crazy2: 

Lol, sorry, figuring out the materials is getting deep and putting my mind in a strange place.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 11:31:56 am
lol. anything I can help with?
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 11:50:00 am
It's complicated... not sure I even have any solid questions... my main problems at the moment are two things - the flags values, and some basic texturing concepts and how they relate to blender objects... ideally I'd have a modelling expert watching over my shoulder filling me in on all the modelling stuff that is second nature to them...

I need to figure out how to handle this kind of thing in python:
http://kinsey.no/blog/index.php/2009/11/17/storing-multiple-privilegessettings-in-a-single-integer/ (http://kinsey.no/blog/index.php/2009/11/17/storing-multiple-privilegessettings-in-a-single-integer/)

That's how the material flags are stored:
Code: [Select]
enum
{
kTexMapped      = 0x0001, // set if texture mapping
kGouraud        = 0x0002, // set if gouraud (smooth) shading
kFlat = 0x0004, // set if flat shading
kWire           = 0x0008, // set if polygon should be wire frame
kAdditive = 0x0010, // set if polygon should be blended
kLuminance = 0x0020, // set if we have luminance texture maps
};

So if it is texture mapped, Gourad shaded and has a luminance texture the integer value is 35.... but I need to figure out how to succinctly analyse this value in python... get all the possible combinations and then do the right thing to the material... see how it is kinda hard to wrap one's head around? My problem is I'm no expert in any one programming language. It gets confusing sometimes.


Then I need to pull the UV coords for each face out and in the get them in the right format for the blender object. I have already parsed the data from the file, I just need to get it into the right form... (then I can strip out all the redundant data and debug output...)

I need it sorted better in my head before I can put it to code.

Once that is done I'll need to figure out exactly how to implement the LODs in blender. It will be easy enough to loop through and pull out the other meshes once the first is all the way done, but then how to store, display and name in blender? what is the logical and appropriate mechanism that will be natural for the user to follow... I like natural and intuitive UI design whether actual display is involved or not.

and radioparadise is distracting the hell out of me, but I need it...
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 11:52:39 am
I'm not sure how to extract flags like that >.< I can't help you there, but I can give you some theory on UV Unwrapping.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 12:05:19 pm
I'm OK on theory I think... it's just projecting the plane(s) on the surface face by face ... the numbers are all there...

What I'm not really familiar with is the texturing interfaces from the user side in blender... I expect this is also where marstone got a bit hung up...

Oh ... I know what would help ... an equivalent model in the sample pack in native .blend format... could you manage that somehow? (note to avoid naming objects in a way that might conflict with blender system objects... I'm a fan of and perhaps overuse prefixes on everything. - but I suppose I'll have to consider the user that wants to name their model file bpy.data.meshes.mod or something like that....  sanitize all input... hhmmm another place for a prefix!  ;D)
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 12:06:16 pm
Erm - I don't have a copy of Blender handy - maybe kreeargh?
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 12:10:09 pm
Needs to be the 2.55 beta too... oh wait... I'm passing the buck a bit much here, I suppose I can import the control model from the .3ds version in blender and then save it in native format... but I'm leery of that 3ds import script... it looks too scary inside... not organised the way I would...

I'll just do that and see what I get for now, it should help. As does working it out in posts like this...
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 12:11:37 pm
Lol, alrighty then - the 3ds Version is the same as the Control: bare essentials + Materials. Can't add dummy points (hardpoints, etc) I dont think.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 12:16:36 pm
Can't add dummy points (hardpoints, etc) I dont think.
:skeptic:  Curious as to the explanation?

Here is the result of importing the 3ds control model into blender... hmmm.... I had hoped to see textures for an example to work toward....
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 12:18:41 pm
I don't think 3ds Supports dummy objects. I could be wrong, however. I was under the impression that it handles only geometry.

You might have to reassign the bitmap, it may be pointing to somewhere on my desktop >.< Furthermore, 3ds Format only supports a few characters in texture name assignments, so it probably nixed off the last few charcters of the texture name.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 12:21:02 pm
I get nothing at all for materials or textures with the blender 2.55 .3ds import script... (perhaps the import for the new beta is not finished?) I guess I'll have to fire up blender 2.49 and see what I get...

Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 12:53:23 pm
new 3ds file with shorter file names for the textures so they don't truncate.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 14, 2010, 01:25:51 pm
OK that did it... importing that file into blender 2.55 with its included 3ds import seems to work. (attached) Now I have a corresponding example to work toward. Perhaps that same model in .mod format as exported by max would be good too...
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 03:17:28 pm
Okay, Once more time. Here is the file with all the different color-depthed textures (which I dont think will matter in the MOD format, since all it does is point to a texture). There are also versions with the two different illumination-texture math that we talked about. The types of MOD and 3ds formats are documented in the Information.txt file, but I can also walk you through it on TS of course, if there is any ambiguity.

http://robinomicon.com/haven/bonk/ColorDepth%20and%20Illuminence%20Types.zip (http://robinomicon.com/haven/bonk/ColorDepth%20and%20Illuminence%20Types.zip)

(Had to upload it to my server, bigger than 1024kb)
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on November 14, 2010, 08:53:15 pm
Erm - I don't have a copy of Blender handy - maybe kreeargh?
Yea what version i have 2.49 and 2.5. I havent checked in a while im not sure 2.5 went past beta yet.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 14, 2010, 10:34:22 pm
*giggle* you said "maxunits"  hehe hehe hehe ...  :crazy2: 

I just got that......
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 15, 2010, 02:57:07 pm
I've got the materials flags sorted now, by unpacking the 4 byte int into a tuple, then converting to a binary string and with a little string massaging a gourad shaded material with a diffuse texture and a luminance texture looks like '100011'...

with each bit representing: 'kTexMapped,kGouraud,kFlat,kWire,kAdditive,kLuminance' (in reverse order)

As we discussed, it appears the 3dmax .mod exporter does not set the additive flag, I am most curious if the game engine will recognise it if set. (edit: I suspect it won't as there are structures for diffuse and luminace textures but not additive ones, but if a texture in the diffuse or luminance slot is also marked as additive - what will happen?)

I'm as far as adding materials, I've almost got it figured out.

It seems there are about 16 ways to skin the cat of texturing something and the .mod file format takes one approach (an old one), the architecture of the blender format is considerably more complicated...

The idea that comes to mind is material wrapped vs texture wrapped texturing. The .mod is something in-between.  >:(  As we discussed, the shading and other parameters are set by material in the .mod format but are set by texture in blender... I'm not 100% I've got it right, but I will by the time this is done.

Texturing is friggin complicated. This is not easy. I'm starting to get the hang of Python though. That's a good thing.
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 15, 2010, 04:28:37 pm
If the additive property is recognized by the engine, it won't need any sort of value indicated its strength, its a boolean property. Basically it means instead of display a model normally, it will take each of the model and add it to the pixel of the background.

Here's an example:

(http://img831.imageshack.us/img831/3967/additiveteapot.jpg)

The teapot on the left is normally shaded, the teapot on the right has its additive flag turned on. No strength floats or anything, just "yes/no" flag.

Actually, now that I think about it - the engine has to support additive texturing in one form or another, because of how it does shields, phaserbeams, and what not.... In fact. I dare you to open the shield.mod and see if it has additive flags turned on.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 15, 2010, 05:19:26 pm
yes textures are complicated (specially for us none graphics type people). One reason I stopped at that point.  I got abit lost, and the support guys got busy on other things so didn't get questions answered as needed to keep going.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 15, 2010, 05:43:54 pm
Actually, now that I think about it - the engine has to support additive texturing in one form or another, because of how it does shields, phaserbeams, and what not.... In fact. I dare you to open the shield.mod and see if it has additive flags turned on.

You bastard... I was watching the lastest Episode of Canada's Worst Driver (funny stuff)... now I have to go look...  ;D

yes textures are complicated (specially for us none graphics type people). One reason I stopped at that point.  I got abit lost, and the support guys got busy on other things so didn't get questions answered as needed to keep going.

I had a great chat with Tus and FoaS on TS yesterday while I stewed it all over... I was wishing you were there too, but I was just kind of rambling all afternoon as I read through the blender and python docs and quizzed the guys on modelling stuff.

We are going to have to brush up on and fully comprehend all of it, plus some of the new stuff in the last ten years eventually... ;)

Feel free to jump back in with it any time, I'm still at what you called the "spagetti code" stage with it. I have a bunch of useless stuff in there and some stuff still not worked out, in the right form...

What I'm grappling with in me head right now is meshes.uv_textures vs meshes.texture_slots and all the various combinations of such object trees in blender.

I may end up using bones as in milkshape... what object are hardpoints labelled from in max again?
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 15, 2010, 05:45:14 pm
Been on teamspeak for about an hour while I play EVE, just in case you dropped in and needed help ;)
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 15, 2010, 05:47:23 pm
Quote
I may end up using bones as in milkshape... what object are hardpoints labelled from in max again?

Dummy objects.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 15, 2010, 06:01:56 pm
Cool... I'll play with both solutions later.

For now the sheild.mod is rather interesting. It choked my import script. The PNTS block is present but empty!  :o  (edit: oh wait, not such a shock... its a sheild needs no named points... and the script only chokes cuz I try and print the last one...)
Quote
C:\Users\user\Documents\blender255\shield\shield.mod
modHdrTag: MDLS
modHdrFileSize: 37900
modHdrVersion: 512
modHdrRadius: 7.383409
modHdrTotalLODs: 1
modHdrLODHyst: 5.000000
modHdrLODTrans:
(0.0, 45.0, 90.0, 135.0, 180.0)
modChnkTag: STRS
modChnkSize: 1
modStrSizePadded: 4
modStrList:
['', '', '', '', '']
modChnkTag: MATS
modChnkSize: 28
modMtsFlags:
['000010']
(last)modMts:
(4282895360, 0.0, 0.0, 0.0, 0, 0)
modChnkTag: PNTS
modChnkSize: 0
modPtsNum: 0
(last)modPts:
Traceback (most recent call last):
  File "Text", line 262, in execute
  File "Text", line 97, in import_mod
IndexError: list index out of range

One material flagged as gourad shaded, that's it. No texture...? (empty strings confirms)

but that first value in the materials structure which I thought was the "COLORREF" (bit depth?) which I was reading as an unsigned int but it appears to be a float? Though I'm looking at some color structures defined in the max3 importer ... hmmm marstone might be able to figure that one... I think it might be an RGB value stored oddly...
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 15, 2010, 06:31:15 pm
I think that COLORREF structure miust be defined in the max API... good lord... where am I going to find a copy of the max3 api? I might get lucky with the right google search...

Looking at that additive teapot naturally makes me think Thol.  :)  But I don't think we should get our hopes up... bah enough speculation... I'll set the flag on a material and test it in game here at some point...
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 15, 2010, 09:08:43 pm
Oh yeah, the Max3 .mod import code I am working from... (posted elsewhere too I think... and the max4 code should be out there somewhere...) ... as mentioned. (I think the gmax one was compiled from the max4 code with a few tweaks)



Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 15, 2010, 11:57:29 pm
Colorref should be a color mask/format that the color for the image is in. I haven't found where in the code it is used tho beyond being read in (will look more). will look more to see if it is something in the format but not implemented.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 16, 2010, 12:15:51 am
Looking in the export code. They use the rgb function to set fcolor so it is a mask for the color in the image and probably not used as the set it to 24 bit color in the code and our modders say they can't get the engine to use it.

*edit*
Looking deeper in export code. They just flat set all fcolor the same so probably not used in the engine.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 16, 2010, 06:16:21 am
I'd buy that except for the different value in the shield.mod... as up till then it was like 16million in all the files I looked at so I assumed it was a colour depth value. But the sheild.mod value makes no sense by that interpretation. I have this sneaking suspicion that it is a colour mask stored as an RGB uchar triplet encoded into 4 bytes. Or something like that... a feature used in the game engine but not implemented for user built models.

I guess I better start looking at the exporter code too.

I can probably get the model textured skipping some of this unknown stuff, but I want to figure out as much as I can about the format and how it works. If we're going to do a set of import/export scripts I want it done right. Blender has a future. But we have limitations so we'll do the best we can.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 16, 2010, 06:30:32 am
Well, that is what it is. It is a color mask, but the exporter (at least for 3ds v3 just uses the same mask so it should be 0xFFF0. Maybe some exporters do it differently.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 16, 2010, 07:02:13 am
Interesting. Thanks for the input. I got all excited when I got the mesh up, but man, slogging through this part is slow...
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 16, 2010, 07:29:16 am
More awake now. second coffee... I see... the 3ds exported .mods will have it set to FF FF FF 00 ...(255,255,255,0) (RGB white - but the fourth byte...?) makes sense I guess.

The fColor value for the one material in shield.mod:  00 CC 47 FF  .... well now what's that fourth byte... alpha? saturation? (0,204,71,255) does that make sense as a colour mask for the shield?

Is there something different about the packing of that mod? While the control.mod that FoaS gave me does not choke my script the shield mod does... and neither have named points.. hmmm... aha it is different... it appears the max exporter does not create an empty PNTS block if there are no named points... yet the shield .mod has one. Conclusion: created with different/earlier/manual tools.

Ahh... versions... I've been looking at OP models exclusively... I should start throwing stock EAW and SFC1 .mods in the testing mix... I'll learn more. I bet the sheild.mod is an EAW/SFC1 carryover...

Waiiit a minute.... release dates... Max3 vs Max4 vs SFC1/EAW/OP ... I think I need to establish the timeline relationship.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 16, 2010, 07:48:44 am
Ah, if it is from that early then it might have format options that have been changed or tweeked as the game developed.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 19, 2010, 02:21:14 am
Grr, back to the problem I had last time. Wrapping my head around how blender holds materials and textures internally.

I can get the information from the .mod file but need to get it into the blender structures (haven't found the structure layouts in the manual pages yet). Got some of it down but just anough to be confusing. More reading and searching to go. 
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on November 19, 2010, 03:57:37 am
Now there I cannot help you
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on November 19, 2010, 04:30:36 am
Yeah, I know. If the programmers done a good job, it all should be hidden behind the interface from artists.

If I can't find it in the docs might have to download the source and find it there. But I have faith they documented the api somewhere.

Other option is to go into the scripting interface while running blender and check the structures there, bleh.
Title: Re: Blender to .mod scripts are there any working?
Post by: Bonk on November 19, 2010, 07:11:01 am
Ah uhndastand. That's pretty much where I'm at.  Slowly getting it lined up with stuff like:

Code: [Select]
    # new mesh, vertices and faces
    mod_obj = bpy.data.meshes.new(name)
    mod_obj.vertices.add(modMeshes[0][0])
    # print (modMeshes[0][0])
   
    mod_obj.vertices.foreach_set("co", modMeshes[0][2])
    # mod_obj.vertices.foreach_set("normal", modMeshes[0][2])
   
    # print (modMeshes[0][2])
    mod_obj.faces.add(modMeshes[0][1])
    # print (modMeshes[0][1])
    # mod_obj.faces.foreach_set("vertices_raw", modMeshes[0][4])
    mod_obj.faces.foreach_set("vertices", modMeshes[0][4])
 

    i = 0
    for Mtl in modMts[:]:
        matdata = bpy.data.materials.new("mat")
        # Color,fAmbient,fDiffuse,fEmittance,TexID,TexNameOffset(,TexID,TexNameOffset)
        matdata.ambient = Mtl[1]
        matdata.diffuse_intensity = Mtl[2]
        matdata.emit = Mtl[3]
        # matdata.active_texture
        # matdata.texture_slots
        if modMtsFlags[i][5] == "1":
            texdata = mod_obj.uv_textures.new()
            texdata.uv = *tough part goes here*
            matdata.active_texture = texdata
        mod_obj.materials.append(matdata)
        i += 1
       
    # mod_obj.faces.foreach_set("material_index", modMeshes[0][3])
    # mod_obj.faces.foreach_set("normal", modMeshes[0][4])

I think at a certain point the knowledge will snowball and we'll get it.

http://www.blender.org/documentation/250PythonDoc/contents.html (http://www.blender.org/documentation/250PythonDoc/contents.html)  (docs I've been using for 2.55 - need to drill down many layers end up with dozens of tabs open)

Links to info on scripting in both versions:
http://wiki.blender.org/index.php/Extensions:Py/Scripts (http://wiki.blender.org/index.php/Extensions:Py/Scripts)

The 2.5 docs seem to be more user-friendly. I've been spending a lot of time here:
http://www.blender.org/documentation/250PythonDoc/bpy.types.Mesh.html#bpy.types.Mesh (http://www.blender.org/documentation/250PythonDoc/bpy.types.Mesh.html#bpy.types.Mesh)
and here:
http://www.blender.org/documentation/250PythonDoc/bpy.types.MeshTextureFace.html#bpy.types.MeshTextureFace (http://www.blender.org/documentation/250PythonDoc/bpy.types.MeshTextureFace.html#bpy.types.MeshTextureFace)

Yeah, I know. If the programmers done a good job, it all should be hidden behind the interface from artists.

Interestingly, in 2.55 almost every single UI element has a tooltip popup that describes the relevant python object - not much use to me yet as the script has not come that far, but for UI interaction and debuggin it might be nice...

2.5 also makes dumping script debug data easier...
Code: [Select]
print(dir(bpy.data)).meshes
.materials
.textures... etc.
Title: Re: Blender to .mod scripts are there any working?
Post by: Scottish Andy on February 02, 2012, 11:27:27 am
Hello all,

I've started playing around with Blender and I still have my Milkshape. I was wondering if Blender has the ability to import SFC's .MOD files? I am not interested in exporting a Blender model into .MOD for playing in the game, but I would like to compose gorgeous Hi-Res shots of some of the gorgeous and inspired models created for this game.

Thanks.
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 02, 2012, 11:50:18 pm
Hello all,

I've started playing around with Blender and I still have my Milkshape. I was wondering if Blender has the ability to import SFC's .MOD files? I am not interested in exporting a Blender model into .MOD for playing in the game, but I would like to compose gorgeous Hi-Res shots of some of the gorgeous and inspired models created for this game.

Thanks.
Sad to say but It dont work, not yet that I know about. With hope and the all mighty coder soon will be a real issue?!!!???
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 03, 2012, 02:00:52 am
yeah, sorry.  I was working on the blender script to import .mod.  Ran into stuff I couldn't figure out at the time (how to do the textures on import).  I got it so it will bring in the mesh, but doesn't have the texture on it yet.

Have lots of projects being worked on will see if I can get back on this one in the near future, but can't say when.
Title: Re: Blender to .mod scripts are there any working?
Post by: atheorhaven on February 05, 2012, 09:20:29 pm
yeah, sorry.  I was working on the blender script to import .mod.  Ran into stuff I couldn't figure out at the time (how to do the textures on import).  I got it so it will bring in the mesh, but doesn't have the texture on it yet.

Have lots of projects being worked on will see if I can get back on this one in the near future, but can't say when.

If it will bring in the mesh, does it also retain the UV mappings, or are they stripped with the textures?

And as a thought, I don't suppose comparing the plugins for something that may be more complete (.3ds maybe?) for Blender against a similar import script for Max or Milkshape would help?  And I don't suppose anyone still has Chris' (Assimsoft's) old import/export stuff (AssimView) around anymore?  Darkdrone?  :)
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 05, 2012, 10:33:25 pm
yeah, sorry.  I was working on the blender script to import .mod.  Ran into stuff I couldn't figure out at the time (how to do the textures on import).  I got it so it will bring in the mesh, but doesn't have the texture on it yet.

Have lots of projects being worked on will see if I can get back on this one in the near future, but can't say when.

If the mesh is importing all good!  :notworthy: :thumbsup: Gmax or milkshape can map the model if needed.
What Type of mesh was tested tris or quads?   
Import blender to .mod more usefull than the export from.mod .
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 06, 2012, 12:59:14 am
yeah, sorry.  I was working on the blender script to import .mod.  Ran into stuff I couldn't figure out at the time (how to do the textures on import).  I got it so it will bring in the mesh, but doesn't have the texture on it yet.

Have lots of projects being worked on will see if I can get back on this one in the near future, but can't say when.

If the mesh is importing all good!  :notworthy: :thumbsup: Gmax or milkshape can map the model if needed.
What Type of mesh was tested tris or quads?   
Import blender to .mod more usefull than the export from.mod .

I guess it would be tris, as they are triangles (although for some reason graphic stuff still call that a quad).

remapping a model would be a pain for some people.  So will have to re-check on how to do the textures.
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 06, 2012, 01:01:49 am
yeah, sorry.  I was working on the blender script to import .mod.  Ran into stuff I couldn't figure out at the time (how to do the textures on import).  I got it so it will bring in the mesh, but doesn't have the texture on it yet.

Have lots of projects being worked on will see if I can get back on this one in the near future, but can't say when.

If it will bring in the mesh, does it also retain the UV mappings, or are they stripped with the textures?

And as a thought, I don't suppose comparing the plugins for something that may be more complete (.3ds maybe?) for Blender against a similar import script for Max or Milkshape would help?  And I don't suppose anyone still has Chris' (Assimsoft's) old import/export stuff (AssimView) around anymore?  Darkdrone?  :)

right now the UV mapping is dropped.  Reason being I don't know what internal structures are used for the textures and how they work.  Will have to do a search on more docs and see if I can find it.  Since I don't know how the program holds the texture haven't been able to set it up for it.  It has been along time now, and python is not my language of choice so will have a learning curve to get back into it.  (plus time, never time).
Title: Re: Blender to .mod scripts are there any working?
Post by: FoaS_XC on February 06, 2012, 02:43:40 am
Quads an Triangles in some ways are semantic distinctions and in some ways technical distinctions. When it comes to the MOD file (and most other simple object formats), A quad really is nothing more than two triangles seamed together by an edge. However: in advanced modelling apps (like 3ds Max) quad faces are a class (to use the programming context of the word "class") unto themselves, with separate methods (which sometimes are similar to those of distinct triangles).

(okay, technically object classes that have distinct methods for their quads are of a separate class from objects without quad-specific methods).

I'm fairly certain I remember how UVW mapping is stored by an object in 3ds Max - I know nothing behind the inner workings of blender, sadly :/

What I do know forces me to stress one particular point: in XYZ space (your typical 3d-space) a vertex can only have one location, its X,Y, and Z... However in UVW space, that same vertex can have N locations where N = number of faces said vertex is used in constructing (this upcoming example DOES get a tad more complicated when dealing with triangulation, but hold that thought): The corner of a cube can have a set 3 UVW coordinates. (with a triangulated cube, that number might be anywhere from 3 to 6, depending on how it triangulates).

this gets even MORE complicated when dealing with multiple mapping channels (think an array of 3 dimensional UVW spaces), but that falls out of the purview of what MOD files can do at this time.


Hope that helps rather than hinders :3
Title: Re: Blender to .mod scripts are there any working?
Post by: Kreeargh on February 06, 2012, 10:52:32 pm
http://blendernewbies.blogspot.com/2008/11/3d-mesh-topology-tip-quads-vs-triangles.html (http://blendernewbies.blogspot.com/2008/11/3d-mesh-topology-tip-quads-vs-triangles.html)

No matter what the end result is ,.  Whatever to .modplugin is needed the most.  Export from .mod format is just a nother way of theift.  The " .Mod format is about the game" Convert to the game but do not rip from it!
Title: Re: Blender to .mod scripts are there any working?
Post by: marstone on February 08, 2012, 03:46:12 am
thanks for the link for the read on quads and triangles.  It was interesting but doesn't help on the code side as I need.  As the .mod only uses triangles, it would be rough to try and figure out quads from them so the import will only have triangles. 

Export will be an interesting things as you have so many tools and ways for making a model in programs these days, and it has to convert to triangles when exported.

As for the import (or export) have to find better documentation on the structures that are underlying blender so I can do the translate to or from them.  So far, haven't located that much that helps, but looking slowly.