Topic: Blender to .mod scripts are there any working?  (Read 33004 times)

0 Members and 1 Guest are viewing this topic.

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #100 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.
The smell of printer ink in the morning,
Tis the smell of programming.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #101 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.

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #102 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.
The smell of printer ink in the morning,
Tis the smell of programming.

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #103 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.
The smell of printer ink in the morning,
Tis the smell of programming.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #104 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.

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
« Last Edit: November 08, 2010, 03:24:53 pm by marstone »
The smell of printer ink in the morning,
Tis the smell of programming.

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #106 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.  ::)
The smell of printer ink in the morning,
Tis the smell of programming.

Offline FoaS_XC

  • Photorps, Sammiches, woot woot.
  • Global Moderator
  • Commander
  • *
  • Posts: 4571
  • Gender: Male
    • Robinomicon
Re: Blender to .mod scripts are there any working?
« Reply #107 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.
Robinomicon
"When I was 5 years old, my mom always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down “happy.” They told me I didn’t understand the assignment and I told them they didn’t understand life."

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #108 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.
« Last Edit: November 08, 2010, 04:35:58 pm by Bonk »


Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #110 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.
The smell of printer ink in the morning,
Tis the smell of programming.

Offline Tus-XC

  • Capt
  • XenoCorp® Member
  • Commander
  • *
  • Posts: 2782
  • Gender: Male
Re: Blender to .mod scripts are there any working?
« Reply #111 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)
Rob

"Elige Sortem Tuam"

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #112 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.

Offline FoaS_XC

  • Photorps, Sammiches, woot woot.
  • Global Moderator
  • Commander
  • *
  • Posts: 4571
  • Gender: Male
    • Robinomicon
Re: Blender to .mod scripts are there any working?
« Reply #113 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.
Robinomicon
"When I was 5 years old, my mom always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down “happy.” They told me I didn’t understand the assignment and I told them they didn’t understand life."

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #114 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.


Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #115 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.
The smell of printer ink in the morning,
Tis the smell of programming.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #116 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 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).

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #117 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)
The smell of printer ink in the morning,
Tis the smell of programming.

Offline Bonk

  • Commodore
  • *
  • Posts: 13298
  • You don't have to live like a refugee.
Re: Blender to .mod scripts are there any working?
« Reply #118 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...)  :)

Offline marstone

  • Because I can
  • Commander
  • *
  • Posts: 3014
  • Gender: Male
  • G.E.C.K. - The best kit to have
    • Ramblings on the Q3, blog
Re: Blender to .mod scripts are there any working?
« Reply #119 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)
The smell of printer ink in the morning,
Tis the smell of programming.